]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/gadgets-docs.factor
394841c5995572db9cd36eb10108c1e849215b50
[factor.git] / basis / ui / gadgets / gadgets-docs.factor
1 USING: help.markup help.syntax opengl kernel strings
2        classes.tuple classes quotations models math.geometry.rect ;
3 IN: ui.gadgets
4
5 HELP: gadget-child
6 { $values { "gadget" gadget } { "child" gadget } }
7 { $description "Outputs the first child of the gadget. Typically this word is used with gadgets which are known to have an only child." } ;
8
9 HELP: nth-gadget
10 { $values { "n" "a non-negative integer" } { "gadget" gadget } { "child" gadget } }
11 { $description "Outputs the " { $snippet "n" } "th child of the gadget." }
12 { $errors "Throws an error if " { $snippet "n" } " is negative or greater than or equal to the number of children." } ;
13
14 HELP: <gadget>
15 { $values { "gadget" "a new " { $link gadget } } }
16 { $description "Creates a new gadget." } ;
17
18 HELP: relative-loc
19 { $values { "fromgadget" gadget } { "togadget" gadget } { "loc" "a pair of integers" } }
20 { $description
21     "Outputs the location of the top-left corner of " { $snippet "togadget" } " relative to the co-ordinate system of " { $snippet "fromgadget" } "."
22 }
23 { $errors
24     "Throws an error if " { $snippet "togadget" } " is not contained in a child of " { $snippet "fromgadget" } "."
25 } ;
26
27 HELP: user-input*
28 { $values { "str" string } { "gadget" gadget } { "?" "a boolean" } }
29 { $contract "Handle free-form textual input while the gadget has keyboard focus." } ;
30
31 HELP: children-on
32 { $values { "rect/point" "a " { $link rect } " or a pair of integers" } { "gadget" gadget } { "seq" "a sequence of gadgets" } }
33 { $contract "Outputs a sequence of gadgets which potentially intersect a rectangle or contain a point in the co-ordinate system of the gadget." }
34 { $notes "This does not have to be an accurate intersection test, and simply returning " { $snippet "children" } " is a valid implementation. However, an accurate intersection test reduces the amount of work done when drawing this gadget if it is partially clipped and not all children are visible." } ;
35
36 HELP: pick-up
37 { $values { "point" "a pair of integers" } { "gadget" gadget } { "child/f" "a " { $link gadget } " or " { $link f } } }
38 { $description "Outputs the child at a point in the gadget's co-ordinate system. This word recursively descends the gadget hierarchy, and so outputs the deepest child." } ;
39
40 HELP: max-dim
41 { $values { "dims" "a sequence of pairs of integers" } { "dim" "a pair of integers" } }
42 { $description "Outputs the smallest dimensions of a rectangle which can fit all the dimensions in the sequence." } ;
43
44 { pref-dims max-dim dim-sum } related-words
45
46 HELP: each-child
47 { $values { "gadget" gadget } { "quot" "a quotation with stack effect " { $snippet "( child -- )" } } }
48 { $description "Applies the quotation to each child of the gadget." } ;
49
50 HELP: gadget-selection?
51 { $values { "gadget" gadget } { "?" "a boolean" } }
52 { $contract "Outputs if the gadget has an active text selection; if so, the selected text can be obtained with a call to " { $link gadget-selection } "." } ;
53
54 HELP: gadget-selection
55 { $values { "gadget" gadget } { "string/f" "a " { $link string } " or " { $link f } } }
56 { $contract "Outputs the gadget's text selection, or " { $link f } " if nothing is selected." } ;
57
58 HELP: relayout
59 { $values { "gadget" gadget } }
60 { $description "Relayout and redraw a gadget before the next iteration of the event loop. Unlike " { $link relayout-1 } ", this relayouts all parents up to a gadget having " { $snippet "root?" } " set, so this word should be used when the gadget's dimensions have potentially changed." } ;
61
62 HELP: relayout-1
63 { $values { "gadget" gadget } }
64 { $description "Relayout and redraw a gadget before the next iteration of the event loop. Unlike " { $link relayout } ", this does not propagate requests up to the parent, and so this word should only be used when the gadget's internal layout or appearance has changed, but the dimensions have not." } ;
65
66 { relayout relayout-1 } related-words
67
68 HELP: pref-dim*
69 { $values { "gadget" gadget } { "dim" "a pair of integers" } }
70 { $contract "Outputs the preferred dimensions of the gadget, possibly computing them from the preferred dimensions of the gadget's children." }
71 { $notes "User code should not call this word directly, instead call " { $link pref-dim } "." } ;
72
73 HELP: pref-dim
74 { $values { "gadget" gadget } { "dim" "a pair of integers" } }
75 { $description "Outputs the preferred dimensions of the gadget. The value is cached between calls, and invalidated when the gadget needs to be relayout." } ;
76
77 HELP: pref-dims
78 { $values { "gadgets" "a sequence of gadgets" } { "seq" "a sequence of pairs of integers" } }
79 { $description "Collects the preferred dimensions of every gadget in the sequence into a new sequence." } ;
80
81 HELP: layout*
82 { $values { "gadget" gadget } }
83 { $contract "Lays out the children of the gadget according to the gadget's policy. The dimensions of the gadget are already set by the parent by the time this word is called." }
84 { $notes "User code should not call this word directly, instead call " { $link relayout } " and " { $link relayout-1 } "." } ;
85
86 HELP: prefer
87 { $values { "gadget" gadget } }
88 { $contract "Resizes the gadget to assume its preferred dimensions." } ;
89
90 HELP: dim-sum
91 { $values { "seq" "a sequence of pairs of integers" } { "dim" "a pair of integers" } }
92 { $description "Sums a sequence of dimensions." } ;
93
94 HELP: layout
95 { $values { "gadget" gadget } }
96 { $description "Lays out the children of the gadget if the gadget needs to be relayout, and otherwise does nothing." }
97 { $notes "User code should not call this word directly, instead call " { $link relayout } " and " { $link relayout-1 } "." } ;
98
99 { pref-dim pref-dim* layout layout* } related-words
100
101 HELP: graft*
102 { $values { "gadget" gadget } }
103 { $contract "Called to notify the gadget it has become visible on the screen. This should set up timers and threads, and acquire any resources used by the gadget." } ;
104
105 { graft graft* ungraft ungraft* } related-words
106
107 HELP: ungraft*
108 { $values { "gadget" gadget } }
109 { $contract "Called to notify the gadget it is no longer visible on the screen. This should stop timers and threads, and release any resources used by the gadget." } ;
110
111 HELP: graft
112 { $values { "gadget" gadget } }
113 { $description "Calls " { $link graft* } " on the gadget and all children." }
114 { $notes "This word should never be called directly." } ;
115
116 HELP: ungraft
117 { $values { "gadget" gadget } }
118 { $description "If the gadget is grafted, calls " { $link ungraft* } " on the gadget and all children." }
119 { $notes "This word should never be called directly." } ;
120
121 HELP: unparent
122 { $values { "gadget" gadget } }
123 { $description "Removes the gadget from its parent. This will relayout the parent." }
124 { $notes "This may result in " { $link ungraft* } " being called on the gadget and its children, if the gadget's parent is visible on the screen." } ;
125
126 HELP: clear-gadget
127 { $values { "gadget" gadget } }
128 { $description "Removes all children from the gadget. This will relayout the gadget." }
129 { $notes "This may result in " { $link ungraft* } " being called on the children, if the gadget is visible on the screen." }
130 { $side-effects "gadget" } ;
131
132 HELP: add-gadget
133 { $values { "parent" gadget } { "child" gadget } }
134 { $description "Adds a child gadget to a parent. If the gadget is contained in another gadget, " { $link unparent } " is called on the gadget first. The parent will be relayout." }
135 { $notes "Adding a gadget to a parent may result in " { $link graft* } " being called on the children, if the parent is visible on the screen." }
136 { $side-effects "parent" } ;
137
138 HELP: add-gadgets
139 { $values { "parent" gadget } { "children" "a sequence of gadgets" } }
140 { $description "Adds a sequence of gadgets to a parent. The parent will be relayout." }
141 { $notes "This may result in " { $link graft* } " being called on the children, if the parent is visible on the screen." }
142 { $side-effects "parent" } ;
143
144 HELP: parents
145 { $values { "gadget" gadget } { "seq" "a sequence of gadgets" } }
146 { $description "Outputs a sequence of all parents of the gadget, with the first element being the gadget itself." } ;
147
148 HELP: each-parent
149 { $values { "gadget" gadget } { "quot" "a quotation with stack effect " { $snippet "( gadget -- ? )" } } { "?" "a boolean" } }
150 { $description "Applies the quotation to every parent of the gadget, starting from the gadget itself, stopping if the quotation yields " { $link f } ". Outputs " { $link t } " if the iteration completed, and outputs " { $link f } " if it was stopped prematurely." } ;
151
152 HELP: find-parent
153 { $values { "gadget" gadget } { "quot" "a quotation with stack effect " { $snippet "( gadget -- ? )" } } { "parent" gadget } }
154 { $description "Outputs the first parent of the gadget, starting from the gadget itself, for which the quotation outputs a true value, or " { $link f } " if the quotation outputs " { $link f } " for every parent." } ;
155
156 HELP: screen-loc
157 { $values { "gadget" gadget } { "loc" "a pair of integers" } }
158 { $description "Outputs the location of the gadget relative to the top-left corner of the world containing the gadget. This word does not output a useful value if the gadget is not grafted." } ;
159
160 HELP: child?
161 { $values { "parent" gadget } { "child" gadget } { "?" "a boolean" } }
162 { $description "Tests if " { $snippet "child" } " is contained inside " { $snippet "parent" } "." } ;
163
164 HELP: focusable-child*
165 { $values { "gadget" gadget } { "child/t" "a " { $link gadget } " or " { $link t } } }
166 { $description "Outputs the child of the gadget which would prefer to receive keyboard focus, or " { $link t } " if the gadget itself should receive focus." }
167 { $examples "For example, if your gadget consists of an editor together with an output area whose contents react to changes in editor contents, then the " { $link focusable-child* } " method for your gadget class should return the editor, so that when the gadget is displayed in a window or passed to " { $link request-focus } ", the editor receives keyboard focus automatically." } ;
168
169 HELP: focusable-child
170 { $values { "gadget" gadget } { "child" gadget } }
171 { $description "Outputs the child of the gadget which would prefer to receive keyboard focus." } ;
172
173 { control-value set-control-value } related-words
174
175 HELP: control-value
176 { $values { "control" gadget } { "value" object } }
177 { $description "Outputs the value of the control's model." } ;
178
179 HELP: set-control-value
180 { $values { "value" object } { "control" gadget } }
181 { $description "Sets the value of the control's model." } ;
182
183 ARTICLE: "ui-control-impl" "Implementing controls"
184 "A " { $emphasis "control" } " is a gadget which is linked to an underlying " { $link model } " by having its " { $snippet "model" } " slot set to a " { $link model } " instance."
185 $nl
186 "Some utility words useful in control implementations:"
187 { $subsection control-value }
188 { $subsection set-control-value }
189 { $see-also "models" } ;