Repository navigation
Expand file tree
/
Copy pathcontent.json
More file actions
2153 lines (2153 loc) · 109 KB
/
Copy pathcontent.json
File metadata and controls
2153 lines (2153 loc) · 109 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"sections": {
"overview": {
"title": "Overview",
"type": "regular",
"pages": {
"overview": {
"title": "Construct 3 Flexbox Layout Engine",
"addonCards": [
{
"title": "UI Element",
"description": "A behavior you add to world objects. It holds the element's classes and inline style and makes the object part of a layout.",
"icon": "Flexbox.png",
"storeUrl": "https://www.construct.net/en/make-games/addons/1450/ui-element",
"sourceUrl": "https://github.com/skymen/flexbox",
"price": "Free"
},
{
"title": "UI Controller",
"description": "A single global object that holds the class declarations and runs the layout engine every tick.",
"icon": "FlexboxController.png",
"storeUrl": "https://www.construct.net/en/make-games/addons/1451/ui-controller",
"sourceUrl": "https://github.com/skymen/flexboxController",
"price": "Free"
}
],
"content": [
"A layout engine for Construct 3 that brings CSS Flexbox-like positioning and sizing to game objects. You style objects with a small CSS-like language, build the hierarchy with Construct's own scene graph, and the engine positions and sizes everything every tick.",
{
"type": "heading",
"level": 2,
"text": "Two Essential Free Addons"
},
"This layout system consists of two complementary addons available for free on the Construct 3 addon exchange:",
{
"type": "note",
"text": "<strong>Important:</strong> Both addons are required. The <strong>UI Element</strong> behavior (named <code class=\"inline-code\">UI</code> in the editor) is added to each object that takes part in a layout. The <strong>UI Controller</strong> object must exist in the project: it stores class declarations and runs the layout."
},
{
"type": "heading",
"level": 2,
"text": "Features"
},
{
"type": "list",
"items": [
"CSS-like property syntax, in kebab-case or camelCase",
"Flexbox sizing: flex-grow, flex-shrink, flex-basis and the flex shorthand",
"Layout modes: column, row, column-reverse, row-reverse and grid",
"Wrapping rows and columns with flex-wrap and align-content",
"Box model: margin, padding and border, per side",
"Positioning: relative (in flow), absolute (offsets inside the parent) and anchor (attach to another object)",
"Percentage sizing, min/max constraints and fit-content containers",
"Classes declared at runtime, cascading with inline styles and !important",
"Layout runs automatically every tick on Construct's own object hierarchy"
]
},
{
"type": "heading",
"level": 2,
"text": "How it works"
},
"Every tick, the UI Controller takes each top-level object that has the UI behavior and processes its hierarchy:",
{
"type": "list",
"ordered": true,
"items": [
"Merge the element's classes and inline style into one style",
"Apply sizing properties (percentages, flex-basis, width/height, min/max)",
"Recursively process in-flow children so they have their sizes",
"Run the layout algorithm chosen by <code class=\"inline-code\">display</code> on the in-flow children",
"If <code class=\"inline-code\">fit-content</code> is set, size the container to its children and lay them out again",
"Position out-of-flow children (absolute and anchor) last"
]
},
{
"type": "note",
"text": "<strong>New here?</strong> Start with <strong>Getting Started in Construct</strong>, then read <strong>Classes and Cascade</strong>. The <strong>Properties</strong> section is the reference for every supported style property."
}
]
},
"basic-concepts": {
"title": "Basic Concepts",
"content": [
{
"type": "heading",
"level": 2,
"text": "Elements and Hierarchy"
},
"An <strong>element</strong> is any world object with the UI behavior. Elements are nested using Construct's scene graph: a child added with <em>Add child</em> (or drawn as a child in the editor's hierarchy) is a child in the layout too. The topmost element of a hierarchy is the <strong>layout root</strong>.",
{
"type": "heading",
"level": 2,
"text": "Layout Flow"
},
"Elements participate in one of two kinds of flow:",
{
"type": "list",
"items": [
"<strong>Normal flow:</strong> the element is positioned by its parent's <code class=\"inline-code\">display</code> algorithm (column, row, grid and the reverse variants). This is <code class=\"inline-code\">position: relative</code>, the default.",
"<strong>Out of flow:</strong> <code class=\"inline-code\">position: absolute</code> and <code class=\"inline-code\">position: anchor</code> elements are positioned on their own after the in-flow children and do not take space from them."
]
},
{
"type": "heading",
"level": 2,
"text": "Container vs Items"
},
{
"type": "list",
"items": [
"<strong>Container:</strong> the parent element. Its <code class=\"inline-code\">display</code>, <code class=\"inline-code\">gap</code>, <code class=\"inline-code\">padding</code>, <code class=\"inline-code\">align-items</code> and <code class=\"inline-code\">justify-content</code> control how its children are placed.",
"<strong>Items:</strong> the direct children. Their <code class=\"inline-code\">flex</code>, <code class=\"inline-code\">margin</code>, <code class=\"inline-code\">align-self</code>, size and position properties control how each one behaves inside the container."
]
},
"Every element is a container for its own children and an item for its parent at the same time.",
{
"type": "heading",
"level": 2,
"text": "Main and Cross Axis"
},
{
"type": "list",
"items": [
"<strong>Row layout:</strong> main axis is horizontal (left to right), cross axis is vertical",
"<strong>Column layout:</strong> main axis is vertical (top to bottom), cross axis is horizontal"
]
},
"<code class=\"inline-code\">justify-content</code> distributes children along the main axis; <code class=\"inline-code\">align-items</code> aligns them on the cross axis. Flex growing and shrinking happen along the main axis only.",
{
"type": "heading",
"level": 2,
"text": "Coordinates and Sizes"
},
"The engine works on each object's bounding box. An element's <code class=\"inline-code\">width</code> and <code class=\"inline-code\">height</code> are the object's actual size in Construct. All numbers are in layout pixels; there are no units."
]
}
}
},
"construct": {
"title": "Using in Construct",
"type": "regular",
"pages": {
"getting-started": {
"title": "Getting Started in Construct",
"content": [
"This page walks through everything needed to get a first layout running inside a Construct 3 project.",
{
"type": "step",
"number": 1,
"title": "Install both addons",
"content": [
"Download and install <strong>UI Element</strong> and <strong>UI Controller</strong> from the addon exchange (links on the Overview page). Both are needed: the behavior does nothing without the controller, and the controller shows an alert if the behavior is missing."
]
},
{
"type": "step",
"number": 2,
"title": "Add one UI Controller object",
"content": [
"Insert a <strong>UI Controller</strong> object into the project. It is a single global object: add it once and it is available on every layout. It has no editor properties.",
{
"type": "note",
"text": "The controller runs the layout engine automatically. There is no action to run or refresh a layout."
}
]
},
{
"type": "step",
"number": 3,
"title": "Add the UI behavior to your objects",
"content": [
"Add the <strong>UI</strong> behavior to each world object that takes part in a layout: the containers and the items. Only one instance of the behavior is allowed per object type.",
"The behavior has three editor properties:",
{
"type": "list",
"items": [
"<strong>Enabled</strong> (checkbox, default on): whether the element takes part in its parent's layout. See <em>Runtime Behaviour</em> for details.",
"<strong>Classes</strong> (text): a space-separated list of class names, for example <code class=\"inline-code\">panel dark</code>.",
"<strong>Style</strong> (multi-line text): the element's inline style, written in the CSS-like syntax."
]
}
]
},
{
"type": "step",
"number": 4,
"title": "Build the hierarchy",
"content": [
"Nesting is Construct's own scene graph. Make an item a child of its container with the <em>Add child</em> action at runtime, or by building a hierarchy in the layout editor. The layout engine reads <code class=\"inline-code\">children()</code> and <code class=\"inline-code\">getParent()</code>, nothing else.",
{
"type": "code",
"text": "System → Create object: Button on layer \"UI\"\nPanel → Add child: Button"
},
{
"type": "note",
"text": "In the <em>Add child</em> action and in the editor's hierarchy settings, turn on <strong>transform X</strong> and <strong>transform Y</strong>, and leave <strong>transform width</strong>, <strong>transform height</strong> and <strong>transform angle</strong> off. The engine sets sizes itself and only needs children to move with their parent. Transform angle makes every child recompute its angle through the whole parent chain on each change, which is the main cost in deep hierarchies; turn it on only for a root you really rotate."
},
{
"type": "warning",
"text": "<strong>The root must have the behavior.</strong> The controller only processes top-level objects (objects with no parent) that have the UI behavior, and each of those processes its whole subtree. An element whose parent is a plain object without the behavior is never laid out."
},
"Children that do not have the behavior still take part in the layout, with default styles. Giving them the behavior lets you style them."
]
},
{
"type": "step",
"number": 5,
"title": "Declare classes on start of layout",
"content": [
"Classes are declared at runtime with the controller's <strong>Declare Class</strong> action. The usual place is <em>On start of layout</em>:",
{
"type": "code",
"text": "UI Controller → Declare class \"panel\" to\n \"display: column;\n gap: 8;\n padding: 12;\"\n\nUI Controller → Declare class \"button\" to\n \"height: 40;\n flex: 1;\"\n"
},
"Elements that list a class that has not been declared yet simply ignore it until it is declared."
]
},
{
"type": "step",
"number": 6,
"title": "Run it",
"content": [
"Preview the project. On every tick the controller lays out every root element and its descendants. Anything you change through actions (classes, styles, class declarations, hierarchy, visibility) is reflected on the next tick.",
{
"type": "note",
"text": "<strong>Tip:</strong> Use the <strong>Style Validator</strong> in the Tools section to check a style string before pasting it into the editor or an action."
}
]
}
]
},
"classes-and-cascade": {
"title": "Classes and Cascade",
"content": [
"An element's final style is the merge of the styles of its classes followed by its inline style. This page explains the order and the exceptions.",
{
"type": "heading",
"level": 2,
"text": "Declaring classes"
},
"Classes live in the UI Controller. They are plain names mapped to a style string, declared with the <strong>Declare Class</strong> action, and can be changed at any time:",
{
"type": "list",
"items": [
"<strong>Declare Class</strong> (class name, style string): sets the whole style of the class, replacing any previous declaration.",
"<strong>Set Class Property</strong> (class name, property, value): changes one property. Declaring a property on a class that does not exist creates the class. An empty value removes the property.",
"<strong>Remove Class Property</strong> (class name, property): removes one property."
]
},
"Changing a class updates every element that uses it on the next tick.",
{
"type": "heading",
"level": 2,
"text": "Assigning classes to elements"
},
"An element's classes come from the behavior's <strong>Classes</strong> property, and can be changed with the <strong>Set Classes</strong>, <strong>Add Classes</strong> and <strong>Remove Classes</strong> actions. All of these take a space-separated list. Duplicate names are collapsed; unknown names are ignored.",
{
"type": "heading",
"level": 2,
"text": "Cascade order"
},
"Properties are applied in this order, later entries overriding earlier ones:",
{
"type": "list",
"ordered": true,
"items": [
"Each class, in the order the names appear on the element (not the order they were declared)",
"The element's inline style (the <strong>Style</strong> property, or whatever the <strong>Set Style</strong> / <strong>Set Style Property</strong> actions set)"
]
},
{
"type": "code",
"text": "/* class \"card\" */\nwidth: 200;\npadding: 10;\n\n/* class \"wide\" */\nwidth: 400;\n\n/* Element with classes \"card wide\" and inline style \"padding: 0\" */\n/* Result: width 400 (from wide), padding 0 (inline wins) */"
},
{
"type": "heading",
"level": 2,
"text": "!important"
},
"A property marked <code class=\"inline-code\">!important</code> is not overridden by later non-important declarations. A later <code class=\"inline-code\">!important</code> declaration still overrides an earlier one.",
{
"type": "code",
"text": "/* class \"locked\" */\nwidth: 100 !important;\n\n/* inline style */\nwidth: 300;\n\n/* Result: width 100. The inline style would need \"width: 300 !important\" to win. */"
},
{
"type": "heading",
"level": 2,
"text": "Inline style actions"
},
{
"type": "list",
"items": [
"<strong>Set Style</strong> (style string): replaces the whole inline style.",
"<strong>Set Style Property</strong> (property, value): changes one inline property. An empty value removes it.",
"<strong>Remove Style Property</strong> (property): removes one inline property."
]
},
{
"type": "note",
"text": "Class declarations are kept by the controller for the whole session and are not part of savegames. Declaring them <em>On start of layout</em> is the safe pattern. An element's own classes and inline style are saved and restored."
}
]
},
"runtime-behaviour": {
"title": "Runtime Behaviour",
"content": [
{
"type": "heading",
"level": 2,
"text": "When layout runs"
},
"The controller processes every root element on every tick, after the normal tick. Each pass has two steps: a <strong>measure</strong> step that walks the hierarchy bottom-up and works out every element's size (its own size, an explicit width/height, or the extent of its children for fit-content), and a <strong>layout</strong> step that walks top-down, resolves percent sizes and flex against the now-final parent size, and positions the children. Because sizes are known before anything is placed, nested layouts settle in a single tick.",
"Only the parts of a hierarchy that changed are laid out. The measure step notices changed styles, sizes, positions, visibility and children; an unchanged frame costs the measure step and nothing else. There is no way to trigger a layout manually and no event when it finishes; changes made in an event sheet are visible on the following tick.",
{
"type": "heading",
"level": 2,
"text": "Enabled and visibility"
},
{
"type": "list",
"items": [
"An element whose behavior is <strong>disabled</strong> (property or <strong>Set Enabled</strong> action) is skipped by its parent: it takes no space and is not moved. It still lays out its own children.",
"An <strong>invisible</strong> object is skipped by its parent in the same way.",
"Disabling a <strong>root</strong> element does not stop its layout, because roots are not laid out by anyone; it only matters once the element has a parent."
]
},
"Use <strong>Is Enabled</strong> to test the property in conditions.",
{
"type": "heading",
"level": 2,
"text": "Hierarchy flags"
},
"The engine positions and sizes every element itself and relies on Construct to move children along with their parent. When you add a child (the <em>Add child</em> action or the editor's hierarchy), turn on <strong>transform X</strong> and <strong>transform Y</strong> and leave <strong>transform width</strong>, <strong>transform height</strong> and <strong>transform angle</strong> off. Width and height would let Construct rescale children behind the engine's back; angle makes each child recompute its angle through the parent chain on every change and is the largest cost in deep hierarchies.",
{
"type": "heading",
"level": 2,
"text": "Angle"
},
"Only the <strong>root</strong> is laid out upright: its angle is set to 0 for the duration of the pass and restored afterwards, so a rotated root's whole layout is computed as if it were level and then turns with it. Children keep their own angle during the pass and are placed by their axis-aligned bounding box, so rotate roots, not containers inside a hierarchy. Whether the children turn with the root depends on the hierarchy's <strong>transform angle</strong> flag: with it off (recommended) the children's positions still orbit the root's origin but each child stays upright; with it on the whole UI rotates rigidly. A root that is not at angle 0 costs two bounding-box invalidations of its subtree per tick, one to level it and one to restore it.",
{
"type": "heading",
"level": 2,
"text": "Children without the behavior"
},
"Plain objects that are children of an element are laid out with default styles (in flow, rigid: they never grow or shrink). They cannot be styled and their own children are not laid out.",
{
"type": "heading",
"level": 2,
"text": "Savegames"
},
"The behavior saves the <strong>Enabled</strong> state, the list of classes and the inline style. Computed styles are rebuilt after a load. Class declarations held by the controller are not saved; declare them on start of layout.",
{
"type": "heading",
"level": 2,
"text": "Performance"
},
"Layout cost is proportional to the number of elements that changed, plus a cheap measure step over everything. A frame where nothing changes reads each element's bounding box once and writes nothing; a change costs the re-layout of the containers it affects. Construct's own bookkeeping is the larger share: every position or size write invalidates the bounding boxes of the whole subtree below it, and a child that rotates with its parent (<strong>transform angle</strong> on) recomputes its angle by walking up to the root. Deep hierarchies therefore cost more per element than wide ones. Keep nesting to what the design needs, turn <strong>transform angle</strong> off for children that never need to rotate, and prefer hiding or disabling big subtrees over destroying and recreating them."
]
}
}
},
"css": {
"title": "CSS Syntax",
"type": "regular",
"pages": {
"syntax-basics": {
"title": "Basic Syntax",
"content": [
{
"type": "heading",
"level": 2,
"text": "Property Format"
},
"Styles are written using CSS-like syntax. Properties are separated by line breaks or semicolons:",
{
"type": "code",
"text": "display: row;\ngap: 10;\nalign-items: center;\njustify-content: space-between;"
},
{
"type": "heading",
"level": 2,
"text": "Property Names"
},
"Properties can be written in either kebab-case or camelCase:",
{
"type": "code",
"text": "/* Both formats are equivalent */\nalign-items: center;\nalignItems: center;\n\nflex-grow: 1;\nflexGrow: 1;"
},
{
"type": "heading",
"level": 2,
"text": "Value Types"
},
{
"type": "list",
"items": [
"<strong>Numbers:</strong> <code class=\"inline-code\">10</code>, <code class=\"inline-code\">3.5</code>, <code class=\"inline-code\">-8</code>. Numbers are pixels; never write units.",
"<strong>Percentages:</strong> <code class=\"inline-code\">50%</code>, <code class=\"inline-code\">100%</code>. Only <code class=\"inline-code\">width</code>, <code class=\"inline-code\">height</code> and <code class=\"inline-code\">flex-basis</code> accept them, relative to the parent's content area.",
"<strong>Keywords:</strong> per property, for example <code class=\"inline-code\">center</code>, <code class=\"inline-code\">row</code>, <code class=\"inline-code\">absolute</code>, <code class=\"inline-code\">true</code>."
]
},
{
"type": "warning",
"text": "<strong>No units.</strong> A value such as <code class=\"inline-code\">100px</code> is kept as text and ignored by numeric properties, so <code class=\"inline-code\">width: 100px</code> does nothing. Write <code class=\"inline-code\">width: 100</code>. The one exception is that a zero with a unit (<code class=\"inline-code\">0px</code>, <code class=\"inline-code\">0%</code>) is read as 0."
},
{
"type": "heading",
"level": 2,
"text": "Syntax Notes"
},
{
"type": "list",
"items": [
"Semicolons are optional; line breaks also separate properties",
"Whitespace around colons and values is ignored",
"Lines without a colon, and properties with an empty value, are skipped",
"Unknown properties are stored but have no effect"
]
}
]
},
"property-formats": {
"title": "Important and Per-Side Properties",
"content": [
{
"type": "heading",
"level": 2,
"text": "Important Declarations"
},
"Add <code class=\"inline-code\">!important</code> after a value to protect it from being overridden later in the cascade (see <em>Classes and Cascade</em>):",
{
"type": "code",
"text": "width: 200 !important;\nheight: 100 !important;"
},
{
"type": "heading",
"level": 2,
"text": "Per-Side Properties"
},
"<code class=\"inline-code\">margin</code>, <code class=\"inline-code\">padding</code> and <code class=\"inline-code\">border</code> (or <code class=\"inline-code\">border-width</code>) take one to four numbers with CSS meaning: all sides; vertical and horizontal; top, horizontal and bottom; top, right, bottom and left. The shorthand always expands to the four per-side properties, which are available too. As in CSS, the later declaration wins:",
{
"type": "code",
"text": "/* Same margin on every side */\nmargin: 10;\n\n/* Vertical, horizontal */\nmargin: 10 20;\n\n/* Top, right, bottom, left */\nmargin: 10 20 10 20;\n\n/* Per side */\nmargin-top: 10;\nmargin-right: 20;\nmargin-bottom: 10;\nmargin-left: 20;\n\n/* Mixed: 10 everywhere except the left */\npadding: 10;\npadding-left: 30;\n\n/* Border widths */\nborder: 2; /* or border-width: 2 */\nborder-top-width: 4;"
},
{
"type": "note",
"text": "Values must be plain numbers. A shorthand with a unit or a keyword (<code class=\"inline-code\">border: 1px solid red</code>) or with more than four values is ignored as a whole."
},
{
"type": "heading",
"level": 2,
"text": "The flex shorthand"
},
"<code class=\"inline-code\">flex</code> expands into flex-grow, flex-shrink and flex-basis. See <em>Flex Shorthand</em>."
]
},
"flex-shorthand": {
"title": "Flex Shorthand",
"content": [
"The <code class=\"inline-code\">flex</code> property is shorthand for flex-grow, flex-shrink, and flex-basis:",
{
"type": "heading",
"level": 2,
"text": "Single Value Syntax"
},
{
"type": "code",
"text": "/* Number: sets flex-grow, defaults others */\nflex: 1; /* flex-grow: 1, flex-shrink: 1, flex-basis: 0 */\n\n/* Keywords */\nflex: auto; /* flex-grow: 1, flex-shrink: 1, flex-basis: auto */\nflex: none; /* flex-grow: 0, flex-shrink: 0, flex-basis: auto */\nflex: initial; /* flex-grow: 0, flex-shrink: 1, flex-basis: auto */"
},
{
"type": "heading",
"level": 2,
"text": "Two Value Syntax"
},
{
"type": "code",
"text": "/* flex-grow and flex-shrink (second value is a plain number) */\nflex: 1 2; /* flex-grow: 1, flex-shrink: 2, flex-basis: 0 */\n\n/* flex-grow and flex-basis (second value is a percentage) */\nflex: 1 50%; /* flex-grow: 1, flex-shrink: 1, flex-basis: 50% */"
},
{
"type": "heading",
"level": 2,
"text": "Three Value Syntax"
},
{
"type": "code",
"text": "/* flex-grow, flex-shrink, and flex-basis */\nflex: 1 2 100; /* flex-grow: 1, flex-shrink: 2, flex-basis: 100 */\nflex: 1 1 25%; /* flex-grow: 1, flex-shrink: 1, flex-basis: 25% */"
},
{
"type": "note",
"text": "In the two-value form a plain number is always read as flex-shrink. To give a numeric flex-basis, use the three-value form. A flex-basis of <code class=\"inline-code\">0</code> really is 0: <code class=\"inline-code\">flex: 1</code> items start from nothing and share the whole main axis by their grow factor, so items of different sizes end up equal. Use <code class=\"inline-code\">flex: 1 1 auto</code> to grow from the element's own size instead."
}
]
},
"box-model": {
"title": "Box Model",
"content": [
"The engine uses a simple box model built on the object's actual size in Construct.",
{
"type": "code",
"text": "┌─ margin (outside, transparent) ───────────────┐\n│ ┌─ object bounding box = width × height ───┐ │\n│ │ border │ │\n│ │ ┌─ padding ──────────────────────────┐ │ │\n│ │ │ content area: children go here │ │ │\n│ │ └────────────────────────────────────┘ │ │\n│ └──────────────────────────────────────────┘ │\n└────────────────────────────────────────────────┘"
},
{
"type": "list",
"items": [
"<strong>width / height</strong> are the object's bounding box size. Padding and border are carved out <em>inside</em> it; they do not add to it.",
"<strong>content area</strong> = width − padding-left − padding-right − border-left − border-right (and likewise vertically). Children are laid out inside it, and percentages resolve against it.",
"<strong>margin</strong> is outside the box. It adds space between siblings and counts toward the parent's fit-content size, but never changes the object's own size."
]
},
{
"type": "heading",
"level": 2,
"text": "Worked example"
},
{
"type": "code",
"text": "width: 200;\npadding: 10;\nborder: 2;\nmargin: 5;\n\n/* Object size in Construct: 200 wide */\n/* Content area for children: 200 - 20 - 4 = 176 */\n/* Space taken in the parent: 200 + 5 + 5 = 210 */"
},
{
"type": "note",
"text": "<code class=\"inline-code\">border</code> only reserves space in the layout. It draws nothing; use the object's own appearance for visible borders."
}
]
}
}
},
"guides": {
"title": "Guides",
"type": "regular",
"pages": {
"layout-basics": {
"title": "Layout Basics Guide",
"content": [
{
"type": "step",
"number": 1,
"title": "Choose a Display Mode",
"content": [
"Start by setting the <code class=\"inline-code\">display</code> property on your container:",
{
"type": "code",
"text": "/* Stack children vertically (default) */\ndisplay: column;\n\n/* Arrange children horizontally */\ndisplay: row;\n\n/* Same, in reverse order */\ndisplay: column-reverse;\ndisplay: row-reverse;\n\n/* Grid with a fixed number of columns */\ndisplay: grid;\ncolumns: 3;"
}
]
},
{
"type": "step",
"number": 2,
"title": "Add Spacing",
"content": [
"Control spacing between and around children:",
{
"type": "code",
"text": "/* 10 pixels between each child */\ngap: 10;\n\n/* 16 pixels inside the container edges */\npadding: 16;"
}
]
},
{
"type": "step",
"number": 3,
"title": "Control Alignment",
"content": [
"Align children within the container:",
{
"type": "code",
"text": "/* Align children on the cross-axis */\nalign-items: center; /* start, center, end */\n\n/* Distribute children on the main axis */\njustify-content: space-between; /* start, center, end, space-between, space-around */"
}
]
},
{
"type": "step",
"number": 4,
"title": "Let Rows Wrap",
"content": [
"When children do not fit on the main axis, let them wrap onto new lines:",
{
"type": "code",
"text": "display: row;\nflex-wrap: wrap; /* nowrap (default), wrap, wrap-reverse */\ngap: 8;"
},
"A row wraps into more rows; a column wraps into more columns. <code class=\"inline-code\">align-items</code> aligns items inside their own line; to place the lines themselves within the container, use <code class=\"inline-code\">align-content</code>."
]
}
]
},
"flexbox-guide": {
"title": "Using Flexbox Guide",
"content": [
{
"type": "step",
"number": 1,
"title": "Understanding Flex Items",
"content": [
"By default, children keep their own size: they never grow and never shrink, even when the container is too small. Setting any flex property (<code class=\"inline-code\">flex</code>, <code class=\"inline-code\">flex-grow</code>, <code class=\"inline-code\">flex-shrink</code> or <code class=\"inline-code\">flex-basis</code>) makes the child a flex item, which shrinks by default (flex-shrink 1):",
{
"type": "code",
"text": "/* Make an item grow to fill available space */\nflex-grow: 1;\n\n/* Make an item shrink twice as fast as the others */\nflex-shrink: 2;\n\n/* Never shrink */\nflex-shrink: 0;\n\n/* Set the starting size on the main axis before growing/shrinking */\nflex-basis: 200;"
}
]
},
{
"type": "step",
"number": 2,
"title": "Common Flex Patterns",
"content": [
"Here are common flex patterns:",
{
"type": "code",
"text": "/* Equal width columns */\nflex: 1;\n\n/* Fixed sidebar, flexible content */\n/* Sidebar: */ flex: none; width: 200;\n/* Content: */ flex-grow: 1;\n\n/* Flexible with minimum size */\nflex: 1; min-width: 150;"
}
]
},
{
"type": "step",
"number": 3,
"title": "Individual Item Alignment",
"content": [
"Override container alignment for specific items:",
{
"type": "code",
"text": "/* Override align-items for this item only */\nalign-self: end;"
}
]
}
]
},
"positioning-guide": {
"title": "Positioning Elements Guide",
"content": [
{
"type": "warning",
"text": "<strong>Absolute and anchor positioning only work on children.</strong> A root element (one with no parent) is always treated as <code class=\"inline-code\">position: relative</code>. To float something, make it a child of another element, for example an invisible full-screen HUD root."
},
{
"type": "step",
"number": 1,
"title": "Relative Positioning",
"content": [
"Default positioning mode. Elements participate in normal layout flow:",
{
"type": "code",
"text": "position: relative; /* Default, can be omitted */"
}
]
},
{
"type": "step",
"number": 2,
"title": "Absolute Positioning",
"content": [
"Remove the element from normal flow and offset it from the edges of the parent's content area:",
{
"type": "code",
"text": "position: absolute;\ntop: 20; /* 20 pixels from the parent's top edge */\nright: 20; /* 20 pixels from the parent's right edge */"
},
"Offsets are numbers only. If neither <code class=\"inline-code\">left</code> nor <code class=\"inline-code\">right</code> is given the element sits at the left edge; the same goes for <code class=\"inline-code\">top</code>."
]
},
{
"type": "step",
"number": 3,
"title": "Anchor Positioning",
"content": [
"Position relative to another object, which can be anywhere in the project:",
{
"type": "code",
"text": "position: anchor;\nanchor-target: button1; /* Instance tag of the target */\nanchor-point: bottom; /* Point on the target */\nself-anchor: top; /* Point on this element */\nanchor-offset-y: 10; /* Additional offset */"
},
"See the <em>Anchor Positioning Guide</em> for the details."
]
}
]
},
"anchor-positioning-guide": {
"title": "Anchor Positioning Guide",
"content": [
"Anchor positioning lets an element attach itself to another object anywhere in the game world: tooltips, health bars, name tags, contextual menus and overlays.",
{
"type": "warning",
"text": "<strong>Key Concept:</strong> An anchored element is out of flow: it does not take space in its parent's layout. It still has to be a <em>child</em> of an element so that the engine processes it; only the <em>target</em> can be any object. A root element cannot be anchored."
},
{
"type": "step",
"number": 1,
"title": "Basic Anchor Setup",
"content": [
"To enable anchor positioning, you need three essential properties:",
{
"type": "code",
"text": "/* Enable anchor positioning */\nposition: anchor;\n\n/* Choose what to anchor to (an instance tag, or \"parent\") */\nanchor-target: button1;\n\n/* Choose where to attach on the target */\nanchor-point: bottom;"
},
"This positions the element's center (the default <code class=\"inline-code\">self-anchor</code>) on the bottom edge of the object tagged <code class=\"inline-code\">button1</code>."
]
},
{
"type": "step",
"number": 2,
"title": "Understanding Anchor Points",
"content": [
"Both the target and your element have 9 anchor points:",
{
"type": "code",
"text": "top-left top top-right\nleft center right\nbottom-left bottom bottom-right\n\n/* Visual layout */\n┌─────────┬─────────┐\n│top-left │ top │top-right\n├─────────┼─────────┤\n│ left │ center │ right\n├─────────┼─────────┤\n│bottom- │ bottom │bottom-\n│left │ │right\n└─────────┴─────────┘"
},
"<code class=\"inline-code\">top-center</code>, <code class=\"inline-code\">bottom-center</code>, <code class=\"inline-code\">center-left</code> and <code class=\"inline-code\">center-right</code> are accepted aliases for <code class=\"inline-code\">top</code>, <code class=\"inline-code\">bottom</code>, <code class=\"inline-code\">left</code> and <code class=\"inline-code\">right</code>. Any other name falls back to <code class=\"inline-code\">center</code>."
]
},
{
"type": "step",
"number": 3,
"title": "Controlling Your Element's Attachment Point",
"content": [
"By default, your element attaches using its center point. Use <code class=\"inline-code\">self-anchor</code> to change this:",
{
"type": "code",
"text": "/* Tooltip above a button */\nposition: anchor;\nanchor-target: helpButton;\nanchor-point: top; /* Target's top edge */\nself-anchor: bottom; /* This element's bottom edge */\n\n/* Result: Tooltip appears above button with no overlap */"
},
"Common self-anchor patterns:",
{
"type": "code",
"text": "/* Dropdown menu */\nanchor-point: bottom;\nself-anchor: top;\n\n/* Side panel */\nanchor-point: right;\nself-anchor: left;\n\n/* Centered overlay */\nanchor-point: center;\nself-anchor: center;"
}
]
},
{
"type": "step",
"number": 4,
"title": "Fine-tuning with Offsets",
"content": [
"Use anchor offsets to add spacing or make micro-adjustments:",
{
"type": "code",
"text": "/* Tooltip with spacing */\nposition: anchor;\nanchor-target: button;\nanchor-point: top;\nself-anchor: bottom;\nanchor-offset-y: -10; /* 10 pixel gap above the button */\n\n/* Notification badge */\nposition: anchor;\nanchor-target: avatar;\nanchor-point: top-right;\nself-anchor: center;\nanchor-offset-x: 8; /* Slight offset to the right */\nanchor-offset-y: -8; /* Slight offset upward */"
},
{
"type": "note",
"text": "<strong>Coordinate System:</strong> Positive X moves right, negative X moves left. Positive Y moves down, negative Y moves up."
}
]
},
{
"type": "step",
"number": 5,
"title": "Choosing Anchor Targets",
"content": [
"<code class=\"inline-code\">anchor-target</code> is either the keyword <code class=\"inline-code\">parent</code> or an <strong>instance tag</strong>. The engine searches every instance of every object type in the project and uses the first one that has that tag. The target does not need the UI behavior.",
{
"type": "code",
"text": "/* Anchor to the parent element (also the default when omitted) */\nanchor-target: parent;\n\n/* Anchor to any object carrying the tag */\nanchor-target: player;\nanchor-target: inventoryButton;"
},
{
"type": "warning",
"text": "<strong>Tags must be unique per target.</strong> If several instances share the tag, whichever is found first is used. Set tags on the instance in the editor or with the <em>Set tags</em> action."
}
]
},
{
"type": "example",
"title": "Practical Example: Tooltip Above a Skill Button",
"content": [
"A tooltip that appears above a skill button. The tooltip is a child of the HUD root element; the button only needs the <code class=\"inline-code\">skillButton</code> tag.",
{
"type": "code",
"text": "/* Tooltip element (child of the HUD root) */\nposition: anchor;\nanchor-target: skillButton; /* Target the skill button */\nanchor-point: top; /* Attach to the button's top edge */\nself-anchor: bottom; /* Using the tooltip's bottom edge */\nanchor-offset-y: -15; /* 15 pixel gap above the button */\nwidth: 200;\npadding: 10;\ndisplay: column;\n\n/* Optional arrow: a second anchored child of the HUD root */\nposition: anchor;\nanchor-target: skillButton;\nanchor-point: top;\nself-anchor: bottom;\nanchor-offset-y: -5;\nwidth: 10;\nheight: 10;"
}
]
},
{
"type": "example",
"title": "Practical Example: Health Bar Above a Character",
"content": [
"A health bar that follows a character. The bar background is a child of the HUD root; the fill is a child of the background.",
{
"type": "code",
"text": "/* Health bar background (child of the HUD root) */\nposition: anchor;\nanchor-target: player; /* Follows the object tagged \"player\" */\nanchor-point: top; /* Above the player */\nself-anchor: bottom;\nanchor-offset-y: -20; /* 20 pixels above the player */\nwidth: 60;\nheight: 8;\ndisplay: row;\n\n/* Health bar fill (child of the background) */\nheight: 100%;\nwidth: 75%; /* 75% health; change it with Set Style Property */"
}
]
},
{
"type": "example",
"title": "Practical Example: Contextual Menu",
"content": [
"A menu that appears next to an inventory slot:",
{
"type": "code",
"text": "/* Context menu container (child of the HUD root) */\nposition: anchor;\nanchor-target: inventorySlot;\nanchor-point: right; /* To the right of the slot */\nself-anchor: left; /* Menu's left edge */\nanchor-offset-x: 10; /* Small gap */\ndisplay: column;\ngap: 2;\nwidth: 120;\npadding: 5;\nfit-content: true; /* Height follows the number of items */\n\n/* Menu items (children of the container) */\nheight: 30;\nwidth: 100%;"
}
]
},
{
"type": "step",
"number": 6,
"title": "Common Patterns and Best Practices",
"content": [
{
"type": "heading",
"level": 3,
"text": "Tooltip Pattern"
},
{
"type": "code",
"text": "/* Above target */\nanchor-point: top; self-anchor: bottom; anchor-offset-y: -gap;\n\n/* Below target */\nanchor-point: bottom; self-anchor: top; anchor-offset-y: gap;\n\n/* Left of target */\nanchor-point: left; self-anchor: right; anchor-offset-x: -gap;\n\n/* Right of target */\nanchor-point: right; self-anchor: left; anchor-offset-x: gap;"
},
{
"type": "heading",
"level": 3,
"text": "Overlay Pattern"
},
{
"type": "code",
"text": "/* Centered overlay */\nanchor-point: center;\nself-anchor: center;\n\n/* Corner badge */\nanchor-point: top-right;\nself-anchor: center;\nanchor-offset-x: 5;\nanchor-offset-y: -5;"
},
{
"type": "heading",
"level": 3,
"text": "Following Elements"
},
{
"type": "code",
"text": "/* Health/status bars */\nanchor-point: top;\nself-anchor: bottom;\nanchor-offset-y: -distance;\n\n/* Name tags */\nanchor-point: bottom;\nself-anchor: top;\nanchor-offset-y: distance;"
}
]
},
{
"type": "step",
"number": 7,
"title": "Troubleshooting Common Issues",
"content": [
{
"type": "heading",
"level": 3,
"text": "Element Not Moving"
},
{
"type": "list",
"items": [
"Check that the element is a child of another element; a root cannot be anchored",
"Check that exactly one object carries the tag named in anchor-target",
"Verify that position is set to <code class=\"inline-code\">anchor</code>",
"Make sure the anchored element is visible and enabled; hidden or disabled children are skipped"
]
},
{
"type": "heading",
"level": 3,
"text": "Wrong Position"
},
{
"type": "list",
"items": [
"Check the anchor-point and self-anchor combination",
"Verify the anchor-offset-x and anchor-offset-y signs",
"Remember that the target might be moving or changing size; the element follows it every tick"
]
},
{
"type": "heading",
"level": 3,
"text": "Performance Considerations"
},
{
"type": "list",
"items": [
"Resolving a tag searches every instance in the project, every tick. Keep the number of anchored elements moderate.",
"Anchoring to <code class=\"inline-code\">parent</code> is free; prefer it when the target is the parent anyway.",
"Disable anchored elements that are not needed instead of leaving them anchored off-screen."
]
}
]
}
]
},
"responsive-guide": {
"title": "Responsive Layouts Guide",
"content": [
{
"type": "step",
"number": 1,
"title": "Percentage-based Sizing",
"content": [
"Make elements size themselves relative to their parent's content area:",
{
"type": "code",
"text": "/* Half of the parent's content width */\nwidth: 50%;\n\n/* Full parent content height */\nheight: 100%;"
},
"Percentages need a parent; they have no effect on a root element."
]
},
{
"type": "step",
"number": 2,
"title": "Constraints",
"content": [
"Set minimum and maximum sizes to prevent elements from becoming too small or too large:",
{
"type": "code",
"text": "width: 50%;\nmin-width: 200; /* Never smaller than 200 pixels */\nmax-width: 800; /* Never larger than 800 pixels */"
}
]
},
{
"type": "step",
"number": 3,
"title": "Flexible Containers",
"content": [
"Use fit-content to make containers size to their children:",
{
"type": "code",
"text": "display: column;\nfit-content: true; /* Width fits the widest child, height fits the stack */\npadding: 12;"
},
{
"type": "note",
"text": "Percentage-sized children inside a fit-content container work: the child counts with its own size while the container is measured, then the percentage resolves against the fitted size. <code class=\"inline-code\">width: 100%</code> on a child of a fitted row therefore overflows the row, as in CSS; use it on the cross axis (for example <code class=\"inline-code\">height: 100%</code> in a fitted row) or give the child a fixed size."
}
]
},
{
"type": "step",
"number": 4,
"title": "Reacting to the viewport",
"content": [
"The engine never reads the viewport. To make a layout follow the window, size the root element from the event sheet, for example every tick or <em>On resize</em>:",
{
"type": "code",
"text": "HUDRoot → Set size to (ViewportWidth(\"UI\"), ViewportHeight(\"UI\"))\nHUDRoot → Set position to (ViewportLeft(\"UI\"), ViewportTop(\"UI\"))"
},
"Children with percentages and flex then follow automatically on the next tick."
]
}
]
},
"common-patterns": {
"title": "Common Layout Patterns",
"content": [
{
"type": "example",
"title": "Navigation Bar",
"content": [
{
"type": "code",
"text": "/* Container */\ndisplay: row;\ngap: 20;\nalign-items: center;\njustify-content: space-between;\npadding: 10;"
}
]
},
{
"type": "example",
"title": "Sidebar Layout",
"content": [
{
"type": "code",
"text": "/* Main Container */\ndisplay: row;\ngap: 20;\n\n/* Sidebar */\nwidth: 250;\nflex: none;\n\n/* Content Area */\nflex-grow: 1;\nheight: 100%;"
}
]
},
{
"type": "example",
"title": "Card Layout",
"content": [
{
"type": "code",
"text": "/* Card Container */\ndisplay: column;\nheight: 400;\n\n/* Header */\nheight: 60;\nflex: none;\nwidth: 100%;\n\n/* Content */\nflex-grow: 1;\npadding: 20;\nwidth: 100%;\n\n/* Footer */\nheight: 40;\nflex: none;\nwidth: 100%;"
}
]
},
{
"type": "example",
"title": "Centered Modal",
"content": [
"The modal is a child of a full-screen root element:",
{
"type": "code",
"text": "position: anchor;\nanchor-target: parent;\nanchor-point: center;\nself-anchor: center;\nwidth: 400;\nheight: 300;"
}
]
},
{
"type": "example",
"title": "Wrapping Tag List",
"content": [
{
"type": "code",
"text": "/* Container */\ndisplay: row;\nflex-wrap: wrap;\ngap: 6;\nwidth: 300;\n\n/* Each tag keeps its own size */\nflex: none;"
}
]
},
{
"type": "example",
"title": "Inventory Grid",
"content": [
{
"type": "code",
"text": "/* Container */\ndisplay: grid;\ncolumns: 5;\ngap: 4;\npadding: 8;\nfit-content: true;\n\n/* Slots */\nwidth: 48;\nheight: 48;"
}
]
}
]
}
}
},
"properties": {