Gadget line support
Factor handbook » UI framework » Implementing new gadgets

Prev:Clipboard protocol


The ui.gadgets.line-support vocabulary provides common code shared by gadgets which display a sequence of lines of text. Currently, the two gadgets that use it are Editor gadgets and Table gadgets.

The class of line gadgets:
line-gadget

line-gadget? ( object -- ? )


Line gadgets are backed by a model which must be a sequence. The number of lines in the gadget is the length of the sequence.

Line gadgets cannot be created and used directly, instead a subclass must be defined:
new-line-gadget ( class -- gadget )


Subclasses must implement a generic word:
draw-line ( line index gadget -- )


Two optional generic words may be implemented; if they are not implemented in the subclass, a default implementation based on font metrics will be used:
line-height ( gadget -- n )

line-leading ( gadget -- n )


Validating line numbers:
validate-line ( m gadget -- n )


Working with visible lines:
visible-lines ( gadget -- n )

first-visible-line ( gadget -- n )

last-visible-line ( gadget -- n )


Converting y coordinates to line numbers, and vice versa:
line>y ( n gadget -- y )

y>line ( y gadget -- n )