1.152 class style

A style object describes the visual appearance of a fragment object in an editor object or dict_item objects in a list_browser object: font, highlighting, underlining, etc. Style objects are associated with editors using the editor->style method. Fragments that have fragment<->style equal to name will be displayed according to the associated style.

The online manual uses various styles. E.g.

titleSection titles in helvetica bold font
codecode fragments in a fixed-width screen font
activeattribute-bold for links to definitions.

An elaborate example of using editors, fragments and styles is the XPCE help browser, whose sources are in the XPCE library file pce_helper.pl. A simple example is in the example Multiple Fonts.

Bugs:

When a style is changed, the corresponding text is not immediately updated. It is adviced to use styles in a read-only fashion.

See also
- class text_margin
- editor->style
- editor-selected_fragment_style
- class editor
- class fragment

1.152.1 Instance variables

style-attributes: alien:long
Or'ed bits for style->underline, style->highlight, style->grey, style->closed and style->bold.
style <-> background: [colour|pixmap|elevation]
Background for the characters. If it is an instance of class elevation, the characters are placed in an elevated box. See also style->colour.
style <-> colour: [colour]
Colour of the characters. See also style->background.
style <-> font: [font]
Font used to display the characters of the fragment. When two fragments overlap and they do not agree on the font to be used, the font of the smallest fragment is used.

Defaults: @default (meaning use editor<->font).

style <-> icon: image*
When a style object is associated with an editor that has a text_margin object attached to it, the start of fragments related to this style object is marked in the margin using this image object. See class text_margin and editor->margin_width.
See also
- class text_margin
- editor->margin_width
style <-> left_margin: int
Left- and right-margins. Used by class text_image (underlying class editor and class view) to control indentation and wrapping.

In combination with text_image->wrap, the margins may be used to realise quotations and intended lists in WYSIWYG like editors.

Class text_image fetches the new margins whenever it starts a new screen line.

style <-> right_margin: int
Inherits description from: style-left_margin
style <-> underline: [bool|texture_name|colour]
Underline text. If @default, underlining of overlapping fragments is respected. If @off there is no underlining. If @on, the text is underlined using the same colour as the text. If an explicit colour is used the line is painted in this colour.

1.152.2 Send methods

style ->bold: bool
Inherits description from: style<-bold
style ->grey: bool
Inherits description from: style<-bold
style ->hidden: bool
If a style object has style->hidden: @on, the text will be made invisible. Currently this attribute is ignored if the style is used for a dict_item object.

May be used to implement outline editors or to hide control sequences.

See also class fragment and class editor.

style ->highlight: bool
Inherits description from: style<-bold
style ->initialise: icon=[image]*, font=[font], colour=[colour], highlight=[bool], underline=[bool|texture_name|colour], bold=[bool], grey=[bool], background=[colour|pixmap|elevation], hidden=[bool], left_margin=[int], right_margin=[int], strikethrough=[bool|texture_name|colour]
Create a style object from its (margin-)image, font and text-attributes. For example:
send(Editor, style, section_header,
     style(font := huge)).

The arguments are:

style->icon Image shown in text_margin object
style->font Font used to display characters
style->colour Colour for characters
style->highlight Swap colour and background
style->underline Underline text
style->bold Print bold
style->grey Print grey using colour<-reduce
style->background Colour/elevation for background
style->hidden If true, text is invisible
style->left_margin Left margin (pixels)
style->right_margin Right margin (pixels from right)

NOTE: this method defines a large number of arguments. It is advised to use the keyword := value construct for specifying the arguments. The following two terms define a bold style:

style(bold := @on)
style(@default, @default, @default, @default, @default, @on)

See also class := and send_method->send.

style ->underline:
Bugs: Underlining is done at a fixed distance of the base-line with a fixed line thickness (1). These parameters ought to be read from the (X-)font attributes.

Inherits description from: style<-bold

1.152.3 Get methods

style <-grey: -> bool
style <-highlight: -> bool
style <-underline: -> [bool|texture_name|colour]
style <-bold: -> bool
These methods set/query the appropriate field from the style -attributes slot. The attributes are:
style->bold bold-face using double-strike (see also style->font)
style->underline underlined text.
style->highlight inverted background and foreground.
style->grey greyed-out by and'ing with @grey50_image.

Bugs: style<->closed is not implemented. Future versions might use this to hide the text of a fragment temporary.

style <-hidden: -> bool
Inherits description from: style->hidden