| Did you know ... | Search Documentation: |
| Text inside box |
Creating a compound graphical
An effective way to find the references of elements of a
window/device/dialog is using the graphical<->name
attribute and the
device<-member
or device<-catch_all
methods, which provide a mechanism to decent the consists_of hierarchy
of graphicals by name.
The example below defines a box with text and a method to set the string-value of the text. It uses user-defined classes.
:- pce_begin_class(text_box(string, width, height), device).
initialise(T, S:string, Width:[int], Height:[int]) :->
"Initialise from string, width and heigth"::
default(Width, 100, W),
default(Height, 50, H),
send(T, send_super, initialise),
send(T, display, box(W,H)),
send(T, display, text(S, center)),
send(T, recenter).
recenter(T) :->
"Put text in center of box"::
get(T, member, text, Txt),
get(T, member, box, B),
send(Txt, center, B?center).
string(T, S:string) :->
"Set the string of the text"::
get(T, member, text, Txt),
send(Txt, string, S).
string(T, S) :<-
"Get the string of the text"::
get(T, member, text, Txt),
get(Txt, string, S).
:- pce_end_class.
% Start the demo
:- send(new(P, picture('Text box demo')), open),
send(P, display,
text_box('Box with centered text', 200, 50),
point(50,50)).
<-member <-get_catch_all -name