@@ -4,78 +4,77 @@ import rand
4
4
import datatypes
5
5
6
6
// Shape is the only data structure in GUI used to draw to the screen.
7
+ // Members are arranged for packing to reduce memory footprint.
7
8
pub struct Shape {
8
9
pub :
9
10
id string // user assigned
10
- id_focus u32 // >0 indicates shape is focusable. Value determines tabbing order
11
11
name string // internal shape name, useful for debugging
12
12
type ShapeType
13
13
uid u64 = rand.u64 () // internal use only
14
+ id_focus u32 // >0 indicates shape is focusable. Value determines tabbing order
14
15
axis Axis
15
16
cfg voidptr
16
17
pub mut :
17
- clip bool
18
+ // --- text spans (likely largest field, place early) ---
19
+ text_spans datatypes.LinkedList[TextSpan] // rich text format spans
20
+ // --- strings grouped together ---
21
+ text string
22
+ image_name string // filename of image
23
+ text_lines []string
24
+ // --- callback functions grouped together ---
25
+ on_char fn (voidptr , mut Event, mut Window) = unsafe { nil }
26
+ on_keydown fn (voidptr , mut Event, mut Window) = unsafe { nil }
27
+ on_click fn (voidptr , mut Event, mut Window) = unsafe { nil }
28
+ on_mouse_move fn (voidptr , mut Event, mut Window) = unsafe { nil }
29
+ on_mouse_up fn (voidptr , mut Event, mut Window) = unsafe { nil }
30
+ on_char_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
31
+ on_keydown_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
32
+ on_mouse_down_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
33
+ on_mouse_move_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
34
+ on_mouse_up_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
35
+ on_mouse_scroll_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
36
+ amend_layout fn (mut Layout, mut Window) = unsafe { nil }
37
+ on_hover fn (mut Layout, mut Event, mut Window) = unsafe { nil }
38
+ // --- larger structs ---
18
39
shape_clip DrawClip // used for hit-testing
19
40
color Color
20
- disabled bool
21
- fill bool
22
- focus_skip bool
23
- // --- sizes, positions ---
24
- x f32
25
- y f32
26
- width f32
27
- min_width f32
28
- max_width f32
29
- height f32
30
- min_height f32
31
- max_height f32
32
- h_align HorizontalAlign
33
- v_align VerticalAlign
34
41
padding Padding
35
- radius f32
42
+ text_style TextStyle
36
43
sizing Sizing
37
- spacing f32
38
- // -- text ---
39
- text string
40
- text_lines []string
41
- text_style TextStyle
42
- text_mode TextMode
43
- text_is_password bool
44
- text_is_placeholder bool
45
- text_sel_beg u32
46
- text_sel_end u32
47
- text_tab_size u32 = 4
48
- text_spans datatypes.LinkedList[TextSpan] // rich text format spans
49
- // --- image ---
50
- image_name string // filename of image
51
- // --- float ---
52
- float bool
53
- float_anchor FloatAttach
54
- float_tie_off FloatAttach
44
+ // --- f32 fields grouped together (4-byte alignment) ---
45
+ x f32
46
+ y f32
47
+ width f32
48
+ min_width f32
49
+ max_width f32
50
+ height f32
51
+ min_height f32
52
+ max_height f32
53
+ radius f32
54
+ spacing f32
55
55
float_offset_x f32
56
56
float_offset_y f32
57
- // -- scrolling ---
58
- id_scroll u32 // >0 indicates shape is scrollable
59
- over_draw bool // allows scrollbars to draw in padding area
60
- scroll_mode ScrollMode
61
- // --- user callbacks ---
62
- on_char fn (voidptr , mut Event, mut Window) = unsafe { nil }
63
- on_keydown fn (voidptr , mut Event, mut Window) = unsafe { nil }
64
- on_click fn (voidptr , mut Event, mut Window) = unsafe { nil }
65
- on_mouse_move fn (voidptr , mut Event, mut Window) = unsafe { nil }
66
- on_mouse_up fn (voidptr , mut Event, mut Window) = unsafe { nil }
67
- // --- for internal use and not intended for end users ---
68
- // --- however, composite views can set these in the ---
69
- // --- layout amend callback. See input view for example ---
70
- on_char_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
71
- on_keydown_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
72
- on_mouse_down_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
73
- on_mouse_move_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
74
- on_mouse_up_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
75
- on_mouse_scroll_shape fn (& Shape, mut Event, mut Window) = unsafe { nil }
76
- // amend_layout called after all other layout operations complete
77
- amend_layout fn (mut Layout, mut Window) = unsafe { nil }
78
- on_hover fn (mut Layout, mut Event, mut Window) = unsafe { nil }
57
+ // --- u32 fields grouped together (4-byte alignment) ---
58
+ id_scroll u32 // >0 indicates shape is scrollable
59
+ text_sel_beg u32
60
+ text_sel_end u32
61
+ text_tab_size u32 = 4
62
+ // --- enums (typically 4-byte alignment) ---
63
+ h_align HorizontalAlign
64
+ v_align VerticalAlign
65
+ text_mode TextMode
66
+ scroll_mode ScrollMode
67
+ float_anchor FloatAttach
68
+ float_tie_off FloatAttach
69
+ // --- boolean fields grouped at the end (1-byte each, can be packed) ---
70
+ clip bool
71
+ disabled bool
72
+ fill bool
73
+ focus_skip bool
74
+ text_is_password bool
75
+ text_is_placeholder bool
76
+ float bool
77
+ over_draw bool // allows scrollbars to draw in padding area
79
78
}
80
79
81
80
// ShapeType defines the kind of Shape.
0 commit comments