]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/gadgets-docs.factor
improve help by linking to types directly.
[factor.git] / basis / ui / gadgets / gadgets-docs.factor
1 USING: help.markup help.syntax opengl kernel strings
2 classes.tuple classes quotations models math.rectangles
3 ui.gadgets.private accessors ;
4 IN: ui.gadgets
5
6 HELP: gadget-child
7 { $values { "gadget" gadget } { "child" gadget } }
8 { $description "Outputs the first child of the gadget. Typically this word is used with gadgets which are known to have an only child." } ;
9
10 HELP: nth-gadget
11 { $values { "n" "a non-negative integer" } { "gadget" gadget } { "child" gadget } }
12 { $description "Outputs the " { $snippet "n" } "th child of the gadget." }
13 { $errors "Throws an error if " { $snippet "n" } " is negative or greater than or equal to the number of children." } ;
14
15 HELP: <gadget>
16 { $values { "gadget" "a new " { $link gadget } } }
17 { $description "Creates a new gadget." } ;
18
19 HELP: relative-loc
20 { $values { "fromgadget" gadget } { "togadget" gadget } { "loc" "a pair of integers" } }
21 { $description
22     "Outputs the location of the top-left corner of " { $snippet "togadget" } " relative to the co-ordinate system of " { $snippet "fromgadget" } "."
23 }
24 { $errors
25     "Throws an error if " { $snippet "togadget" } " is not contained in a child of " { $snippet "fromgadget" } "."
26 } ;
27
28 HELP: user-input*
29 { $values { "str" string } { "gadget" gadget } { "?" boolean } }
30 { $contract "Handle free-form textual input while the gadget has keyboard focus." } ;
31
32 HELP: children-on
33 { $values { "rect" rect } { "gadget" gadget } { "seq" "a sequence of gadgets" } }
34 { $contract "Outputs a sequence of gadgets which potentially intersect a rectangle in the co-ordinate system of the gadget." }
35 { $notes "This does not have to be an accurate intersection test, and simply returning " { $link 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." } ;
36
37 HELP: pick-up
38 { $values { "point" "a pair of integers" } { "gadget" gadget } { "child/f" { $maybe gadget } } }
39 { $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." } ;
40
41 HELP: max-dims
42 { $values { "seq" "a sequence of pairs of integers" } { "dim" "a pair of integers" } }
43 { $description "Outputs the smallest dimensions of a rectangle which can fit all the dimensions in the sequence." } ;
44
45 { pref-dims max-dims sum-dims } related-words
46
47 HELP: each-child
48 { $values { "gadget" gadget } { "quot" { $quotation ( child -- ) } } }
49 { $description "Applies the quotation to each child of the gadget." } ;
50
51 HELP: gadget-selection?
52 { $values { "gadget" gadget } { "?" boolean } }
53 { $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 } "." } ;
54
55 HELP: gadget-selection
56 { $values { "gadget" gadget } { "string/f" { $maybe string } } }
57 { $contract "Outputs the gadget's text selection, or " { $link f } " if nothing is selected." } ;
58
59 HELP: relayout
60 { $values { "gadget" gadget } }
61 { $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." } ;
62
63 HELP: relayout-1
64 { $values { "gadget" gadget } }
65 { $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." } ;
66
67 { relayout relayout-1 } related-words
68
69 HELP: pref-dim*
70 { $values { "gadget" gadget } { "dim" "a pair of integers" } }
71 { $contract "Outputs the preferred dimensions of the gadget, possibly computing them from the preferred dimensions of the gadget's children." }
72 { $notes "User code should not call this word directly, instead call " { $link pref-dim } "." } ;
73
74 HELP: pref-dim
75 { $values { "gadget" gadget } { "dim" "a pair of integers" } }
76 { $description "Outputs the preferred dimensions of the gadget. The value is cached between calls, and invalidated when the gadget needs to be relayout." } ;
77
78 HELP: pref-dims
79 { $values { "gadgets" "a sequence of gadgets" } { "seq" "a sequence of pairs of integers" } }
80 { $description "Collects the preferred dimensions of every gadget in the sequence into a new sequence." } ;
81
82 HELP: layout*
83 { $values { "gadget" gadget } }
84 { $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." }
85 { $notes "User code should not call this word directly, instead call " { $link relayout } " and " { $link relayout-1 } "." } ;
86
87 HELP: prefer
88 { $values { "gadget" gadget } }
89 { $contract "Resizes the gadget to assume its preferred dimensions." } ;
90
91 HELP: sum-dims
92 { $values { "seq" "a sequence of pairs of integers" } { "dim" "a pair of integers" } }
93 { $description "Sums a sequence of dimensions." } ;
94
95 HELP: layout
96 { $values { "gadget" gadget } }
97 { $description "Lays out the children of the gadget if the gadget needs to be relayout, and otherwise does nothing." }
98 { $notes "User code should not call this word directly, instead call " { $link relayout } " and " { $link relayout-1 } "." } ;
99
100 { pref-dim pref-dim* layout layout* } related-words
101
102 HELP: graft*
103 { $values { "gadget" gadget } }
104 { $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." } ;
105
106 { graft graft* ungraft ungraft* } related-words
107
108 HELP: ungraft*
109 { $values { "gadget" gadget } }
110 { $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." } ;
111
112 HELP: graft
113 { $values { "gadget" gadget } }
114 { $description "Calls " { $link graft* } " on the gadget and all children." }
115 { $notes "This word should never be called directly." } ;
116
117 HELP: ungraft
118 { $values { "gadget" gadget } }
119 { $description "If the gadget is grafted, calls " { $link ungraft* } " on the gadget and all children." }
120 { $notes "This word should never be called directly." } ;
121
122 HELP: unparent
123 { $values { "gadget" gadget } }
124 { $description "Removes the gadget from its parent. This will relayout the parent." }
125 { $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." } ;
126
127 HELP: clear-gadget
128 { $values { "gadget" gadget } }
129 { $description "Removes all children from the gadget. This will relayout the gadget." }
130 { $notes "This may result in " { $link ungraft* } " being called on the children, if the gadget is visible on the screen." }
131 { $side-effects "gadget" } ;
132
133 HELP: add-gadget
134 { $values { "parent" gadget } { "child" gadget } }
135 { $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." }
136 { $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." }
137 { $side-effects "parent" } ;
138
139 HELP: add-gadgets
140 { $values { "parent" gadget } { "children" "a sequence of gadgets" } }
141 { $description "Adds a sequence of gadgets to a parent. The parent will be relayout." }
142 { $notes "This may result in " { $link graft* } " being called on the children, if the parent is visible on the screen." }
143 { $side-effects "parent" } ;
144
145 HELP: parents
146 { $values { "gadget" gadget } { "seq" "a sequence of gadgets" } }
147 { $description "Outputs a sequence of all parents of the gadget, with the first element being the gadget itself." } ;
148
149 HELP: each-parent
150 { $values { "gadget" gadget } { "quot" { $quotation ( gadget -- ? ) } } { "?" boolean } }
151 { $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." } ;
152
153 HELP: find-parent
154 { $values { "gadget" gadget } { "quot" { $quotation ( gadget -- ? ) } } { "parent" gadget } }
155 { $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." } ;
156
157 HELP: screen-loc
158 { $values { "gadget" gadget } { "loc" "a pair of integers" } }
159 { $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." } ;
160
161 HELP: child?
162 { $values { "parent" gadget } { "child" gadget } { "?" boolean } }
163 { $description "Tests if " { $snippet "child" } " is contained inside " { $snippet "parent" } "." } ;
164
165 HELP: focusable-child*
166 { $values { "gadget" gadget } { "child/t" "a " { $link gadget } " or " { $link t } } }
167 { $description "Outputs the child of the gadget which would prefer to receive keyboard focus, or " { $link t } " if the gadget itself should receive focus." }
168 { $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." } ;
169
170 HELP: focusable-child
171 { $values { "gadget" gadget } { "child" gadget } }
172 { $description "Outputs the child of the gadget which would prefer to receive keyboard focus." } ;
173
174 { control-value set-control-value } related-words
175
176 HELP: control-value
177 { $values { "control" gadget } { "value" object } }
178 { $description "Outputs the value of the control's model." } ;
179
180 HELP: set-control-value
181 { $values { "value" object } { "control" gadget } }
182 { $description "Sets the value of the control's model." } ;
183
184 ARTICLE: "ui-control-impl" "Implementing controls"
185 "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."
186 $nl
187 "Some utility words useful in control implementations:"
188 { $subsections
189     control-value
190     set-control-value
191 }
192 { $see-also "models" } ;