| Did you know ... | Search Documentation: |
| Fonts and images |
XPCE browsers support multiple fonts and images indicating the type
of the item. Font, colour and icon specification use the style
object based mechanism to specify the appearance of a dict_item
object of specified style. For example, to make a browser for files and
directories, where the directories are printed purple and using the closedir.svg
icon, use the following code as a starting point:
file_browser(B) :-
new(B, browser),
line_icon(B, 'closedir.svg', DirIcon),
line_icon(B, 'document.svg', FileIcon),
send(B, style, directory,
style(icon := DirIcon, colour := purple)),
send(B, style, file,
style(icon := FileIcon)).
append_directory(B, Name) :-
send(B, append,
dict_item(Name, style := directory)).
append_file(B, Name) :-
send(B, append,
dict_item(Name, style := file)).
An icon is placed on the baseline at its image<->hot_spot.
An SVG image is rendered at the size given when it is created, so we can
scale it to the ascent of the browser's list_browser<-font,
which makes it stand on the baseline as high as the capitals. The
browser leaves
list_browser<-icon_gap
pixels between the icon and the label.
line_icon(B, File, Icon) :-
get(B, font, Font),
get(Font, ascent, A),
new(Icon, image(File, A, A)),
send(Icon, hot_spot, point(0, A)).
A style applies to the whole item. To use multiple fonts or colours
within an item, make its label a markup
object (see
dict_item<-label
and class markup).
The markup applies on top of the style, so the item below still gets the
icon and colour of style
directory, while the name is bold and the number of entries
grey. Icons can only be specified using a style.
append_directory(B, Name, Entries) :-
send(B, append,
dict_item(Name,
markup("<b>%s</b> <span foreground='grey50'>%d items</span>",
Name, Entries),
style := directory)).