Class text is used to display (short) text fragments on a graphical device object.
The text may be printed in any font. It may span multiple lines (separated by newline-characters (ASCII value 10)), which may be aligned on their left-side, center or right-side. The current implementation silently truncates text objects that span more than 200 physical lines.
Text objects can be
boxed by setting their graphical->pen.
Text objects provide
limited editing capabilities which are compatible to the editing
capabilities provided by class editor
(EMACS oriented).
Text objects are edited
using the method text->typed.
See also class text_item (text entry field), class view and class editor.
-font->typed
@see class text
|pixmap]*->transparent.->caret
to @default
places the caret at the end of the text.
Defaults: Resource defined.
format describes how the lines of a text containing
multiple lines are aligned and how the area of the text changes if the
string or font is changed:
<-wrap, text<-margin
controls how long strings are represented by class text.
These slots are manipulated by text->margin.walk due to rounding errors.|{passive}->keyboard_focus
and text->caret.
Defaults: @off
->margin.
<->length
is specified (i.e. non-zero), this value
indicates how many pixels at the left-side are not visible.
\e DEL)->typed
@see text<-pointed<-string.
In addition, if text<-string
does not accept the method, but class string
does, the text<-string
is converted to a string
object holding the same characters. See also
text->has_send_method.<-area
from the text<-string, text<-font
and text<-margin.->typed
on itself if the event if a keyboard event and the text<-show_caret
yields
@on. See also graphical->keyboard_focus.<-string,
text<-font
and text<-margin.<-string
and of class string.
See also text->catch_all.<-string
defaults to” , the text<-format
to left and the text<-font
to the
text.font<-margin
in the text<-fonts ex units
(see font<-ex).
New code should use the more advanced text->margin
method.<-wrap:
->margin: @nil).
The graphical is as big as needed to display the string
->margin:
width, clip) The graphical has fixed width. If the string is too long it
will be clipped.
->margin:
width, wrap) The graphical has a text<-margin
defined. If the string is too long to fit within the margin it will be
wrapped on multiple physical lines. Wrapping only happens at word
boundaries.
->margin:
width, wrap_fixed_width) Similar to wrap-1, but the graphical<-width
of the graphical equals the margin rather than the width occupied by the
displayed characters.
<-cut_buffer.->resizefrom is @nil
to must be omitted and the selection is cleared. Otherwise default
values do not change the corresponding end of the selection.
See also text<-selected_text,
class edit_text_gesture
and the Prolog library(pce_editable_text).
|{passive}->typed
@see text<-pointed<-background.
The value @on
is equivalent to text->background: @nil
and @off to text->background:
@default.|event_idtext does not provide default
event-handling, but editable text
objects are easily created by forwarding keyboard-events to this method:
:- pce_global(@edit_text_recogniser,
new(handler(keyboard,
message(@receiver,
typed,
@arg1)))).
text_make_editable(T) :-
send(T, recogniser, @edit_text_recogniser).
This method uses the key_binding
object called text from @key_bindings
to map the typed keys on selectors and then invokes methods on class text.
With the above, if the user types control-U to the text the following
happens:
->typed
using
@edit_text_recogniser.
<-id
is processed by the text key_binding
object and mapped on the selector clear. text->clear
does not require arguments and the key_binding
object just invokes text->clear.
->clear erases all characters from
the text.
Diagnostics: Fails if the keyboard event could not be handled.
|colour
?- new(T, text('Hello World')),
send(T, show_caret, @on),
send(T, recogniser,
click_gesture(left, '', single,
message(T, caret,
?(T, pointed,
@event?position)))).
<-selection->selection.