i_slint_common/
builtin_structs.rs

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]
29macro_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            /// This structure is passed to the callbacks of the `DropArea` element
119            struct DropEvent {
120                @name = "slint::private_api::DropEvent"
121                export {
122                    /// The mime type of the data being dragged
123                    mime_type: SharedString,
124                    /// The data being dragged
125                    data: SharedString,
126                    /// The current mouse position in coordinates of the `DropArea` element
127                    position: LogicalPosition,
128                }
129                private {
130                }
131            }
132
133            /// Represents an item in a StandardListView and a StandardTableView.
134            #[non_exhaustive]
135            struct StandardListViewItem {
136                @name = "slint::StandardListViewItem"
137                export {
138                    /// The text content of the item
139                    text: SharedString,
140                }
141                private {
142                }
143            }
144
145            /// This is used to define the column and the column header of a TableView
146            #[non_exhaustive]
147            struct TableColumn {
148                @name = "slint::private_api::TableColumn"
149                export {
150                    /// The title of the column header
151                    title: SharedString,
152                    /// The minimum column width (logical length)
153                    min_width: Coord,
154                    /// The horizontal column stretch
155                    horizontal_stretch: f32,
156                    /// Sorts the column
157                    sort_order: SortOrder,
158                    /// the actual width of the column (logical length)
159                    width: Coord,
160                }
161                private {
162                }
163            }
164
165            /// Value of the state property
166            /// A state is just the current state, but also has information about the previous state and the moment it changed
167            struct StateInfo {
168                @name = "slint::private_api::StateInfo"
169                export {
170                    /// The current state value
171                    current_state: i32,
172                    /// The previous state
173                    previous_state: i32,
174                }
175                private {
176                    /// The instant in which the state changed last
177                    change_time: crate::animations::Instant,
178                }
179            }
180
181            /// A structure to hold metrics of a font for a specified pixel size.
182            struct FontMetrics {
183                @name = "slint::private_api::FontMetrics"
184                export {
185                    /// The distance between the baseline and the top of the tallest glyph in the font.
186                    ascent: Coord,
187                    /// The distance between the baseline and the bottom of the tallest glyph in the font.
188                    /// This is usually negative.
189                    descent: Coord,
190                    /// The distance between the baseline and the horizontal midpoint of the tallest glyph in the font,
191                    /// or zero if not specified by the font.
192                    x_height: Coord,
193                    /// The distance between the baseline and the top of a regular upper-case glyph in the font,
194                    /// or zero if not specified by the font.
195                    cap_height: Coord,
196                }
197                private {
198                }
199            }
200
201            /// An item in the menu of a menu bar or context menu
202            struct MenuEntry {
203                @name = "slint::private_api::MenuEntry"
204                export {
205                    /// The text of the menu entry
206                    title: SharedString,
207                    /// the icon associated with the menu entry
208                    icon: Image,
209                    /// an opaque id that can be used to identify the menu entry
210                    id: SharedString,
211                    // keyboard_shortcut: KeySequence,
212                    /// whether the menu entry is enabled
213                    enabled: bool,
214                    /// whether the menu entry is checkable
215                    checkable: bool,
216                    /// whether the menu entry is checked
217                    checked: bool,
218                    /// Sub menu
219                    has_sub_menu: bool,
220                    /// The menu entry is a separator
221                    is_separator: bool,
222                }
223                private {}
224            }
225        ];
226    };
227}