trebol-dev 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/move.trb ADDED
@@ -0,0 +1,129 @@
1
+ Trebol [
2
+ title: "Moving a face: beside another anywhere in the file, or into a box; and a step up or down that goes in and out of boxes"
3
+ exports: [boxes pane-block count-inside move-to move-step]
4
+ ]
5
+
6
+ ; A move gives new text and where the face moved is in the structure afterwards (its index in
7
+ ; shown-faces). The face's code goes with its comment; its lines are indented as the place it goes.
8
+
9
+ import %model.trb
10
+ import %options.trb
11
+
12
+ ; the styles whose block holds faces: what is added with one of them chosen goes inside it
13
+ boxes: [view row column panel form grid scroll dialog device]
14
+
15
+ pane-block: function ["The block a face's faces are written in, or none: a view's, a screen's, a box's, a rows' template" d [object!] f [object!]] [
16
+ if b: own-block d f [return b]
17
+ ; rows: the faces of one row, its template
18
+ if f/style = 'rows [
19
+ r: face-range d f
20
+ foreach p face-parts d f [
21
+ if all [p/what = 'block p/e/field = first [template:]] [return pick r/1 p/from]
22
+ ]
23
+ ]
24
+ unless all [find boxes f/style r: face-range d f] [return none]
25
+ b: pick r/1 r/3
26
+ either block? b [b] [none]
27
+ ]
28
+
29
+ count-inside: function ["How many faces of the structure a face holds" d [object!] f [object!]] [
30
+ n: 0
31
+ ; as the structure lists them: every face written, and those inside one that is not, as the entry of rows
32
+ foreach g any [pane-of d f []] [n: n + (either face-range d g [1] [0]) + count-inside d g]
33
+ n
34
+ ]
35
+
36
+ ; a face that can move: written, and not a view, a screen, a tab or a step
37
+ movable?: function [d f] [all [f face-range d f not own-block d f]]
38
+
39
+ ; the faces written in the same block as a face, in order
40
+ siblings: function [d f] [
41
+ r: face-range d f
42
+ collect [foreach g shown-faces d [if all [movable? d g q: face-range d g same? head q/1 head r/1] [keep g]]]
43
+ ]
44
+
45
+ ; the face whose faces it is one of
46
+ holder: function [d f] [
47
+ r: face-range d f
48
+ foreach g shown-faces d [if all [b: pane-block d g same? head b head r/1] [return g]]
49
+ none
50
+ ]
51
+
52
+ ; the code of a face, its comment too, its lines after the first a step out of where it is written
53
+ code-of: function [d f] [
54
+ s: face-span d f
55
+ code: copy/part at d/text s/x (after-line d/text s/x + s/y) - s/x
56
+ replace/all code rejoin [newline indent-at d/text s/x] newline
57
+ ]
58
+
59
+ move-to: function [
60
+ "New text and the face's index in shown-faces after moving it: where is [before g], [after g] or [into g]; none when it cannot go there"
61
+ d [object!] f [object!] where [block!]
62
+ ] [
63
+ how: where/1
64
+ g: where/2
65
+ unless all [movable? d f g not same? f g not inside? d g f] [return none]
66
+ if find [before after] how [unless movable? d g [return none]]
67
+ if how = 'into [unless b: pane-block d g [return none]]
68
+ s: face-span d f
69
+ code: code-of d f
70
+ t: face-span d g
71
+ ; the new text with the code where it goes, and where that is
72
+ switch how [
73
+ before [
74
+ indent: indent-at d/text t/x
75
+ ip: t/x
76
+ new: splice d/text ip 0 rejoin [replace/all copy code newline rejoin [newline indent] newline indent]
77
+ ]
78
+ after [
79
+ ip: t/x + t/y
80
+ new: insert-after d g code
81
+ ]
82
+ into [
83
+ o: block-span d b
84
+ ip: o/x + o/y - 1
85
+ ; already the last of its block: nowhere to go
86
+ r: face-range d f
87
+ if all [same? head r/1 head b r/3 = length? b] [return none]
88
+ new: insert-into d b code
89
+ ]
90
+ ]
91
+ unless new [return none]
92
+ ; the face goes from where it was: later in the text it moved by what was put before it
93
+ unless ip > s/x [s: as-pair s/x + (length? new) - (length? d/text) s/y]
94
+ new: cut new s
95
+ ; where it is in the structure now: where it went among the faces, those it held left out
96
+ fs: shown-faces d
97
+ there: index? find/same fs g
98
+ pos: switch how [
99
+ before [there]
100
+ after [there + 1 + count-inside d g]
101
+ into [there + 1 + count-inside d g]
102
+ ]
103
+ was: index? find/same fs f
104
+ reduce [new either pos > was [pos - 1 - count-inside d f] [pos]]
105
+ ]
106
+
107
+ move-step: function [
108
+ "New text and index after a step up (by -1) or down (by 1): past the face beside it, into a box beside it, or out of its box; none when it cannot"
109
+ d [object!] f [object!] by [integer!]
110
+ ] [
111
+ unless movable? d f [return none]
112
+ sib: siblings d f
113
+ n: index? find/same sib f
114
+ next-one: pick sib n + by
115
+ if all [by < 0 n = 1] [next-one: none]
116
+ either next-one [
117
+ either pane-block d next-one [
118
+ ; a box beside it: in as its first face going down, as its last going up
119
+ inner: collect [foreach g shown-faces d [if all [q: face-range d g same? head q/1 head pane-block d next-one movable? d g] [keep g]]]
120
+ either all [by > 0 not empty? inner] [move-to d f reduce ['before first inner]] [move-to d f reduce ['into next-one]]
121
+ ] [
122
+ move-to d f reduce [either by > 0 ['after] ['before] next-one]
123
+ ]
124
+ ] [
125
+ ; the first or last of its box: out of it, beside it
126
+ unless all [h: holder d f movable? d h] [return none]
127
+ move-to d f reduce [either by > 0 ['after] ['before] h]
128
+ ]
129
+ ]
@@ -0,0 +1,404 @@
1
+ Trebol [
2
+ title: "What each value a face was written with is, read from what its style takes, and the edits of its options"
3
+ exports: [
4
+ style-def-of face-parts option-rows option-of group-part row-values custom-rule-words
5
+ set-option remove-option set-event remove-event set-reaction set-hint set-action
6
+ insert-option-at values-span
7
+ ]
8
+ ]
9
+
10
+ import %model.trb
11
+
12
+ ; Every style says what it takes (takes: in its definition, read into ui-style-defs), so the
13
+ ; designer reads a face the way layout does: after its style, each value is tried against the
14
+ ; entries that start with a word, then against those of a type; strings are its text and hint,
15
+ ; on-xxx blocks its handlers, is, calc and react what it follows, and blocks go in turn to the
16
+ ; entries that take one, the last being its action. Nothing here names a style: a style a
17
+ ; package defines is read and edited the same.
18
+
19
+ part: make object! [
20
+ what: none ; global label style name entry text hint event reaction block action computed stray
21
+ e: none ; the take-entry of an entry or block
22
+ word: none ; the event, or is calc react, or the custom rule
23
+ from: none ; the first index in the face's loaded block
24
+ to: none ; the last
25
+ ]
26
+
27
+ style-def-of: function ["The definition of the style a face was written with" d [object!] f [object!]] [
28
+ w: style-word d f
29
+ any [select d/defs w select ui-style-defs w select ui-style-defs f/style]
30
+ ]
31
+
32
+ ; the words that start an entry of a definition, and the words of its one-of lists
33
+ entry-words: function [def] [
34
+ out: copy []
35
+ foreach e def/entries [
36
+ if e/kw [append out e/kw]
37
+ foreach a e/args [if all [block? a 'one-of = first a] [append out choices-of a]]
38
+ ]
39
+ unique out
40
+ ]
41
+
42
+ choices-of: func [a] [either word? a/2 [get a/2] [a/2]]
43
+
44
+ custom-rule-words: function ["The rules programs and packages added with rule"] [
45
+ taken: copy words-of styles
46
+ foreach n keys-of ui-style-defs [append taken entry-words select ui-style-defs n]
47
+ append taken [global required react is calc later]
48
+ exclude ui-dialect-words taken
49
+ ]
50
+
51
+ event-word?: func [w] [all [word? :w "on-" = copy/part form w 3]]
52
+
53
+ ; A word right after the style names the field or labels the face when it is no word of the style
54
+ name-word?: function [def w customs] [
55
+ not any [
56
+ not word? :w
57
+ event-word? w
58
+ find [global required react is calc] w
59
+ all [any [find entry-words def w find customs w] not find [email url integer] w]
60
+ ]
61
+ ]
62
+
63
+ arg-at?: function [a b [block!] i [integer!]] [
64
+ if i > length? b [return false]
65
+ v: pick b i
66
+ case [
67
+ ; compose puts a value there when the screen is shown
68
+ paren? :v [true]
69
+ a = 'text [any [string? :v map? :v lit-word? :v]]
70
+ 'one-of = first a [all [word? :v to logic! find choices-of a v]]
71
+ true [
72
+ rule: copy []
73
+ foreach t a [unless empty? rule [append rule '|] append rule t]
74
+ parse copy/part at b i 1 rule
75
+ ]
76
+ ]
77
+ ]
78
+
79
+ ; where entry e, tried at index i of b, ends; none when what is there is not its
80
+ take-at: function [e b [block!] i [integer!] last-i [integer!] customs] [
81
+ w: pick b i
82
+ switch e/how [
83
+ flag [return all [word? :w w = e/kw i]]
84
+ custom [return all [word? :w find customs w i]]
85
+ name label block [return none]
86
+ ]
87
+ k: i
88
+ ; a value compose puts in is taken only after a word that starts an entry, as layout reads it
89
+ if all [e/how = 'value paren? :w] [return none]
90
+ if find [keyword rule] e/how [
91
+ unless all [word? :w w = e/kw] [return none]
92
+ k: i + 1
93
+ ]
94
+ foreach a e/args [
95
+ unless all [k <= last-i arg-at? a b k] [return none]
96
+ k: k + 1
97
+ ]
98
+ k - 1
99
+ ]
100
+
101
+ one-of-value?: func [e] [all [e/how = 'value block? first e/args 'one-of = first first e/args]]
102
+
103
+ ; Whether entry x, a block's, took a block of face f: its function may say no, as grid's weights
104
+ ; do to the faces' block, so the face as layout read it says: the field changed, and no value of
105
+ ; another entry had filled it.
106
+ block-took?: function [def f x parts] [
107
+ unless x/fn [return true]
108
+ unless set-word? x/field [return true]
109
+ w: to word! x/field
110
+ foreach p parts [if all [p/e p/e/field = x/field] [return false]]
111
+ v: select f w
112
+ not any [none? :v same? :v select def/proto w]
113
+ ]
114
+
115
+ face-parts: function [
116
+ "The parts of what a face was written with, in order: what each is and where it sits in its loaded block"
117
+ d [object!] f [object!]
118
+ ] [
119
+ r: face-range d f
120
+ b: r/1 i: r/2 z: r/3
121
+ def: style-def-of d f
122
+ customs: custom-rule-words
123
+ out: copy []
124
+ add-part: func [what from to /with e word] [
125
+ p: make part []
126
+ p/what: what p/from: from p/to: to p/e: e p/word: word
127
+ append out p
128
+ ]
129
+ ; a view has no word of its own: its words start its block
130
+ unless own-block d f [
131
+ if 'global = pick b i [add-part 'global i i i: i + 1]
132
+ if set-word? pick b i [add-part 'label i i i: i + 1]
133
+ add-part 'style i i i: i + 1
134
+ ]
135
+ foreach e def/entries [
136
+ if all [e/lead i <= z] [
137
+ w: pick b i
138
+ case [
139
+ find [name label] e/how [if name-word? def :w customs [add-part/with e/how i i e none i: i + 1]]
140
+ q: take-at e b i z customs [add-part/with 'entry i q e none i: q + 1]
141
+ ]
142
+ ]
143
+ ]
144
+ texts: 0
145
+ blocks: copy []
146
+ while [i <= z] [
147
+ v: pick b i
148
+ q: none
149
+ foreach e def/entries [
150
+ if all [not q not e/lead any [e/how <> 'value one-of-value? e]] [
151
+ if q: take-at e b i z customs [add-part/with 'entry i q e (all [e/how = 'custom v])]
152
+ ]
153
+ ]
154
+ unless q [foreach e def/entries [
155
+ if all [not q not e/lead e/how = 'value] [if q: take-at e b i z customs [add-part/with 'entry i q e none]]
156
+ ]]
157
+ unless q [case [
158
+ any [string? :v map? :v lit-word? :v] [
159
+ texts: texts + 1
160
+ add-part either texts = 1 ['text] ['hint] i i
161
+ q: i
162
+ ]
163
+ all [event-word? :v i < z block? pick b i + 1] [add-part/with 'event i i + 1 none v q: i + 1]
164
+ all [find [calc is] :v i < z block? pick b i + 1] [add-part/with 'reaction i i + 1 none v q: i + 1]
165
+ all ['react = :v i < z] [
166
+ q: either all ['later = pick b i + 1 i + 1 < z] [i + 2] [i + 1]
167
+ either block? pick b q [add-part/with 'reaction i q none 'react] [add-part 'stray i i q: i]
168
+ ]
169
+ block? :v [
170
+ e: none
171
+ n: 0
172
+ foreach x def/entries [
173
+ n: n + 1
174
+ if all [not e x/how = 'block not find blocks n block-took? def f x out] [e: x append blocks n]
175
+ ]
176
+ either e [add-part/with 'block i i e none] [add-part 'action i i]
177
+ q: i
178
+ ]
179
+ paren? :v [add-part 'computed i i q: i]
180
+ true [add-part 'stray i i q: i]
181
+ ]]
182
+ i: q + 1
183
+ ]
184
+ out
185
+ ]
186
+
187
+ ; --- the options a face's style takes, as the designer shows them --------------------------
188
+
189
+ option-rows: function [
190
+ "Each option a face's style takes, its own first, then those of the style it is made from: [style [group ...] ...]"
191
+ def [object!]
192
+ ] [
193
+ ; a group is the entries that are one option: those that fill one field with a value or a
194
+ ; block, as grid 3 and grid [1 2 1] do, or kind right after chart and later
195
+ out: copy []
196
+ seen: copy []
197
+ s: def
198
+ while [s] [
199
+ gs: copy []
200
+ foreach e s/own [
201
+ key: either find [value block] e/how [reduce [e/field 'bare]] [reduce [e/field e/how e/kw mold e/args]]
202
+ either g: select/only seen key [
203
+ unless find collect [foreach x g [keep mold x/args]] mold e/args [append g e]
204
+ ] [
205
+ g: reduce [e]
206
+ append/only seen key
207
+ append/only seen g
208
+ append/only gs g
209
+ ]
210
+ ]
211
+ unless empty? gs [append out reduce [s/name gs]]
212
+ s: s/parent
213
+ ]
214
+ out
215
+ ]
216
+
217
+ group-part: function ["The part a face has of an option, a group of entries: [part entry], or none" parts [block!] es [block!]] [
218
+ foreach e es [if p: option-of parts e [return reduce [p e]]]
219
+ none
220
+ ]
221
+
222
+ same-entry?: func [a b] [
223
+ all [a b a/field = b/field a/how = b/how a/kw = b/kw (mold a/args) = mold b/args]
224
+ ]
225
+
226
+ option-of: function [
227
+ "The part of a face that entry e took, or none; for a custom rule, the part of that rule"
228
+ parts [block!] e [object!] /rule w
229
+ ] [
230
+ foreach p parts [
231
+ if all [find [entry block name label] p/what same-entry? p/e e any [not rule p/word = w]] [return p]
232
+ ]
233
+ none
234
+ ]
235
+
236
+ row-values: function [
237
+ "The values of an option a face has: what follows its word"
238
+ d [object!] f [object!] p [object!]
239
+ ] [
240
+ r: face-range d f
241
+ from: either all [p/e p/e/kw find [keyword rule] p/e/how] [p/from + 1] [p/from]
242
+ copy/part at r/1 from p/to - from + 1
243
+ ]
244
+
245
+ values-span: function ["Where the values from one index to another of a loaded block sit" d [object!] b [block!] from [integer!] to [integer!]] [
246
+ a: span-of d b from
247
+ z: span-of d b to
248
+ as-pair a/x z/x + z/y - a/x
249
+ ]
250
+
251
+ ; where a new option goes: after the last value that is no block nor handler, so on the face's first line
252
+ insert-option-at: function ["The index in the text where a new option of a face goes" d [object!] f [object!]] [
253
+ r: face-range d f
254
+ n: r/2
255
+ ; a view with no words of its own yet: they go at the start of its block
256
+ if r/3 < r/2 [return 1 + first block-span d r/1]
257
+ foreach p face-parts d f [
258
+ if find [global label style name entry text hint computed stray] p/what [n: p/to]
259
+ ]
260
+ s: span-of d r/1 n
261
+ s/x + s/y
262
+ ]
263
+
264
+ molded: function [vals [block!]] [mold/only vals]
265
+
266
+ set-option: function [
267
+ "The text with an option of a face set to values (none for a flag): written anew where it is, or added"
268
+ d [object!] f [object!] e [object!] vals [block! none!] /rule w /over q [object!] "In place of the part of another entry of the option"
269
+ ] [
270
+ parts: face-parts d f
271
+ p: either rule [option-of/rule parts e w] [option-of parts e]
272
+ r: face-range d f
273
+ vals: any [vals copy []]
274
+ if all [over not p] [
275
+ s: values-span d r/1 q/from q/to
276
+ return splice d/text s/x s/y either e/kw [rejoin [e/kw " " molded vals]] [molded vals]
277
+ ]
278
+ if p [
279
+ if find [flag custom] e/how [return d/text]
280
+ from: either all [e/kw find [keyword rule] e/how] [p/from + 1] [p/from]
281
+ if from > p/to [return d/text]
282
+ s: values-span d r/1 from p/to
283
+ return splice d/text s/x s/y molded vals
284
+ ]
285
+ code: case [
286
+ e/how = 'custom [form w]
287
+ e/kw [either empty? vals [form e/kw] [rejoin [e/kw " " molded vals]]]
288
+ true [molded vals]
289
+ ]
290
+ if e/lead [
291
+ ; right after the style, after the ones before it
292
+ n: none
293
+ foreach q parts [if any [q/what = 'style all [q/e q/e/lead]] [n: q/to]]
294
+ s: span-of d r/1 n
295
+ return splice d/text s/x + s/y 0 rejoin [" " code]
296
+ ]
297
+ either e/how = 'block [
298
+ ; blocks are taken in turn: it goes before the first that comes after it, and the action
299
+ def: style-def-of d f
300
+ mine: index? find/same def/entries e
301
+ before: none
302
+ foreach q parts [
303
+ if all [not before any [
304
+ q/what = 'action
305
+ all [q/what = 'block mine < index? find/same def/entries q/e]
306
+ ]] [before: q]
307
+ ]
308
+ either before [
309
+ s: span-of d r/1 before/from
310
+ splice d/text s/x 0 rejoin [code " "]
311
+ ] [
312
+ s: face-span d f
313
+ splice d/text s/x + s/y 0 rejoin [" " code]
314
+ ]
315
+ ] [
316
+ either all [own-block d f r/3 < r/2] [view-words-at d r/1 code] [
317
+ splice d/text insert-option-at d f 0 rejoin [" " code]
318
+ ]
319
+ ]
320
+ ]
321
+
322
+ ; the first words of a view: a line of their own before its first face, or its whole block
323
+ view-words-at: function [d [object!] b [block!] code [string!]] [
324
+ if empty? b [return insert-into d b code]
325
+ s: span-of d b 1
326
+ splice d/text s/x 0 rejoin [code newline indent-at d/text s/x]
327
+ ]
328
+
329
+ remove-option: function [
330
+ "The text without an option of a face"
331
+ d [object!] f [object!] e [object!] /rule w
332
+ ] [
333
+ parts: face-parts d f
334
+ p: either rule [option-of/rule parts e w] [option-of parts e]
335
+ unless p [return d/text]
336
+ r: face-range d f
337
+ cut d/text values-span d r/1 p/from p/to
338
+ ]
339
+
340
+ part-of: function [parts what word] [
341
+ foreach p parts [if all [p/what = what p/word = word] [return p]]
342
+ none
343
+ ]
344
+
345
+ set-event: function ["The text with a face's handler of an event set to code" d [object!] f [object!] ev [word!] code [block!]] [
346
+ r: face-range d f
347
+ either p: part-of face-parts d f 'event ev [
348
+ replace-value d r/1 p/to code
349
+ ] [
350
+ s: face-span d f
351
+ splice d/text s/x + s/y 0 rejoin [" " ev " " mold code]
352
+ ]
353
+ ]
354
+
355
+ set-action: function [
356
+ "The text with what a face does when clicked, the block after it, set to code; none takes it out"
357
+ d [object!] f [object!] code [block! none!]
358
+ ] [
359
+ r: face-range d f
360
+ p: part-of face-parts d f 'action none
361
+ case [
362
+ all [p code] [replace-value d r/1 p/to code]
363
+ p [cut d/text values-span d r/1 p/from p/to]
364
+ ; blocks are taken in turn: the action comes after them all
365
+ code [s: face-span d f splice d/text s/x + s/y 0 rejoin [" " mold code]]
366
+ true [d/text]
367
+ ]
368
+ ]
369
+
370
+ remove-event: function ["The text without a face's handler of an event" d [object!] f [object!] ev [word!]] [
371
+ r: face-range d f
372
+ either p: part-of face-parts d f 'event ev [cut d/text values-span d r/1 p/from p/to] [d/text]
373
+ ]
374
+
375
+ set-reaction: function [
376
+ "The text with what a face follows (is, calc or react) set to code; none takes it out"
377
+ d [object!] f [object!] kind [word!] code [block! none!]
378
+ ] [
379
+ r: face-range d f
380
+ p: part-of face-parts d f 'reaction kind
381
+ case [
382
+ all [p code] [replace-value d r/1 p/to code]
383
+ p [cut d/text values-span d r/1 p/from p/to]
384
+ code [splice d/text insert-option-at d f 0 rejoin [" " kind " " mold code]]
385
+ true [d/text]
386
+ ]
387
+ ]
388
+
389
+ set-hint: function ["The text with the hint a face shows changed, added or, empty, taken out" d [object!] f [object!] new [string!]] [
390
+ parts: face-parts d f
391
+ r: face-range d f
392
+ p: part-of parts 'hint none
393
+ case [
394
+ all [p empty? new] [cut d/text values-span d r/1 p/from p/to]
395
+ p [replace-value d r/1 p/from new]
396
+ empty? new [d/text]
397
+ t: part-of parts 'text none [
398
+ s: span-of d r/1 t/to
399
+ splice d/text s/x + s/y 0 rejoin [" " mold new]
400
+ ]
401
+ ; a hint needs a text before it
402
+ true [splice d/text insert-option-at d f 0 rejoin [" " mold "" " " mold new]]
403
+ ]
404
+ ]
@@ -0,0 +1,145 @@
1
+ Trebol [
2
+ title: "What the designer adds"
3
+ exports: [palette palette-code palette-menu]
4
+ ]
5
+
6
+ ; Each group of the Add menu: a title, then for each item the word the menu gives, its text and the code
7
+ ; it adds. Every style of the dialect is here; app.test.trb lays each out to see that it loads with no problem.
8
+ palette: [
9
+ "Layout" [
10
+ grid-2 "Two columns" {grid 2 [
11
+ text "Left"
12
+ text "Right"
13
+ ]}
14
+ grid-3 "Three columns" {grid 3 [
15
+ text "One"
16
+ text "Two"
17
+ text "Three"
18
+ ]}
19
+ grid-side "Side column and content" {grid [small 1] [
20
+ panel "Side" []
21
+ panel "Content" []
22
+ ]}
23
+ row "Row" {row []}
24
+ column "Column" {column []}
25
+ panel "Panel" {panel "Panel" []}
26
+ form "Form" {form []}
27
+ screens "Screens of the app" {screens [
28
+ home "Home" [
29
+ text "Home"
30
+ ]
31
+ details "Details" [
32
+ text "Details"
33
+ ]
34
+ ]}
35
+ tabs "Tabs" {tabs [
36
+ "One" []
37
+ "Two" []
38
+ ]}
39
+ steps "Steps" {steps [
40
+ "One" []
41
+ "Two" []
42
+ ]}
43
+ split "Split" {split [
44
+ column []
45
+ column []
46
+ ]}
47
+ scroll "Scroll" {scroll "Scroll" []}
48
+ toolbar "Toolbar" {toolbar [
49
+ button "One"
50
+ button "Two"
51
+ ]}
52
+ dialog "Dialog" {dialog "Dialog" []}
53
+ desktop "Desktop of tiles" {desktop [
54
+ tile #folder "Tile" []
55
+ ]}
56
+ divider "Divider" {divider}
57
+ device "A phone's screen" {device phone [
58
+ text "On a phone"
59
+ ]}
60
+ ]
61
+ "Text" [
62
+ title "Title" {title "Title"}
63
+ heading "Heading" {heading "Heading"}
64
+ text "Text" {text "Text"}
65
+ code "Code" {code "code"}
66
+ link "Link" {link "Link" https://trebol-lang.com}
67
+ icon "Icon" {icon #star}
68
+ breadcrumb "Breadcrumb" {breadcrumb ["Home" home "Here"]}
69
+ ]
70
+ "Input" [
71
+ field "Field" {field "Field"}
72
+ email "Email" {field email "Email" email}
73
+ password "Password" {password "Password"}
74
+ number "Number" {number "Number"}
75
+ money "Money" {money "Amount"}
76
+ date "Date" {date "Date"}
77
+ date-range "Dates from and to" {date-range "Dates"}
78
+ time "Time" {time "Time"}
79
+ area "Long text" {area "Long text"}
80
+ rich "Rich text" {rich "Rich text"}
81
+ rows "Rows" {rows "Rows" [field "Item"]}
82
+ ]
83
+ "Choice" [
84
+ check "Checkbox" {check "Checkbox"}
85
+ toggle "Switch" {toggle "Switch"}
86
+ choice "Choice" {choice "Choice" ["One" "Two"]}
87
+ radio "Options" {radio "Options" ["One" "Two"]}
88
+ segmented "Joined buttons" {radio "View" ["One" "Two"] segmented}
89
+ slider "Slider" {slider "Slider"}
90
+ lookup "Search and pick" {lookup "Search"}
91
+ ]
92
+ "Data" [
93
+ table "Table" {table [name "Name" date "Date"]}
94
+ list "List" {list [name "Name" note "Note"]}
95
+ tree "Tree" {tree [name]}
96
+ board "Board" {board by status [todo "To do" done "Done"]}
97
+ chart "Chart" {chart bar [month "Month" total "Total"]}
98
+ progress "Progress" {progress "Progress" 40%}
99
+ ]
100
+ "Action" [
101
+ button "Button" {button "Button"}
102
+ submit "Submit" {submit "Submit"}
103
+ tile "Tile" {tile #folder "Tile" []}
104
+ ]
105
+ "Media" [
106
+ image "Image" {image %picture.png "Picture"}
107
+ photo "Photo" {photo "Photo"}
108
+ upload "Upload" {upload "Files"}
109
+ video "Video" {video %video.mp4 "Video"}
110
+ audio "Sound" {audio %sound.m4a "Sound"}
111
+ canvas "Drawing" {canvas 120x120 [circle 60x60 50]}
112
+ ]
113
+ ]
114
+
115
+ ; the code an item adds
116
+ palette-code: function [item [word!]] [
117
+ foreach [group items] palette [
118
+ foreach [w label code] items [if w = item [return code]]
119
+ ]
120
+ ; a style the file defines: its word, and a block when it holds faces
121
+ if def: select ui-style-defs item [
122
+ while [def] [
123
+ if def/name = 'container [return rejoin [item " []"]]
124
+ def: def/parent
125
+ ]
126
+ return form item
127
+ ]
128
+ none
129
+ ]
130
+
131
+ ; the Add menu: a submenu per group, and one of the styles the file defines
132
+ palette-menu: function [/own words [block!]] [
133
+ out: collect [
134
+ foreach [group items] palette [
135
+ keep group
136
+ keep/only collect [foreach [w label code] items [keep label keep w]]
137
+ ]
138
+ ]
139
+ words: exclude any [words copy []] [view]
140
+ unless empty? words [
141
+ append out "This file"
142
+ append/only out collect [foreach w words [keep form w keep w]]
143
+ ]
144
+ out
145
+ ]