| Author: | Colin D. Bennett <colin@gibibit.com> |
|---|---|
| Date: | 16 August 2008 |
Contents
The GRUB graphical menu supports themes that can customize the layout and appearance of the GRUB boot menu. The theme is configured through a plain text file that specifies the layout of the various GUI components (including the boot menu, timeout progress bar, and text messages) as well as the appearance using colors, fonts, and images.
Colors can be specified in several ways:
The fonts GRUB uses PFF2 font format bitmap fonts. Fonts are specified with full font names, such as Helvetica Bold 18. Currently there is no provision for a preference list of fonts, or deriving one font from another. Fonts are loaded with the loadfont command in GRUB. To see the list of loaded fonts, execute the lsfonts command. If there are too many fonts to fit on screen, do set pager=1 before executing lsfonts.
Pixmap-styled progress bar.
Plain progress bar, drawn with solid color.
Progress bars are used to display the remaining time before GRUB boots the default menu entry. To create a progress bar that will display the remaining time before automatic boot, simply create a progress_bar component with the id __timeout__. This indicates to GRUB that the progress bar should be updated as time passes, and it should be made invisible if the countdown to automatic boot is interrupted by the user.
Progress bars may optionally have text displayed on them. This is controlled through the show_text property, which can be set to either true or false to control whether text is displayed. When GRUB is counting down to automatic boot, the text informs the user of the number of seconds remaining.
The circular progress indicator functions similarly to the progress bar. When given an id of __timeout__, GRUB updates the circular progress indicator's value to indicate the time remaining. For the circular progress indicator, there are two images used to render it: the center image, and the tick image. The center image is rendered in the center of the component, while the tick image is used to render each mark along the circumference of the indicator.
Text labels can be placed on the boot screen. The font, color, and horizontal alignment can be specified for labels. If a label is given the id __timeout__, then the text property for that label is also updated with a message informing the user of the number of seconds remaining until automatic boot. This is useful in case you want the text displayed somewhere else instead of directly on the progress bar.
The boot menu where GRUB displays the menu entries from the grub.cfg file. It is a list of items, where each item has a title and an optional icon. The icon is selected based on the classes specified for the menu entry. If there is a PNG file named myclass.png in the grub/themes/icons directory, it will be displayed for items which have the class myclass. The boot menu can be customized in several ways, such as the font and color used for the menu entry title, and by specifying styled boxes for the menu itself and for the selected item highlight.
One of the most important features for customizing the layout is the use of styled boxes. A styled box is composed of 9 rectangular (and potentially empty) regions, which are used to seamlessly draw the styled box on screen:
The 9 slices that make up a box. The abbreviation below each name is used to identify the image for that slice.
To support any size of box on screen, the center slice and the slices for the top, bottom, and sides are all scaled to the correct size for the component on screen, using the following rules:
As an example of how an image might be sliced up, consider the styled box used for a terminal view.
An example of the slices (in red) used for a terminal window. This drawing was created and sliced in Inkscape, as the next section explains.
The Inkscape scalable vector graphics editor is a very useful tool for creating styled box images. One process that works well for slicing a drawing into the necessary image slices is:
# GRUB gfxmenu theme "winter".
# Uses background image from:
# http://www.cyberpunkcafe.com/e107_plugins/autogallery/autogallery.php?show=1.Open%20Source%20Wallpaper
# "without-leaves.png" was called "Without Leafs in Winter.png"
# Designed for 640x480 resolution.
title-text: ""
title-font: "Helvetica Bold 18"
message-font: "Helvetica 8"
title-color: "40, 40, 40"
message-color: "#FFF"
message-bg-color: "0, 166, 183"
desktop-image: "without-leaves.png"
desktop-color: "0, 154, 183"
terminal-box: "terminal_*.png"
+ boot_menu {
position = (100, 65)
preferred_size = (440, -1)
item_font = "Helvetica Bold 14"
selected_item_font = "Helvetica Bold 14"
item_color = "0, 0, 0"
selected_item_color = "203, 251, 255"
menu_pixmap_style = "menu_*.png"
selected_item_pixmap_style = "select_*.png"
icon_width = 44
icon_height = 44
item_height = 32
item_padding = 0
item_icon_space = 3
item_spacing = 11
max_items_shown = 5
scrollbar = true
scrollbar_frame = "sb_fr_*.png"
scrollbar_thumb = "sb_th_*.png"
scrollbar_width = 15
}
# Informational message bar at the bottom of the screen.
+ vbox {
position = (10, 440)
preferred_size = (620, 40)
+ label {
text="Select an item with the arrow keys and press Enter to boot."
font="lime 11" color=#000
}
+ label {
text="Press: 'c' for command line; 't' to switch to non-graphical menu."
font="lime 11" color=#000
}
}
# You can add text at arbitrary locations on the screen.
# The specification within the "+label {...}" block is free-form,
# so you can use as much or as little white space as you like.
+ label {
position = (170, 50)
font = "smoothansi 13"
color = "0,0,128"
text = "This is the Winter theme ... brought to you by GRUB!"
}
# Show the text alignment supported by labels.
+ vbox {
position = (220, 347)
preferred_size = (200, -1) # A preferred size of -1 means automatic.
+ label { text="Text alignment demo" align="center" font="aqui 11" }
+ label { text="Left" align="left" font="cure 11" }
+ label { text="Center" align="center" font="cure 11" }
+ label { text="Right" align="right" font="cure 11" }
}
+ vbox {
position = (580, 10)
+ label { text="GNU" font="gelly 11" color="0, 0, 0" }
+ label { text="GRUB" font="aqui 11" color="0, 0, 0" }
+ label { text="boot loader" font="cure 11" color="0, 0, 0" }
}
+ hbox {
position = (80, 10)
+ label { text="GNU" font="gelly 11" color="0, 0, 0" }
+ label { text="GRUB" font="aqui 11" color="0, 0, 0" }
+ label { text="boot loader" font="cure 11" color="0, 0, 0" }
}
# Demonstration of a compound layout: boxes within boxes.
+ hbox
{
position = (480, 3)
+ vbox
{
# Note: We can't just use 'size' to set the image's size,
# since the vbox will resize the component according to its
# preferred size, which for images is the native image size.
+ image { file="/boot/grub/themes/icons/ubuntu.png"
preferred_size = (20, 20) }
+ image { file="/boot/grub/themes/icons/gentoo.png"
preferred_size = (20, 20) }
}
+ vbox
{
+ label { text="GRand" font="cure 11" color=#99F }
+ label { text="Unified" font="cure 11" color=#BBF }
+ label { text="Bootloader" font="cure 11" color=#DDF }
}
}
# By defining a 'progress_bar' type component with an ID of '__timeout__',
# the progress bar will be used to display the time remaining before an
# the default entry is automatically booted.
+ progress_bar
{
id = "__timeout__"
position = (80, 393)
preferred_size = (500, 24)
font = "cure 11"
text_color = #000
fg_color = #CCF
bg_color = #66B
border_color = #006
show_text = false
}
# Although the progress_bar component is normally used to indicate the
# time remaining, it's also possible to create other components with an ID
# of '__timeout__'. All components with and ID of 'timeout_bar' will have
# the following properties set based on the timeout value:
# text, value, start, end, visible.
# In this case, we have set 'show_text=false' on the progress bar, and use
# the following label's 'text' property to display the message.
+ label
{
id = "__timeout__"
position = (80, 420)
preferred_size = (500, 24)
font = "lime 11"
color = #117
align = "center"
}
The theme file is a plain text file. Lines that begin with # are ignored and considered comments. (Note: This may not be the case if the previous line ended where a value was expected.)
The theme file contains two types of statements:
Global properties are specified with the simple format:
name1: value1 name2: "value which may contain spaces" name3: #88F
In this example, name3 is assigned a color value.
Specifies the file name pattern for the styled box slices used for the command line terminal window. For example,
terminal-box: terminal_*.png
will use the images terminal_c.png as the center area, terminal_n.png as the north (top) edge, terminal_nw.png as the northwest (upper left) corner, and so on. If the image for any slice is not found, it will simply be left empty.
Greater customizability comes is provided by components. A tree of components forms the user interface. Containers are components that can contain other components, and there is always a single root component which is an instance of a canvas container.
Components are created in the theme file by prefixing the type of component with a '+' sign:
+ label { text="GRUB" font="aqui 11" color="#8FF" }
properties of a component are specified as "name = value" (whitespace surrounding tokens is optional and is ignored) where value may be:
The following is a list of the components and the properties they support.
A label displays a line of text.
Properties:
A component that displays an image. The image is scaled to fit the component, although the preferred size defaults to the image's original size unless the preferred_size property is explicitly set.
Properties:
Displays a horizontally oriented progress bar. It can be rendered using simple solid filled rectangles, or using a pair of pixmap styled boxes.
Properties:
Displays a circular progress indicator. The appearance of this component is determined by two images: the center image and the tick image. The center image is generally larger and will be drawn in the center of the component. Around the circumference of a circle within the component, the tick image will be drawn a certain number of times, depending on the properties of the component.
Properties:
Displays the GRUB boot menu. It allows selecting items and executing them.
Properties:
The following properties are supported by all components:
The identifier for the component. This can be any arbitrary string. The ID can be used by scripts to refer to various components in the GUI component tree. Currently, there is one special ID value that GRUB recognizes:
