1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
3 | |
4 | //! This module contains all builtin structures exposed in the .slint language. |
5 | |
6 | /// Call a macro with every builtin structures exposed in the .slint language |
7 | /// |
8 | /// ## Example |
9 | /// ```rust |
10 | /// macro_rules! print_builtin_structs { |
11 | /// ($( |
12 | /// $(#[$struct_attr:meta])* |
13 | /// struct $Name:ident { |
14 | /// @name = $inner_name:literal |
15 | /// export { |
16 | /// $( $(#[$pub_attr:meta])* $pub_field:ident : $pub_type:ty, )* |
17 | /// } |
18 | /// private { |
19 | /// $( $(#[$pri_attr:meta])* $pri_field:ident : $pri_type:ty, )* |
20 | /// } |
21 | /// } |
22 | /// )*) => { |
23 | /// $(println!("{} => export:[{}] private:[{}]" , stringify!($Name), stringify!($($pub_field),*), stringify!($($pri_field),*));)* |
24 | /// }; |
25 | /// } |
26 | /// i_slint_common::for_each_builtin_structs!(print_builtin_structs); |
27 | /// ``` |
28 | #[macro_export ] |
29 | macro_rules! for_each_builtin_structs { |
30 | ($macro:ident) => { |
31 | $macro![ |
32 | /// The `KeyboardModifiers` struct provides booleans to indicate possible modifier keys on a keyboard, such as Shift, Control, etc. |
33 | /// It is provided as part of `KeyEvent`'s `modifiers` field. |
34 | /// |
35 | /// Keyboard shortcuts on Apple platforms typically use the Command key (⌘), such as Command+C for "Copy". On other platforms |
36 | /// the same shortcut is typically represented using Control+C. To make it easier to develop cross-platform applications, on macOS, |
37 | /// Slint maps the Command key to the control modifier, and the Control key to the meta modifier. |
38 | /// |
39 | /// On Windows, the Windows key is mapped to the meta modifier. |
40 | #[derive(Copy, Eq)] |
41 | struct KeyboardModifiers { |
42 | @name = "slint::private_api::KeyboardModifiers" |
43 | export { |
44 | /// Indicates the Alt key on a keyboard. |
45 | alt: bool, |
46 | /// Indicates the Control key on a keyboard, except on macOS, where it is the Command key (⌘). |
47 | control: bool, |
48 | /// Indicates the Shift key on a keyboard. |
49 | shift: bool, |
50 | /// Indicates the Control key on macos, and the Windows key on Windows. |
51 | meta: bool, |
52 | } |
53 | private { |
54 | } |
55 | } |
56 | |
57 | /// Represents a Pointer event sent by the windowing system. |
58 | /// This structure is passed to the `pointer-event` callback of the `TouchArea` element. |
59 | struct PointerEvent { |
60 | @name = "slint::private_api::PointerEvent" |
61 | export { |
62 | /// The button that was pressed or released |
63 | button: PointerEventButton, |
64 | /// The kind of the event |
65 | kind: PointerEventKind, |
66 | /// The keyboard modifiers pressed during the event |
67 | modifiers: KeyboardModifiers, |
68 | } |
69 | private { |
70 | } |
71 | } |
72 | |
73 | /// Represents a Pointer scroll (or wheel) event sent by the windowing system. |
74 | /// This structure is passed to the `scroll-event` callback of the `TouchArea` element. |
75 | struct PointerScrollEvent { |
76 | @name = "slint::private_api::PointerScrollEvent" |
77 | export { |
78 | /// The amount of pixel in the horizontal direction |
79 | delta_x: Coord, |
80 | /// The amount of pixel in the vertical direction |
81 | delta_y: Coord, |
82 | /// The keyboard modifiers pressed during the event |
83 | modifiers: KeyboardModifiers, |
84 | } |
85 | private { |
86 | } |
87 | } |
88 | |
89 | /// This structure is generated and passed to the key press and release callbacks of the `FocusScope` element. |
90 | struct KeyEvent { |
91 | @name = "slint::private_api::KeyEvent" |
92 | export { |
93 | /// The unicode representation of the key pressed. |
94 | text: SharedString, |
95 | /// The keyboard modifiers active at the time of the key press event. |
96 | modifiers: KeyboardModifiers, |
97 | /// This field is set to true for key press events that are repeated, |
98 | /// i.e. the key is held down. It's always false for key release events. |
99 | repeat: bool, |
100 | } |
101 | private { |
102 | /// Indicates whether the key was pressed or released |
103 | event_type: KeyEventType, |
104 | /// If the event type is KeyEventType::UpdateComposition or KeyEventType::CommitComposition, |
105 | /// then this field specifies what part of the current text to replace. |
106 | /// Relative to the offset of the pre-edit text within the text input element's text. |
107 | replacement_range: Option<core::ops::Range<i32>>, |
108 | /// If the event type is KeyEventType::UpdateComposition, this is the new pre-edit text |
109 | preedit_text: SharedString, |
110 | /// The selection within the preedit_text |
111 | preedit_selection: Option<core::ops::Range<i32>>, |
112 | /// The new cursor position, when None, the cursor is put after the text that was just inserted |
113 | cursor_position: Option<i32>, |
114 | anchor_position: Option<i32>, |
115 | } |
116 | } |
117 | |
118 | /// Represents an item in a StandardListView and a StandardTableView. |
119 | #[non_exhaustive] |
120 | struct StandardListViewItem { |
121 | @name = "slint::StandardListViewItem" |
122 | export { |
123 | /// The text content of the item |
124 | text: SharedString, |
125 | } |
126 | private { |
127 | } |
128 | } |
129 | |
130 | /// This is used to define the column and the column header of a TableView |
131 | #[non_exhaustive] |
132 | struct TableColumn { |
133 | @name = "slint::private_api::TableColumn" |
134 | export { |
135 | /// The title of the column header |
136 | title: SharedString, |
137 | /// The minimum column width (logical length) |
138 | min_width: Coord, |
139 | /// The horizontal column stretch |
140 | horizontal_stretch: f32, |
141 | /// Sorts the column |
142 | sort_order: SortOrder, |
143 | /// the actual width of the column (logical length) |
144 | width: Coord, |
145 | } |
146 | private { |
147 | } |
148 | } |
149 | |
150 | /// Value of the state property |
151 | /// A state is just the current state, but also has information about the previous state and the moment it changed |
152 | struct StateInfo { |
153 | @name = "slint::private_api::StateInfo" |
154 | export { |
155 | /// The current state value |
156 | current_state: i32, |
157 | /// The previous state |
158 | previous_state: i32, |
159 | } |
160 | private { |
161 | /// The instant in which the state changed last |
162 | change_time: crate::animations::Instant, |
163 | } |
164 | } |
165 | |
166 | /// A structure to hold metrics of a font for a specified pixel size. |
167 | struct FontMetrics { |
168 | @name = "slint::private_api::FontMetrics" |
169 | export { |
170 | /// The distance between the baseline and the top of the tallest glyph in the font. |
171 | ascent: Coord, |
172 | /// The distance between the baseline and the bottom of the tallest glyph in the font. |
173 | /// This is usually negative. |
174 | descent: Coord, |
175 | /// The distance between the baseline and the horizontal midpoint of the tallest glyph in the font, |
176 | /// or zero if not specified by the font. |
177 | x_height: Coord, |
178 | /// The distance between the baseline and the top of a regular upper-case glyph in the font, |
179 | /// or zero if not specified by the font. |
180 | cap_height: Coord, |
181 | } |
182 | private { |
183 | } |
184 | } |
185 | |
186 | /// An item in the menu of a menu bar or context menu |
187 | struct MenuEntry { |
188 | @name = "slint::private_api::MenuEntry" |
189 | export { |
190 | /// The text of the menu entry |
191 | title: SharedString, |
192 | // /// the icon associated with the menu entry |
193 | // icon: Image, |
194 | /// an opaque id that can be used to identify the menu entry |
195 | id: SharedString, |
196 | // keyboard_shortcut: KeySequence, |
197 | /// whether the menu entry is enabled |
198 | enabled: bool, |
199 | /// Sub menu |
200 | has_sub_menu: bool, |
201 | /// The menu entry is a separator |
202 | is_separator: bool, |
203 | } |
204 | private {} |
205 | } |
206 | ]; |
207 | }; |
208 | } |
209 | |