1 | #pragma once |
2 | |
3 | /* Generated with cbindgen:0.26.0 */ |
4 | |
5 | #include <cstdarg> |
6 | #include <cstdint> |
7 | #include <cstdlib> |
8 | #include <ostream> |
9 | #include <new> |
10 | #include "slint_config.h" |
11 | #include "vtable.h" |
12 | #include "slint_string.h" |
13 | #include "slint_sharedvector.h" |
14 | #include "slint_properties.h" |
15 | #include "slint_callbacks.h" |
16 | #include "slint_color.h" |
17 | #include "slint_image.h" |
18 | #include "slint_pathdata.h" |
19 | #include "slint_brush.h" |
20 | #include "slint_generated_public.h" |
21 | #include "slint_enums_internal.h" |
22 | #include "slint_point.h" |
23 | #include "slint_timer.h" |
24 | #include "slint_builtin_structs_internal.h" |
25 | |
26 | namespace slint { |
27 | namespace private_api { class WindowAdapterRc; } |
28 | namespace cbindgen_private { |
29 | using slint::private_api::WindowAdapterRc; |
30 | using namespace vtable; |
31 | struct KeyEvent; struct PointerEvent; |
32 | using private_api::Property; |
33 | using private_api::PathData; |
34 | using private_api::Point; |
35 | struct Rect; |
36 | using LogicalRect = Rect; |
37 | using LogicalPoint = Point2D<float>; |
38 | using LogicalLength = float; |
39 | struct ItemTreeVTable; |
40 | struct ItemVTable; |
41 | using types::IntRect; |
42 | } |
43 | } |
44 | |
45 | namespace slint { |
46 | namespace cbindgen_private { |
47 | |
48 | enum class AccessibleStringProperty : uint32_t { |
49 | Checkable, |
50 | Checked, |
51 | DelegateFocus, |
52 | Description, |
53 | Label, |
54 | Value, |
55 | ValueMaximum, |
56 | ValueMinimum, |
57 | ValueStep, |
58 | }; |
59 | |
60 | /// The clip board, used in [`Platform::clipboard_text`] and [Platform::set_clipboard_text`] |
61 | enum class Clipboard : uint8_t { |
62 | /// This is the default clipboard used for text action for Ctrl+V, Ctrl+C. |
63 | /// Corresponds to the secondary clipboard on X11. |
64 | DefaultClipboard = 0, |
65 | /// This is the clipboard that is used when text is selected |
66 | /// Corresponds to the primary clipboard on X11. |
67 | /// The Platform implementation should do nothing if copy on select is not supported on that platform. |
68 | SelectionClipboard = 1, |
69 | }; |
70 | |
71 | /// This event is sent to a component and items when they receive or loose |
72 | /// the keyboard focus. |
73 | enum class FocusEvent : uint8_t { |
74 | /// This event is sent when an item receives the focus. |
75 | FocusIn, |
76 | /// This event is sent when an item looses the focus. |
77 | FocusOut, |
78 | /// This event is sent when the window receives the keyboard focus. |
79 | WindowReceivedFocus, |
80 | /// This event is sent when the window looses the keyboard focus. |
81 | WindowLostFocus, |
82 | }; |
83 | |
84 | /// Represents how an item's focus_event handler dealt with a focus event. |
85 | /// An accepted event results in no further event propagation. |
86 | enum class FocusEventResult : uint8_t { |
87 | /// The event was handled. |
88 | FocusAccepted, |
89 | /// The event was not handled and should be sent to other items. |
90 | FocusIgnored, |
91 | }; |
92 | |
93 | /// This value is returned by the `input_event` function of an Item |
94 | /// to notify the run-time about how the event was handled and |
95 | /// what the next steps are. |
96 | /// See [`crate::items::ItemVTable::input_event`]. |
97 | enum class InputEventResult : uint8_t { |
98 | /// The event was accepted. This may result in additional events, for example |
99 | /// accepting a mouse move will result in a MouseExit event later. |
100 | EventAccepted, |
101 | /// The event was ignored. |
102 | EventIgnored, |
103 | /// All further mouse event need to be sent to this item or component |
104 | GrabMouse, |
105 | }; |
106 | |
107 | /// Represents how an item's key_event handler dealt with a key event. |
108 | /// An accepted event results in no further event propagation. |
109 | enum class KeyEventResult : uint8_t { |
110 | /// The event was handled. |
111 | EventAccepted, |
112 | /// The event was not handled and should be sent to other items. |
113 | EventIgnored, |
114 | }; |
115 | |
116 | /// This enum defines the different kinds of key events that can happen. |
117 | enum class KeyEventType : uint8_t { |
118 | /// A key on a keyboard was pressed. |
119 | KeyPressed = 0, |
120 | /// A key on a keyboard was released. |
121 | KeyReleased = 1, |
122 | /// The input method updates the currently composed text. The KeyEvent's text field is the pre-edit text and |
123 | /// composition_selection specifies the placement of the cursor within the pre-edit text. |
124 | UpdateComposition = 2, |
125 | /// The input method replaces the currently composed text with the final result of the composition. |
126 | CommitComposition = 3, |
127 | }; |
128 | |
129 | /// Returned by the `render()` function on items to indicate whether the rendering of |
130 | /// children should be handled by the caller, of if the item took care of that (for example |
131 | /// through layer indirection) |
132 | enum class RenderingResult { |
133 | ContinueRenderingChildren, |
134 | ContinueRenderingWithoutChildren, |
135 | }; |
136 | |
137 | enum class TraversalOrder : uint8_t { |
138 | BackToFront, |
139 | FrontToBack, |
140 | }; |
141 | |
142 | enum class UndoItemKind { |
143 | TextInsert, |
144 | TextRemove, |
145 | }; |
146 | |
147 | struct FlickableData; |
148 | |
149 | /// Alias for `&mut dyn ItemRenderer`. Required so cbindgen generates the ItemVTable |
150 | /// despite the presence of trait object |
151 | struct ItemRendererRef; |
152 | |
153 | template<typename T = void> |
154 | struct Option; |
155 | |
156 | /// The return value of the ItemTree::visit_children_item function |
157 | /// |
158 | /// Represents something like `enum { Continue, Aborted{aborted_at_item: isize} }`. |
159 | /// But this is just wrapping a int because it is easier to use ffi with isize than |
160 | /// complex enum. |
161 | /// |
162 | /// -1 means the visitor will continue |
163 | /// otherwise this is the index of the item that aborted the visit. |
164 | using VisitChildrenResult = uint64_t; |
165 | /// The result used for a visitor that want to continue the visit |
166 | constexpr static const VisitChildrenResult VisitChildrenResult_CONTINUE = UINT64_MAX; |
167 | |
168 | /// A ItemRc is holding a reference to a ItemTree containing the item, and the index of this item |
169 | struct ItemRc { |
170 | VRc<ItemTreeVTable> item_tree; |
171 | uint32_t index; |
172 | }; |
173 | |
174 | /// The constraint that applies to an item |
175 | struct LayoutInfo { |
176 | /// The maximum size for the item. |
177 | float max; |
178 | /// The maximum size in percentage of the parent (value between 0 and 100). |
179 | float max_percent; |
180 | /// The minimum size for this item. |
181 | float min; |
182 | /// The minimum size in percentage of the parent (value between 0 and 100). |
183 | float min_percent; |
184 | /// the preferred size |
185 | float preferred; |
186 | /// the stretch factor |
187 | float stretch; |
188 | inline LayoutInfo merge(const LayoutInfo &other) const; |
189 | friend inline LayoutInfo operator+(const LayoutInfo &a, const LayoutInfo &b) { return a.merge(other: b); } |
190 | friend bool operator==(const LayoutInfo&, const LayoutInfo&) = default; |
191 | }; |
192 | |
193 | /// This value is returned by the `input_event_filter_before_children` function, which |
194 | /// can specify how to further process the event. |
195 | /// See [`crate::items::ItemVTable::input_event_filter_before_children`]. |
196 | struct InputEventFilterResult { |
197 | enum class Tag { |
198 | /// The event is going to be forwarded to children, then the [`crate::items::ItemVTable::input_event`] |
199 | /// function is called |
200 | ForwardEvent, |
201 | /// The event will be forwarded to the children, but the [`crate::items::ItemVTable::input_event`] is not |
202 | /// going to be called for this item |
203 | ForwardAndIgnore, |
204 | /// Just like `ForwardEvent`, but even in the case the children grabs the mouse, this function |
205 | /// will still be called for further event |
206 | ForwardAndInterceptGrab, |
207 | /// The event will not be forwarded to children, if a children already had the grab, the |
208 | /// grab will be cancelled with a [`MouseEvent::Exit`] event |
209 | Intercept, |
210 | /// The event will be forwarding to the children with a delay (in milliseconds), unless it is |
211 | /// being intercepted. |
212 | /// This is what happens when the flickable wants to delay the event. |
213 | /// This should only be used for Press event, and the event will be sent after the delay, or |
214 | /// if a release event is seen before that delay |
215 | DelayForwarding, |
216 | }; |
217 | |
218 | struct DelayForwarding_Body { |
219 | uint64_t _0; |
220 | }; |
221 | |
222 | Tag tag; |
223 | union { |
224 | DelayForwarding_Body delay_forwarding; |
225 | }; |
226 | }; |
227 | |
228 | /// A mouse or touch event |
229 | /// |
230 | /// The only difference with [`crate::platform::WindowEvent`] us that it uses untyped `Point` |
231 | /// TODO: merge with platform::WindowEvent |
232 | struct MouseEvent { |
233 | enum class Tag { |
234 | /// The mouse or finger was pressed |
235 | /// `position` is the position of the mouse when the event happens. |
236 | /// `button` describes the button that is pressed when the event happens. |
237 | /// `click_count` represents the current number of clicks. |
238 | Pressed, |
239 | /// The mouse or finger was released |
240 | /// `position` is the position of the mouse when the event happens. |
241 | /// `button` describes the button that is pressed when the event happens. |
242 | /// `click_count` represents the current number of clicks. |
243 | Released, |
244 | /// The position of the pointer has changed |
245 | Moved, |
246 | /// Wheel was operated. |
247 | /// `pos` is the position of the mouse when the event happens. |
248 | /// `delta_x` is the amount of pixels to scroll in horizontal direction, |
249 | /// `delta_y` is the amount of pixels to scroll in vertical direction. |
250 | Wheel, |
251 | /// The mouse exited the item or component |
252 | Exit, |
253 | }; |
254 | |
255 | struct Pressed_Body { |
256 | LogicalPoint position; |
257 | PointerEventButton button; |
258 | uint8_t click_count; |
259 | }; |
260 | |
261 | struct Released_Body { |
262 | LogicalPoint position; |
263 | PointerEventButton button; |
264 | uint8_t click_count; |
265 | }; |
266 | |
267 | struct Moved_Body { |
268 | LogicalPoint position; |
269 | }; |
270 | |
271 | struct Wheel_Body { |
272 | LogicalPoint position; |
273 | float delta_x; |
274 | float delta_y; |
275 | }; |
276 | |
277 | Tag tag; |
278 | union { |
279 | Pressed_Body pressed; |
280 | Released_Body released; |
281 | Moved_Body moved; |
282 | Wheel_Body wheel; |
283 | }; |
284 | }; |
285 | |
286 | /// A size represented in the coordinate space of logical pixels. That is the space before applying |
287 | /// a display device specific scale factor. |
288 | struct LogicalSize { |
289 | /// The width in logical pixels. |
290 | float width; |
291 | /// The height in logical. |
292 | float height; |
293 | }; |
294 | |
295 | /// Items are the nodes in the render tree. |
296 | struct ItemVTable { |
297 | /// This function is called by the run-time after the memory for the item |
298 | /// has been allocated and initialized. It will be called before any user specified |
299 | /// bindings are set. |
300 | void (*init)(Pin<VRef<ItemVTable>>, const ItemRc *my_item); |
301 | /// offset in bytes from the *const ItemImpl. |
302 | /// isize::MAX means None |
303 | uintptr_t cached_rendering_data_offset; |
304 | /// We would need max/min/preferred size, and all layout info |
305 | LayoutInfo (*layout_info)(Pin<VRef<ItemVTable>>, |
306 | Orientation orientation, |
307 | const WindowAdapterRc *window_adapter); |
308 | /// Event handler for mouse and touch event. This function is called before being called on children. |
309 | /// Then, depending on the return value, it is called for the children, and their children, then |
310 | /// [`Self::input_event`] is called on the children, and finally [`Self::input_event`] is called |
311 | /// on this item again. |
312 | InputEventFilterResult (*input_event_filter_before_children)(Pin<VRef<ItemVTable>>, |
313 | MouseEvent, |
314 | const WindowAdapterRc *window_adapter, |
315 | const ItemRc *self_rc); |
316 | /// Handle input event for mouse and touch event |
317 | InputEventResult (*input_event)(Pin<VRef<ItemVTable>>, |
318 | MouseEvent, |
319 | const WindowAdapterRc *window_adapter, |
320 | const ItemRc *self_rc); |
321 | FocusEventResult (*focus_event)(Pin<VRef<ItemVTable>>, |
322 | const FocusEvent*, |
323 | const WindowAdapterRc *window_adapter, |
324 | const ItemRc *self_rc); |
325 | KeyEventResult (*key_event)(Pin<VRef<ItemVTable>>, |
326 | const KeyEvent*, |
327 | const WindowAdapterRc *window_adapter, |
328 | const ItemRc *self_rc); |
329 | RenderingResult (*render)(Pin<VRef<ItemVTable>>, |
330 | ItemRendererRef *backend, |
331 | const ItemRc *self_rc, |
332 | LogicalSize size); |
333 | }; |
334 | |
335 | /// Object to be passed in visit_item_children method of the ItemTree. |
336 | struct ItemVisitorVTable { |
337 | /// Called for each child of the visited item |
338 | /// |
339 | /// The `item_tree` parameter is the ItemTree in which the item live which might not be the same |
340 | /// as the parent's ItemTree. |
341 | /// `index` is to be used again in the visit_item_children function of the ItemTree (the one passed as parameter) |
342 | /// and `item` is a reference to the item itself |
343 | VisitChildrenResult (*visit_item)(VRefMut<ItemVisitorVTable>, |
344 | const VRc<ItemTreeVTable, Dyn> *item_tree, |
345 | uint32_t index, |
346 | Pin<VRef<ItemVTable>> item); |
347 | /// Destructor |
348 | void (*drop)(VRefMut<ItemVisitorVTable>); |
349 | }; |
350 | |
351 | /// A range of indices |
352 | struct IndexRange { |
353 | /// Start index |
354 | uintptr_t start; |
355 | /// Index one past the last index |
356 | uintptr_t end; |
357 | }; |
358 | |
359 | /// The item tree is an array of ItemTreeNode representing a static tree of items |
360 | /// within a ItemTree. |
361 | union ItemTreeNode { |
362 | enum class Tag : uint8_t { |
363 | /// Static item |
364 | Item, |
365 | /// A placeholder for many instance of item in their own ItemTree which |
366 | /// are instantiated according to a model. |
367 | DynamicTree, |
368 | }; |
369 | |
370 | struct Item_Body { |
371 | Tag tag; |
372 | /// True when the item has accessibility properties attached |
373 | bool is_accessible; |
374 | /// number of children |
375 | uint32_t children_count; |
376 | /// index of the first children within the item tree |
377 | uint32_t children_index; |
378 | /// The index of the parent item (not valid for the root) |
379 | uint32_t parent_index; |
380 | /// The index in the extra item_array |
381 | uint32_t item_array_index; |
382 | }; |
383 | |
384 | struct DynamicTree_Body { |
385 | Tag tag; |
386 | /// the index which is passed in the visit_dynamic callback. |
387 | uint32_t index; |
388 | /// The index of the parent item (not valid for the root) |
389 | uint32_t parent_index; |
390 | }; |
391 | |
392 | struct { |
393 | Tag tag; |
394 | }; |
395 | Item_Body item; |
396 | DynamicTree_Body dynamic_tree; |
397 | constexpr ItemTreeNode(Item_Body x) : item {x} {} |
398 | constexpr ItemTreeNode(DynamicTree_Body x) : dynamic_tree{x} {} |
399 | }; |
400 | |
401 | /// Type alias to the commonly used VWeak<ItemTreeVTable, Dyn>> |
402 | using ItemTreeWeak = VWeak<ItemTreeVTable, Dyn>; |
403 | |
404 | /// A Weak reference to an item that can be constructed from an ItemRc. |
405 | struct ItemWeak { |
406 | ItemTreeWeak item_tree; |
407 | uint32_t index; |
408 | }; |
409 | |
410 | /// A ItemTree is representing an unit that is allocated together |
411 | struct ItemTreeVTable { |
412 | /// Visit the children of the item at index `index`. |
413 | /// Note that the root item is at index 0, so passing 0 would visit the item under root (the children of root). |
414 | /// If you want to visit the root item, you need to pass -1 as an index. |
415 | VisitChildrenResult (*visit_children_item)(Pin<VRef<ItemTreeVTable>>, |
416 | intptr_t index, |
417 | TraversalOrder order, |
418 | VRefMut<ItemVisitorVTable> visitor); |
419 | /// Return a reference to an item using the given index |
420 | Pin<VRef<ItemVTable>> (*get_item_ref)(Pin<VRef<ItemTreeVTable>>, uint32_t index); |
421 | /// Return the range of indices below the dynamic `ItemTreeNode` at `index` |
422 | IndexRange (*get_subtree_range)(Pin<VRef<ItemTreeVTable>>, uint32_t index); |
423 | /// Return the `ItemTreeRc` at `subindex` below the dynamic `ItemTreeNode` at `index` |
424 | void (*get_subtree)(Pin<VRef<ItemTreeVTable>>, |
425 | uint32_t index, |
426 | uintptr_t subindex, |
427 | VWeak<ItemTreeVTable, Dyn> *result); |
428 | /// Return the item tree that is defined by this `ItemTree`. |
429 | /// The return value is an item weak because it can be null if there is no parent. |
430 | /// And the return value is passed by &mut because ItemWeak has a destructor |
431 | Slice<ItemTreeNode> (*get_item_tree)(Pin<VRef<ItemTreeVTable>>); |
432 | /// Return the node this ItemTree is a part of in the parent ItemTree. |
433 | /// |
434 | /// The return value is an item weak because it can be null if there is no parent. |
435 | /// And the return value is passed by &mut because ItemWeak has a destructor |
436 | /// Note that the returned value will typically point to a repeater node, which is |
437 | /// strictly speaking not an Item at all! |
438 | void (*parent_node)(Pin<VRef<ItemTreeVTable>>, ItemWeak *result); |
439 | /// This embeds this ItemTree into the item tree of another ItemTree |
440 | /// |
441 | /// Returns `true` if this ItemTree was embedded into the `parent` |
442 | /// at `parent_item_tree_index`. |
443 | bool (*embed_component)(Pin<VRef<ItemTreeVTable>>, |
444 | const VWeak<ItemTreeVTable> *parent, |
445 | uint32_t parent_item_tree_index); |
446 | /// Return the index of the current subtree or usize::MAX if this is not a subtree |
447 | uintptr_t (*subtree_index)(Pin<VRef<ItemTreeVTable>>); |
448 | /// Returns the layout info for the root of the ItemTree |
449 | LayoutInfo (*layout_info)(Pin<VRef<ItemTreeVTable>>, Orientation); |
450 | /// Returns the item's geometry (relative to its parent item) |
451 | LogicalRect (*item_geometry)(Pin<VRef<ItemTreeVTable>>, uint32_t item_index); |
452 | /// Returns the accessible role for a given item |
453 | AccessibleRole (*accessible_role)(Pin<VRef<ItemTreeVTable>>, uint32_t item_index); |
454 | /// Returns the accessible property |
455 | void (*accessible_string_property)(Pin<VRef<ItemTreeVTable>>, |
456 | uint32_t item_index, |
457 | AccessibleStringProperty what, |
458 | SharedString *result); |
459 | /// Returns a Window, creating a fresh one if `do_create` is true. |
460 | void (*window_adapter)(Pin<VRef<ItemTreeVTable>>, |
461 | bool do_create, |
462 | Option<WindowAdapterRc> *result); |
463 | /// in-place destructor (for VRc) |
464 | Layout (*drop_in_place)(VRefMut<ItemTreeVTable>); |
465 | /// dealloc function (for VRc) |
466 | void (*dealloc)(const ItemTreeVTable*, uint8_t *ptr, Layout layout); |
467 | }; |
468 | |
469 | /// Type alias to the commonly used VRc<ItemTreeVTable, Dyn>> |
470 | using ItemTreeRc = VRc<ItemTreeVTable, Dyn>; |
471 | |
472 | /// Same layout as WindowAdapterRc |
473 | struct WindowAdapterRcOpaque { |
474 | const void *_0; |
475 | const void *_1; |
476 | }; |
477 | |
478 | /// Alias for `vtable::VRef<ItemTreeVTable>` which represent a pointer to a `dyn ItemTree` with |
479 | /// the associated vtable |
480 | using ItemTreeRef = VRef<ItemTreeVTable>; |
481 | |
482 | /// Type alias to the commonly used `Pin<VRef<ItemTreeVTable>>>` |
483 | using ItemTreeRefPin = Pin<ItemTreeRef>; |
484 | |
485 | /// Wraps the internal data structure for the Flickable |
486 | struct FlickableDataBox { |
487 | struct FlickableData; |
488 | FlickableData *_0; |
489 | }; |
490 | |
491 | /// Similar as `Option<core::ops::Range<i32>>` but `repr(C)` |
492 | /// |
493 | /// This is the selection within a preedit |
494 | struct PreEditSelection { |
495 | bool valid; |
496 | int32_t start; |
497 | int32_t end; |
498 | }; |
499 | |
500 | /// This structure must be present in items that are Rendered and contains information. |
501 | /// Used by the backend. |
502 | struct CachedRenderingData { |
503 | /// Used and modified by the backend, should be initialized to 0 by the user code |
504 | uintptr_t cache_index; |
505 | /// Used and modified by the backend, should be initialized to 0 by the user code. |
506 | /// The backend compares this generation against the one of the cache to verify |
507 | /// the validity of the cache_index field. |
508 | uintptr_t cache_generation; |
509 | constexpr CachedRenderingData() : cache_index{}, cache_generation{} {} |
510 | }; |
511 | |
512 | struct UndoItem { |
513 | uintptr_t pos; |
514 | SharedString text; |
515 | uintptr_t cursor; |
516 | uintptr_t anchor; |
517 | UndoItemKind kind; |
518 | }; |
519 | |
520 | /// The implementation of the `TextInput` element |
521 | struct TextInput { |
522 | Property<SharedString> text; |
523 | Property<SharedString> font_family; |
524 | Property<LogicalLength> font_size; |
525 | Property<int32_t> font_weight; |
526 | Property<bool> font_italic; |
527 | Property<Brush> color; |
528 | Property<Color> selection_foreground_color; |
529 | Property<Color> selection_background_color; |
530 | Property<TextHorizontalAlignment> horizontal_alignment; |
531 | Property<TextVerticalAlignment> vertical_alignment; |
532 | Property<TextWrap> wrap; |
533 | Property<InputType> input_type; |
534 | Property<LogicalLength> letter_spacing; |
535 | Property<LogicalLength> width; |
536 | Property<LogicalLength> height; |
537 | Property<int32_t> cursor_position_byte_offset; |
538 | Property<int32_t> anchor_position_byte_offset; |
539 | Property<LogicalLength> text_cursor_width; |
540 | Property<bool> cursor_visible; |
541 | Property<bool> has_focus; |
542 | Property<bool> enabled; |
543 | private_api::CallbackHelper<void> accepted; |
544 | private_api::CallbackHelper<slint::LogicalPosition> cursor_position_changed; |
545 | private_api::CallbackHelper<void> edited; |
546 | Property<bool> single_line; |
547 | Property<bool> read_only; |
548 | Property<SharedString> preedit_text; |
549 | /// A selection within the preedit (cursor and anchor) |
550 | Property<PreEditSelection> preedit_selection; |
551 | CachedRenderingData cached_rendering_data; |
552 | float preferred_x_pos; |
553 | /// 0 = not pressed, 1 = single press, 2 = double clicked+press , ... |
554 | uint8_t pressed; |
555 | SharedVector<UndoItem> undo_items; |
556 | SharedVector<UndoItem> redo_items; |
557 | }; |
558 | |
559 | struct Padding { |
560 | float begin; |
561 | float end; |
562 | }; |
563 | |
564 | struct GridLayoutCellData { |
565 | /// col, or row. |
566 | uint16_t col_or_row; |
567 | /// colspan or rowspan |
568 | uint16_t span; |
569 | LayoutInfo constraint; |
570 | }; |
571 | |
572 | struct GridLayoutData { |
573 | float size; |
574 | float spacing; |
575 | Padding padding; |
576 | Slice<GridLayoutCellData> cells; |
577 | }; |
578 | |
579 | struct BoxLayoutCellData { |
580 | LayoutInfo constraint; |
581 | }; |
582 | |
583 | /// The BoxLayoutData is used to represent both a Horizontal and Vertical layout. |
584 | /// The width/height x/y correspond to that of a horizontal layout. |
585 | /// For vertical layout, they are inverted |
586 | struct BoxLayoutData { |
587 | float size; |
588 | float spacing; |
589 | Padding padding; |
590 | LayoutAlignment alignment; |
591 | Slice<BoxLayoutCellData> cells; |
592 | }; |
593 | |
594 | /// The representation of an easing curve, for animations |
595 | struct EasingCurve { |
596 | enum class Tag : uint32_t { |
597 | /// The linear curve |
598 | Linear, |
599 | /// A Cubic bezier curve, with its 4 parameters |
600 | CubicBezier, |
601 | /// Easing curve as defined at: <https://easings.net/#easeInElastic> |
602 | EaseInElastic, |
603 | /// Easing curve as defined at: <https://easings.net/#easeOutElastic> |
604 | EaseOutElastic, |
605 | /// Easing curve as defined at: <https://easings.net/#easeInOutElastic> |
606 | EaseInOutElastic, |
607 | /// Easing curve as defined at: <https://easings.net/#easeInBounce> |
608 | EaseInBounce, |
609 | /// Easing curve as defined at: <https://easings.net/#easeOutBounce> |
610 | EaseOutBounce, |
611 | /// Easing curve as defined at: <https://easings.net/#easeInOutBounce> |
612 | EaseInOutBounce, |
613 | }; |
614 | |
615 | struct CubicBezier_Body { |
616 | float _0[4]; |
617 | }; |
618 | |
619 | Tag tag; |
620 | union { |
621 | CubicBezier_Body cubic_bezier; |
622 | }; |
623 | constexpr EasingCurve(EasingCurve::Tag tag = Tag::Linear, float a = 0, float b = 0, float c = 1, float d = 1) : tag(tag), cubic_bezier{._0: {a,b,c,d}} {} |
624 | }; |
625 | |
626 | /// The implementation of the `PropertyAnimation` element |
627 | struct PropertyAnimation { |
628 | int32_t delay; |
629 | int32_t duration; |
630 | float iteration_count; |
631 | EasingCurve easing; |
632 | }; |
633 | |
634 | /// 2D Size in integer coordinates |
635 | using IntSize = Size2D<uint32_t>; |
636 | |
637 | /// 2D Size |
638 | using Size = Size2D<float>; |
639 | |
640 | /// A position represented in the coordinate space of logical pixels. That is the space before applying |
641 | /// a display device specific scale factor. |
642 | struct LogicalPosition { |
643 | /// The x coordinate. |
644 | float x; |
645 | /// The y coordinate. |
646 | float y; |
647 | }; |
648 | |
649 | /// A event that describes user input or windowing system events. |
650 | /// |
651 | /// Slint backends typically receive events from the windowing system, translate them to this |
652 | /// enum and deliver them to the scene of items via [`slint::Window::dispatch_event()`](`crate::api::Window::dispatch_event()`). |
653 | /// |
654 | /// The pointer variants describe events originating from an input device such as a mouse |
655 | /// or a contact point on a touch-enabled surface. |
656 | /// |
657 | /// All position fields are in logical window coordinates. |
658 | union WindowEvent { |
659 | enum class Tag : uint32_t { |
660 | /// A pointer was pressed. |
661 | PointerPressed, |
662 | /// A pointer was released. |
663 | PointerReleased, |
664 | /// The position of the pointer has changed. |
665 | PointerMoved, |
666 | /// The wheel button of a mouse was rotated to initiate scrolling. |
667 | PointerScrolled, |
668 | /// The pointer exited the window. |
669 | PointerExited, |
670 | /// A key was pressed. |
671 | KeyPressed, |
672 | /// A key press was auto-repeated. |
673 | KeyPressRepeated, |
674 | /// A key was released. |
675 | KeyReleased, |
676 | /// The window's scale factor has changed. This can happen for example when the display's resolution |
677 | /// changes, the user selects a new scale factor in the system settings, or the window is moved to a |
678 | /// different screen. |
679 | /// Platform implementations should dispatch this event also right after the initial window creation, |
680 | /// to set the initial scale factor the windowing system provided for the window. |
681 | ScaleFactorChanged, |
682 | /// The window was resized. |
683 | /// |
684 | /// The backend must send this event to ensure that the `width` and `height` property of the root Window |
685 | /// element are properly set. |
686 | Resized, |
687 | /// The user requested to close the window. |
688 | /// |
689 | /// The backend should send this event when the user tries to close the window,for example by pressing the close button. |
690 | /// |
691 | /// This will have the effect of invoking the callback set in [`Window::on_close_requested()`](`crate::api::Window::on_close_requested()`) |
692 | /// and then hiding the window depending on the return value of the callback. |
693 | CloseRequested, |
694 | /// The Window was activated or de-activated. |
695 | /// |
696 | /// The backend should dispatch this event with true when the window gains focus |
697 | /// and false when the window loses focus. |
698 | WindowActiveChanged, |
699 | }; |
700 | |
701 | struct PointerPressed_Body { |
702 | Tag tag; |
703 | LogicalPosition position; |
704 | /// The button that was pressed. |
705 | PointerEventButton button; |
706 | }; |
707 | |
708 | struct PointerReleased_Body { |
709 | Tag tag; |
710 | LogicalPosition position; |
711 | /// The button that was released. |
712 | PointerEventButton button; |
713 | }; |
714 | |
715 | struct PointerMoved_Body { |
716 | Tag tag; |
717 | LogicalPosition position; |
718 | }; |
719 | |
720 | struct PointerScrolled_Body { |
721 | Tag tag; |
722 | LogicalPosition position; |
723 | /// The amount of logical pixels to scroll in the horizontal direction. |
724 | float delta_x; |
725 | /// The amount of logical pixels to scroll in the vertical direction. |
726 | float delta_y; |
727 | }; |
728 | |
729 | struct KeyPressed_Body { |
730 | Tag tag; |
731 | /// The unicode representation of the key pressed. |
732 | /// |
733 | /// # Example |
734 | /// A specific key can be mapped to a unicode by using the [`Key`] enum |
735 | /// ```rust |
736 | /// let _ = slint::platform::WindowEvent::KeyPressed { text: slint::platform::Key::Shift.into() }; |
737 | /// ``` |
738 | SharedString text; |
739 | }; |
740 | |
741 | struct KeyPressRepeated_Body { |
742 | Tag tag; |
743 | /// The unicode representation of the key pressed. |
744 | /// |
745 | /// # Example |
746 | /// A specific key can be mapped to a unicode by using the [`Key`] enum |
747 | /// ```rust |
748 | /// let _ = slint::platform::WindowEvent::KeyPressRepeated { text: slint::platform::Key::Shift.into() }; |
749 | /// ``` |
750 | SharedString text; |
751 | }; |
752 | |
753 | struct KeyReleased_Body { |
754 | Tag tag; |
755 | /// The unicode representation of the key released. |
756 | /// |
757 | /// # Example |
758 | /// A specific key can be mapped to a unicode by using the [`Key`] enum |
759 | /// ```rust |
760 | /// let _ = slint::platform::WindowEvent::KeyReleased { text: slint::platform::Key::Shift.into() }; |
761 | /// ``` |
762 | SharedString text; |
763 | }; |
764 | |
765 | struct ScaleFactorChanged_Body { |
766 | Tag tag; |
767 | /// The window system provided scale factor to map logical pixels to physical pixels. |
768 | float scale_factor; |
769 | }; |
770 | |
771 | struct Resized_Body { |
772 | Tag tag; |
773 | /// The new logical size of the window |
774 | LogicalSize size; |
775 | }; |
776 | |
777 | struct WindowActiveChanged_Body { |
778 | Tag tag; |
779 | bool _0; |
780 | }; |
781 | |
782 | struct { |
783 | Tag tag; |
784 | }; |
785 | PointerPressed_Body pointer_pressed; |
786 | PointerReleased_Body pointer_released; |
787 | PointerMoved_Body pointer_moved; |
788 | PointerScrolled_Body pointer_scrolled; |
789 | KeyPressed_Body key_pressed; |
790 | KeyPressRepeated_Body key_press_repeated; |
791 | KeyReleased_Body key_released; |
792 | ScaleFactorChanged_Body scale_factor_changed; |
793 | Resized_Body resized; |
794 | WindowActiveChanged_Body window_active_changed; |
795 | /* Some members of the WindowEvent enum have destructors (with SharedString), but thankfully we don't use these so we can have an empty constructor */ |
796 | ~WindowEvent() {} |
797 | }; |
798 | |
799 | /// Expand Rect so that cbindgen can see it. ( is in fact euclid::default::Rect<f32>) |
800 | struct Rect { |
801 | float x; |
802 | float y; |
803 | float width; |
804 | float height; |
805 | }; |
806 | |
807 | /// An entry in the character map of a [`BitmapFont`]. |
808 | struct CharacterMapEntry { |
809 | /// The unicode code point for a given glyph |
810 | uint32_t code_point; |
811 | /// The corresponding index in the `glyph_data` of [`BitmapGlyphs`] |
812 | uint16_t glyph_index; |
813 | }; |
814 | |
815 | /// A pre-rendered glyph with the alpha map and associated metrics |
816 | struct BitmapGlyph { |
817 | /// The starting x-coordinate for the glyph, relative to the base line |
818 | int16_t x; |
819 | /// The starting y-coordinate for the glyph, relative to the base line |
820 | int16_t y; |
821 | /// The width of the glyph in pixels |
822 | int16_t width; |
823 | /// The height of the glyph in pixels |
824 | int16_t height; |
825 | /// The horizontal distance to the next glyph |
826 | int16_t x_advance; |
827 | /// The 8-bit alpha map that's to be blended with the current text color |
828 | Slice<uint8_t> data; |
829 | }; |
830 | |
831 | /// A set of pre-rendered bitmap glyphs at a fixed pixel size |
832 | struct BitmapGlyphs { |
833 | /// The font size in pixels at which the glyphs were pre-rendered. The boundaries of glyphs may exceed this |
834 | /// size, if the font designer has chosen so. This is only used for matching. |
835 | int16_t pixel_size; |
836 | /// The data of the pre-rendered glyphs |
837 | Slice<BitmapGlyph> glyph_data; |
838 | }; |
839 | |
840 | /// A subset of an originally scalable font that's rendered ahead of time. |
841 | struct BitmapFont { |
842 | /// The family name of the font |
843 | Slice<uint8_t> family_name; |
844 | /// A vector of code points and their corresponding glyph index, sorted by code point. |
845 | Slice<CharacterMapEntry> character_map; |
846 | /// The font supplied size of the em square. |
847 | float units_per_em; |
848 | /// The font ascent in design metrics (typically positive) |
849 | float ascent; |
850 | /// The font descent in design metrics (typically negative) |
851 | float descent; |
852 | /// A vector of pre-rendered glyph sets. Each glyph set must have the same number of glyphs, |
853 | /// which must be at least as big as the largest glyph index in the character map. |
854 | Slice<BitmapGlyphs> glyphs; |
855 | /// The weight of the font in CSS units (400 is normal). |
856 | uint16_t weight; |
857 | /// Whether the type-face is rendered italic. |
858 | bool italic; |
859 | }; |
860 | |
861 | /// The implementation of an empty items that does nothing |
862 | struct Empty { |
863 | CachedRenderingData cached_rendering_data; |
864 | }; |
865 | |
866 | /// The implementation of the `Rectangle` element |
867 | struct Rectangle { |
868 | Property<Brush> background; |
869 | CachedRenderingData cached_rendering_data; |
870 | }; |
871 | |
872 | /// The implementation of the `BasicBorderRectangle` element |
873 | struct BasicBorderRectangle { |
874 | Property<Brush> background; |
875 | Property<LogicalLength> border_width; |
876 | Property<LogicalLength> border_radius; |
877 | Property<Brush> border_color; |
878 | CachedRenderingData cached_rendering_data; |
879 | }; |
880 | |
881 | /// The implementation of the `BorderRectangle` element |
882 | struct BorderRectangle { |
883 | Property<Brush> background; |
884 | Property<LogicalLength> border_width; |
885 | Property<LogicalLength> border_radius; |
886 | Property<LogicalLength> border_top_left_radius; |
887 | Property<LogicalLength> border_top_right_radius; |
888 | Property<LogicalLength> border_bottom_left_radius; |
889 | Property<LogicalLength> border_bottom_right_radius; |
890 | Property<Brush> border_color; |
891 | CachedRenderingData cached_rendering_data; |
892 | }; |
893 | |
894 | /// The implementation of the `Image` element |
895 | struct ImageItem { |
896 | Property<Image> source; |
897 | Property<LogicalLength> width; |
898 | Property<LogicalLength> height; |
899 | Property<ImageFit> image_fit; |
900 | Property<ImageRendering> image_rendering; |
901 | Property<Brush> colorize; |
902 | CachedRenderingData cached_rendering_data; |
903 | }; |
904 | |
905 | /// The implementation of the `ClippedImage` element |
906 | struct ClippedImage { |
907 | Property<Image> source; |
908 | Property<LogicalLength> width; |
909 | Property<LogicalLength> height; |
910 | Property<ImageFit> image_fit; |
911 | Property<ImageRendering> image_rendering; |
912 | Property<Brush> colorize; |
913 | Property<int32_t> source_clip_x; |
914 | Property<int32_t> source_clip_y; |
915 | Property<int32_t> source_clip_width; |
916 | Property<int32_t> source_clip_height; |
917 | Property<ImageHorizontalAlignment> horizontal_alignment; |
918 | Property<ImageVerticalAlignment> vertical_alignment; |
919 | Property<ImageTiling> horizontal_tiling; |
920 | Property<ImageTiling> vertical_tiling; |
921 | CachedRenderingData cached_rendering_data; |
922 | }; |
923 | |
924 | /// The implementation of the `TouchArea` element |
925 | struct TouchArea { |
926 | Property<bool> enabled; |
927 | /// FIXME: We should annotate this as an "output" property. |
928 | Property<bool> pressed; |
929 | Property<bool> has_hover; |
930 | /// FIXME: there should be just one property for the point instead of two. |
931 | /// Could even be merged with pressed in a `Property<Option<Point>>` (of course, in the |
932 | /// implementation item only, for the compiler it would stay separate properties) |
933 | Property<LogicalLength> pressed_x; |
934 | Property<LogicalLength> pressed_y; |
935 | /// FIXME: should maybe be as parameter to the mouse event instead. Or at least just one property |
936 | Property<LogicalLength> mouse_x; |
937 | Property<LogicalLength> mouse_y; |
938 | Property<MouseCursor> mouse_cursor; |
939 | private_api::CallbackHelper<void> clicked; |
940 | private_api::CallbackHelper<void> double_clicked; |
941 | private_api::CallbackHelper<void> moved; |
942 | private_api::CallbackHelper<PointerEvent> pointer_event; |
943 | private_api::CallbackHelper<PointerScrollEvent, EventResult> scroll_event; |
944 | /// FIXME: remove this |
945 | CachedRenderingData cached_rendering_data; |
946 | /// true when we are currently grabbing the mouse |
947 | bool grabbed; |
948 | }; |
949 | |
950 | /// A runtime item that exposes key |
951 | struct FocusScope { |
952 | Property<bool> enabled; |
953 | Property<bool> has_focus; |
954 | private_api::CallbackHelper<KeyEvent, EventResult> key_pressed; |
955 | private_api::CallbackHelper<KeyEvent, EventResult> key_released; |
956 | private_api::CallbackHelper<void> focus_changed_event; |
957 | /// FIXME: remove this |
958 | CachedRenderingData cached_rendering_data; |
959 | }; |
960 | |
961 | /// The implementation of the `Flickable` element |
962 | struct Flickable { |
963 | Property<LogicalLength> viewport_x; |
964 | Property<LogicalLength> viewport_y; |
965 | Property<LogicalLength> viewport_width; |
966 | Property<LogicalLength> viewport_height; |
967 | Property<bool> interactive; |
968 | private_api::CallbackHelper<void> flicked; |
969 | FlickableDataBox data; |
970 | /// FIXME: remove this |
971 | CachedRenderingData cached_rendering_data; |
972 | inline Flickable(); inline ~Flickable(); |
973 | }; |
974 | |
975 | /// The implementation of the `Text` element |
976 | struct Text { |
977 | Property<SharedString> text; |
978 | Property<SharedString> font_family; |
979 | Property<LogicalLength> font_size; |
980 | Property<int32_t> font_weight; |
981 | Property<bool> font_italic; |
982 | Property<Brush> color; |
983 | Property<TextHorizontalAlignment> horizontal_alignment; |
984 | Property<TextVerticalAlignment> vertical_alignment; |
985 | Property<TextWrap> wrap; |
986 | Property<TextOverflow> overflow; |
987 | Property<LogicalLength> letter_spacing; |
988 | Property<LogicalLength> width; |
989 | Property<LogicalLength> height; |
990 | CachedRenderingData cached_rendering_data; |
991 | }; |
992 | |
993 | /// The implementation of the `Path` element |
994 | struct Path { |
995 | Property<PathData> elements; |
996 | Property<Brush> fill; |
997 | Property<FillRule> fill_rule; |
998 | Property<Brush> stroke; |
999 | Property<LogicalLength> stroke_width; |
1000 | Property<float> viewbox_x; |
1001 | Property<float> viewbox_y; |
1002 | Property<float> viewbox_width; |
1003 | Property<float> viewbox_height; |
1004 | Property<bool> clip; |
1005 | CachedRenderingData cached_rendering_data; |
1006 | }; |
1007 | |
1008 | /// The implementation of the `Window` element |
1009 | struct WindowItem { |
1010 | Property<LogicalLength> width; |
1011 | Property<LogicalLength> height; |
1012 | Property<Brush> background; |
1013 | Property<SharedString> title; |
1014 | Property<bool> no_frame; |
1015 | Property<bool> always_on_top; |
1016 | Property<Image> icon; |
1017 | Property<SharedString> default_font_family; |
1018 | Property<LogicalLength> default_font_size; |
1019 | Property<int32_t> default_font_weight; |
1020 | CachedRenderingData cached_rendering_data; |
1021 | }; |
1022 | |
1023 | /// The implementation of the `Clip` element |
1024 | struct Clip { |
1025 | Property<LogicalLength> border_top_left_radius; |
1026 | Property<LogicalLength> border_top_right_radius; |
1027 | Property<LogicalLength> border_bottom_left_radius; |
1028 | Property<LogicalLength> border_bottom_right_radius; |
1029 | Property<LogicalLength> border_width; |
1030 | CachedRenderingData cached_rendering_data; |
1031 | Property<bool> clip; |
1032 | }; |
1033 | |
1034 | /// The implementation of the `BoxShadow` element |
1035 | struct BoxShadow { |
1036 | Property<LogicalLength> border_radius; |
1037 | Property<LogicalLength> offset_x; |
1038 | Property<LogicalLength> offset_y; |
1039 | Property<Color> color; |
1040 | Property<LogicalLength> blur; |
1041 | CachedRenderingData cached_rendering_data; |
1042 | }; |
1043 | |
1044 | /// The implementation of the `Rotate` element |
1045 | struct Rotate { |
1046 | Property<float> rotation_angle; |
1047 | Property<LogicalLength> rotation_origin_x; |
1048 | Property<LogicalLength> rotation_origin_y; |
1049 | CachedRenderingData cached_rendering_data; |
1050 | }; |
1051 | |
1052 | /// The Opacity Item is not meant to be used directly by the .slint code, instead, the `opacity: xxx` or `visible: false` should be used |
1053 | struct Opacity { |
1054 | Property<float> opacity; |
1055 | CachedRenderingData cached_rendering_data; |
1056 | }; |
1057 | |
1058 | /// The Layer Item is not meant to be used directly by the .slint code, instead, the `layer: xxx` property should be used |
1059 | struct Layer { |
1060 | Property<bool> cache_rendering_hint; |
1061 | CachedRenderingData cached_rendering_data; |
1062 | }; |
1063 | |
1064 | extern "C" { |
1065 | |
1066 | /// Initialize the callback. |
1067 | /// slint_callback_drop must be called. |
1068 | void slint_callback_init(CallbackOpaque *out); |
1069 | |
1070 | /// Emit the callback |
1071 | void slint_callback_call(const CallbackOpaque *sig, const void *arg, void *ret); |
1072 | |
1073 | /// Set callback handler. |
1074 | /// |
1075 | /// The binding has signature fn(user_data) |
1076 | void slint_callback_set_handler(const CallbackOpaque *sig, |
1077 | void (*binding)(void *user_data, const void *arg, void *ret), |
1078 | void *user_data, |
1079 | void (*drop_user_data)(void*)); |
1080 | |
1081 | /// Destroy callback |
1082 | void slint_callback_drop(CallbackOpaque *handle); |
1083 | |
1084 | /// Call init() on the ItemVTable of each item in the item array. |
1085 | void slint_register_item_tree(const ItemTreeRc *item_tree_rc, |
1086 | const WindowAdapterRcOpaque *window_handle); |
1087 | |
1088 | /// Free the backend graphics resources allocated in the item array. |
1089 | void slint_unregister_item_tree(ItemTreeRefPin component, |
1090 | Slice<VOffset<uint8_t, ItemVTable, AllowPin>> item_array, |
1091 | const WindowAdapterRcOpaque *window_handle); |
1092 | |
1093 | /// Expose `crate::item_tree::visit_item_tree` to C++ |
1094 | /// |
1095 | /// Safety: Assume a correct implementation of the item_tree array |
1096 | VisitChildrenResult slint_visit_item_tree(const ItemTreeRc *item_tree, |
1097 | Slice<ItemTreeNode> item_tree_array, |
1098 | intptr_t index, |
1099 | TraversalOrder order, |
1100 | VRefMut<ItemVisitorVTable> visitor, |
1101 | VisitChildrenResult (*visit_dynamic)(const void *base, |
1102 | TraversalOrder order, |
1103 | VRefMut<ItemVisitorVTable> visitor, |
1104 | uint32_t dyn_index)); |
1105 | |
1106 | LogicalPoint slint_item_absolute_position(const VRc<ItemTreeVTable> *self_component, |
1107 | uint32_t self_index); |
1108 | |
1109 | /// # Safety |
1110 | /// This must be called using a non-null pointer pointing to a chunk of memory big enough to |
1111 | /// hold a FlickableDataBox |
1112 | void slint_flickable_data_init(FlickableDataBox *data); |
1113 | |
1114 | /// # Safety |
1115 | /// This must be called using a non-null pointer pointing to an initialized FlickableDataBox |
1116 | void slint_flickable_data_free(FlickableDataBox *data); |
1117 | |
1118 | void slint_textinput_set_selection_offsets(Pin<const TextInput*> text_input, |
1119 | const WindowAdapterRcOpaque *window_adapter, |
1120 | const VRc<ItemTreeVTable> *self_component, |
1121 | uint32_t self_index, |
1122 | int32_t start, |
1123 | int32_t end); |
1124 | |
1125 | void slint_textinput_select_all(Pin<const TextInput*> text_input, |
1126 | const WindowAdapterRcOpaque *window_adapter, |
1127 | const VRc<ItemTreeVTable> *self_component, |
1128 | uint32_t self_index); |
1129 | |
1130 | void slint_textinput_clear_selection(Pin<const TextInput*> text_input, |
1131 | const WindowAdapterRcOpaque *window_adapter, |
1132 | const VRc<ItemTreeVTable> *self_component, |
1133 | uint32_t self_index); |
1134 | |
1135 | void slint_textinput_cut(Pin<const TextInput*> text_input, |
1136 | const WindowAdapterRcOpaque *window_adapter, |
1137 | const VRc<ItemTreeVTable> *self_component, |
1138 | uint32_t self_index); |
1139 | |
1140 | void slint_textinput_copy(Pin<const TextInput*> text_input, |
1141 | const WindowAdapterRcOpaque *window_adapter, |
1142 | const VRc<ItemTreeVTable> *self_component, |
1143 | uint32_t self_index); |
1144 | |
1145 | void slint_textinput_paste(Pin<const TextInput*> text_input, |
1146 | const WindowAdapterRcOpaque *window_adapter, |
1147 | const VRc<ItemTreeVTable> *self_component, |
1148 | uint32_t self_index); |
1149 | |
1150 | void slint_solve_grid_layout(const GridLayoutData *data, SharedVector<float> *result); |
1151 | |
1152 | LayoutInfo slint_grid_layout_info(Slice<GridLayoutCellData> cells, |
1153 | float spacing, |
1154 | const Padding *padding); |
1155 | |
1156 | void slint_solve_box_layout(const BoxLayoutData *data, |
1157 | Slice<uint32_t> repeater_indexes, |
1158 | SharedVector<float> *result); |
1159 | |
1160 | /// Return the LayoutInfo for a BoxLayout with the given cells. |
1161 | LayoutInfo slint_box_layout_info(Slice<BoxLayoutCellData> cells, |
1162 | float spacing, |
1163 | const Padding *padding, |
1164 | LayoutAlignment alignment); |
1165 | |
1166 | /// Return the LayoutInfo for a BoxLayout with the given cells. |
1167 | LayoutInfo slint_box_layout_info_ortho(Slice<BoxLayoutCellData> cells, const Padding *padding); |
1168 | |
1169 | /// Calls [`reorder_dialog_button_layout`]. |
1170 | /// |
1171 | /// Safety: `cells` must be a pointer to a mutable array of cell data, the array must have at |
1172 | /// least `roles.len()` elements. |
1173 | void slint_reorder_dialog_button_layout(GridLayoutCellData *cells, Slice<DialogButtonRole> roles); |
1174 | |
1175 | /// Initialize the first pointer of the Property. Does not initialize the content. |
1176 | /// `out` is assumed to be uninitialized |
1177 | void slint_property_init(PropertyHandleOpaque *out); |
1178 | |
1179 | /// To be called before accessing the value |
1180 | void slint_property_update(const PropertyHandleOpaque *handle, void *val); |
1181 | |
1182 | /// Mark the fact that the property was changed and that its binding need to be removed, and |
1183 | /// the dependencies marked dirty. |
1184 | /// To be called after the `value` has been changed |
1185 | void slint_property_set_changed(const PropertyHandleOpaque *handle, const void *value); |
1186 | |
1187 | /// Set a binding |
1188 | /// |
1189 | /// The current implementation will do usually two memory allocation: |
1190 | /// 1. the allocation from the calling code to allocate user_data |
1191 | /// 2. the box allocation within this binding |
1192 | /// It might be possible to reduce that by passing something with a |
1193 | /// vtable, so there is the need for less memory allocation. |
1194 | void slint_property_set_binding(const PropertyHandleOpaque *handle, |
1195 | void (*binding)(void *user_data, void *pointer_to_value), |
1196 | void *user_data, |
1197 | void (*drop_user_data)(void*), |
1198 | bool (*intercept_set)(void *user_data, const void *pointer_to_Value), |
1199 | bool (*intercept_set_binding)(void *user_data, void *new_binding)); |
1200 | |
1201 | /// Set a binding using an already allocated building holder |
1202 | /// |
1203 | void slint_property_set_binding_internal(const PropertyHandleOpaque *handle, void *binding); |
1204 | |
1205 | /// Returns whether the property behind this handle is marked as dirty |
1206 | bool slint_property_is_dirty(const PropertyHandleOpaque *handle); |
1207 | |
1208 | /// Marks the property as dirty and notifies dependencies. |
1209 | void slint_property_mark_dirty(const PropertyHandleOpaque *handle); |
1210 | |
1211 | /// Destroy handle |
1212 | void slint_property_drop(PropertyHandleOpaque *handle); |
1213 | |
1214 | /// Internal function to set up a property animation to the specified target value for an integer property. |
1215 | void slint_property_set_animated_value_int(const PropertyHandleOpaque *handle, |
1216 | int32_t from, |
1217 | int32_t to, |
1218 | const PropertyAnimation *animation_data); |
1219 | |
1220 | /// Internal function to set up a property animation to the specified target value for a float property. |
1221 | void slint_property_set_animated_value_float(const PropertyHandleOpaque *handle, |
1222 | float from, |
1223 | float to, |
1224 | const PropertyAnimation *animation_data); |
1225 | |
1226 | /// Internal function to set up a property animation to the specified target value for a color property. |
1227 | void slint_property_set_animated_value_color(const PropertyHandleOpaque *handle, |
1228 | Color from, |
1229 | Color to, |
1230 | const PropertyAnimation *animation_data); |
1231 | |
1232 | /// Internal function to set up a property animation between values produced by the specified binding for an integer property. |
1233 | void slint_property_set_animated_binding_int(const PropertyHandleOpaque *handle, |
1234 | void (*binding)(void*, int*), |
1235 | void *user_data, |
1236 | void (*drop_user_data)(void*), |
1237 | const PropertyAnimation *animation_data, |
1238 | PropertyAnimation (*transition_data)(void *user_data, |
1239 | uint64_t *start_instant)); |
1240 | |
1241 | /// Internal function to set up a property animation between values produced by the specified binding for a float property. |
1242 | void slint_property_set_animated_binding_float(const PropertyHandleOpaque *handle, |
1243 | void (*binding)(void*, float*), |
1244 | void *user_data, |
1245 | void (*drop_user_data)(void*), |
1246 | const PropertyAnimation *animation_data, |
1247 | PropertyAnimation (*transition_data)(void *user_data, |
1248 | uint64_t *start_instant)); |
1249 | |
1250 | /// Internal function to set up a property animation between values produced by the specified binding for a color property. |
1251 | void slint_property_set_animated_binding_color(const PropertyHandleOpaque *handle, |
1252 | void (*binding)(void*, Color*), |
1253 | void *user_data, |
1254 | void (*drop_user_data)(void*), |
1255 | const PropertyAnimation *animation_data, |
1256 | PropertyAnimation (*transition_data)(void *user_data, |
1257 | uint64_t *start_instant)); |
1258 | |
1259 | /// Internal function to set up a property animation between values produced by the specified binding for a brush property. |
1260 | void slint_property_set_animated_binding_brush(const PropertyHandleOpaque *handle, |
1261 | void (*binding)(void*, Brush*), |
1262 | void *user_data, |
1263 | void (*drop_user_data)(void*), |
1264 | const PropertyAnimation *animation_data, |
1265 | PropertyAnimation (*transition_data)(void *user_data, |
1266 | uint64_t *start_instant)); |
1267 | |
1268 | /// Internal function to set up a state binding on a Property<StateInfo>. |
1269 | void slint_property_set_state_binding(const PropertyHandleOpaque *handle, |
1270 | int32_t (*binding)(void*), |
1271 | void *user_data, |
1272 | void (*drop_user_data)(void*)); |
1273 | |
1274 | /// Initialize the first pointer of the PropertyTracker. |
1275 | /// `out` is assumed to be uninitialized |
1276 | /// slint_property_tracker_drop need to be called after that |
1277 | void slint_property_tracker_init(PropertyTrackerOpaque *out); |
1278 | |
1279 | /// Call the callback with the user data. Any properties access within the callback will be registered. |
1280 | /// Any currently evaluated bindings or property trackers will be notified if accessed properties are changed. |
1281 | void slint_property_tracker_evaluate(const PropertyTrackerOpaque *handle, |
1282 | void (*callback)(void *user_data), |
1283 | void *user_data); |
1284 | |
1285 | /// Call the callback with the user data. Any properties access within the callback will be registered. |
1286 | /// Any currently evaluated bindings or property trackers will be not notified if accessed properties are changed. |
1287 | void slint_property_tracker_evaluate_as_dependency_root(const PropertyTrackerOpaque *handle, |
1288 | void (*callback)(void *user_data), |
1289 | void *user_data); |
1290 | |
1291 | /// Query if the property tracker is dirty |
1292 | bool slint_property_tracker_is_dirty(const PropertyTrackerOpaque *handle); |
1293 | |
1294 | /// Destroy handle |
1295 | void slint_property_tracker_drop(PropertyTrackerOpaque *handle); |
1296 | |
1297 | /// return the current animation tick for the `animation-tick` function |
1298 | uint64_t slint_animation_tick(); |
1299 | |
1300 | /// This function is used for the low-level C++ interface to allocate the backing vector of a SharedVector. |
1301 | uint8_t *slint_shared_vector_allocate(uintptr_t size, |
1302 | uintptr_t align); |
1303 | |
1304 | /// This function is used for the low-level C++ interface to deallocate the backing vector of a SharedVector |
1305 | void slint_shared_vector_free(uint8_t *ptr, |
1306 | uintptr_t size, |
1307 | uintptr_t align); |
1308 | |
1309 | /// This function is used for the low-level C++ interface to initialize the empty SharedVector. |
1310 | const uint8_t *slint_shared_vector_empty(); |
1311 | |
1312 | /// Returns a nul-terminated pointer for this string. |
1313 | /// The returned value is owned by the string, and should not be used after any |
1314 | /// mutable function have been called on the string, and must not be freed. |
1315 | const char *slint_shared_string_bytes(const SharedString *ss); |
1316 | |
1317 | /// Destroy the shared string |
1318 | void slint_shared_string_drop(const SharedString *ss); |
1319 | |
1320 | /// Increment the reference count of the string. |
1321 | /// The resulting structure must be passed to slint_shared_string_drop |
1322 | void slint_shared_string_clone(SharedString *out, const SharedString *ss); |
1323 | |
1324 | /// Safety: bytes must be a valid utf-8 string of size len without null inside. |
1325 | /// The resulting structure must be passed to slint_shared_string_drop |
1326 | void slint_shared_string_from_bytes(SharedString *out, const char *bytes, uintptr_t len); |
1327 | |
1328 | /// Create a string from a number. |
1329 | /// The resulting structure must be passed to slint_shared_string_drop |
1330 | void slint_shared_string_from_number(SharedString *out, double n); |
1331 | |
1332 | /// Append some bytes to an existing shared string |
1333 | /// |
1334 | /// bytes must be a valid utf8 array of size `len`, without null bytes inside |
1335 | void slint_shared_string_append(SharedString *self_, const char *bytes, uintptr_t len); |
1336 | |
1337 | /// Slint animations do not use real time, but use a mocked time. |
1338 | /// Normally, the event loop update the time of the animation using |
1339 | /// real time, but in tests, it is more convenient to use the fake time. |
1340 | /// This function will add some milliseconds to the fake time |
1341 | void slint_mock_elapsed_time(uint64_t time_in_ms); |
1342 | |
1343 | /// Return the current mocked time. |
1344 | uint64_t slint_get_mocked_time(); |
1345 | |
1346 | /// Simulate a click on a position within the component. |
1347 | void slint_send_mouse_click(float x, float y, const WindowAdapterRc *window_adapter); |
1348 | |
1349 | /// Simulate a character input event (pressed or released). |
1350 | void slint_send_keyboard_char(const SharedString *string, |
1351 | bool pressed, |
1352 | const WindowAdapterRc *window_adapter); |
1353 | |
1354 | /// Simulate a character input event. |
1355 | void send_keyboard_string_sequence(const SharedString *sequence, |
1356 | const WindowAdapterRc *window_adapter); |
1357 | |
1358 | /// Returns a nul-terminated pointer for this string. |
1359 | /// The returned value is owned by the string, and should not be used after any |
1360 | /// mutable function have been called on the string, and must not be freed. |
1361 | void slint_translate(SharedString *to_translate, |
1362 | const SharedString *context, |
1363 | const SharedString *domain, |
1364 | Slice<SharedString> arguments, |
1365 | int32_t n, |
1366 | const SharedString *plural); |
1367 | |
1368 | /// Releases the reference to the windowrc held by handle. |
1369 | void slint_windowrc_drop(WindowAdapterRcOpaque *handle); |
1370 | |
1371 | /// Releases the reference to the component window held by handle. |
1372 | void slint_windowrc_clone(const WindowAdapterRcOpaque *source, WindowAdapterRcOpaque *target); |
1373 | |
1374 | /// Spins an event loop and renders the items of the provided component in this window. |
1375 | void slint_windowrc_show(const WindowAdapterRcOpaque *handle); |
1376 | |
1377 | /// Spins an event loop and renders the items of the provided component in this window. |
1378 | void slint_windowrc_hide(const WindowAdapterRcOpaque *handle); |
1379 | |
1380 | /// Returns the visibility state of the window. This function can return false even if you previously called show() |
1381 | /// on it, for example if the user minimized the window. |
1382 | bool slint_windowrc_is_visible(const WindowAdapterRcOpaque *handle); |
1383 | |
1384 | /// Returns the window scale factor. |
1385 | float slint_windowrc_get_scale_factor(const WindowAdapterRcOpaque *handle); |
1386 | |
1387 | /// Sets the window scale factor, merely for testing purposes. |
1388 | void slint_windowrc_set_scale_factor(const WindowAdapterRcOpaque *handle, float value); |
1389 | |
1390 | /// Returns the text-input-focused property value. |
1391 | bool slint_windowrc_get_text_input_focused(const WindowAdapterRcOpaque *handle); |
1392 | |
1393 | /// Set the text-input-focused property. |
1394 | void slint_windowrc_set_text_input_focused(const WindowAdapterRcOpaque *handle, bool value); |
1395 | |
1396 | /// Sets the focus item. |
1397 | void slint_windowrc_set_focus_item(const WindowAdapterRcOpaque *handle, const ItemRc *focus_item); |
1398 | |
1399 | /// Associates the window with the given component. |
1400 | void slint_windowrc_set_component(const WindowAdapterRcOpaque *handle, const ItemTreeRc *component); |
1401 | |
1402 | /// Show a popup. |
1403 | void (const WindowAdapterRcOpaque *handle, |
1404 | const ItemTreeRc *, |
1405 | Point position, |
1406 | bool close_on_click, |
1407 | const ItemRc *parent_item); |
1408 | |
1409 | /// Close the current popup |
1410 | void (const WindowAdapterRcOpaque *handle); |
1411 | |
1412 | /// C binding to the set_rendering_notifier() API of Window |
1413 | bool slint_windowrc_set_rendering_notifier(const WindowAdapterRcOpaque *handle, |
1414 | void (*callback)(RenderingState rendering_state, |
1415 | GraphicsAPI graphics_api, |
1416 | void *user_data), |
1417 | void (*drop_user_data)(void *user_data), |
1418 | void *user_data, |
1419 | SetRenderingNotifierError *error); |
1420 | |
1421 | /// C binding to the on_close_requested() API of Window |
1422 | void slint_windowrc_on_close_requested(const WindowAdapterRcOpaque *handle, |
1423 | CloseRequestResponse (*callback)(void *user_data), |
1424 | void (*drop_user_data)(void *user_data), |
1425 | void *user_data); |
1426 | |
1427 | /// This function issues a request to the windowing system to redraw the contents of the window. |
1428 | void slint_windowrc_request_redraw(const WindowAdapterRcOpaque *handle); |
1429 | |
1430 | /// Returns the position of the window on the screen, in physical screen coordinates and including |
1431 | /// a window frame (if present). |
1432 | void slint_windowrc_position(const WindowAdapterRcOpaque *handle, Point2D<int32_t> *pos); |
1433 | |
1434 | /// Sets the position of the window on the screen, in physical screen coordinates and including |
1435 | /// a window frame (if present). |
1436 | /// Note that on some windowing systems, such as Wayland, this functionality is not available. |
1437 | void slint_windowrc_set_physical_position(const WindowAdapterRcOpaque *handle, |
1438 | const Point2D<int32_t> *pos); |
1439 | |
1440 | /// Sets the position of the window on the screen, in physical screen coordinates and including |
1441 | /// a window frame (if present). |
1442 | /// Note that on some windowing systems, such as Wayland, this functionality is not available. |
1443 | void slint_windowrc_set_logical_position(const WindowAdapterRcOpaque *handle, |
1444 | const Point2D<float> *pos); |
1445 | |
1446 | /// Returns the size of the window on the screen, in physical screen coordinates and excluding |
1447 | /// a window frame (if present). |
1448 | IntSize slint_windowrc_size(const WindowAdapterRcOpaque *handle); |
1449 | |
1450 | /// Resizes the window to the specified size on the screen, in physical pixels and excluding |
1451 | /// a window frame (if present). |
1452 | void slint_windowrc_set_physical_size(const WindowAdapterRcOpaque *handle, const IntSize *size); |
1453 | |
1454 | /// Resizes the window to the specified size on the screen, in physical pixels and excluding |
1455 | /// a window frame (if present). |
1456 | void slint_windowrc_set_logical_size(const WindowAdapterRcOpaque *handle, const Size *size); |
1457 | |
1458 | /// Return wether the style is using a dark theme |
1459 | bool slint_windowrc_dark_color_scheme(const WindowAdapterRcOpaque *handle); |
1460 | |
1461 | /// Dispatch a key pressed or release event |
1462 | void slint_windowrc_dispatch_key_event(const WindowAdapterRcOpaque *handle, |
1463 | KeyEventType event_type, |
1464 | const SharedString *text, |
1465 | bool repeat); |
1466 | |
1467 | /// Dispatch a mouse event |
1468 | void slint_windowrc_dispatch_pointer_event(const WindowAdapterRcOpaque *handle, MouseEvent event); |
1469 | |
1470 | /// Dispatch a window event |
1471 | void slint_windowrc_dispatch_event(const WindowAdapterRcOpaque *handle, const WindowEvent *event); |
1472 | |
1473 | bool slint_windowrc_is_fullscreen(const WindowAdapterRcOpaque *handle); |
1474 | |
1475 | bool slint_windowrc_is_minimized(const WindowAdapterRcOpaque *handle); |
1476 | |
1477 | bool slint_windowrc_is_maximized(const WindowAdapterRcOpaque *handle); |
1478 | |
1479 | void slint_windowrc_set_fullscreen(const WindowAdapterRcOpaque *handle, bool value); |
1480 | |
1481 | void slint_windowrc_set_minimized(const WindowAdapterRcOpaque *handle, bool value); |
1482 | |
1483 | void slint_windowrc_set_maximized(const WindowAdapterRcOpaque *handle, bool value); |
1484 | |
1485 | } // extern "C" |
1486 | |
1487 | } // namespace cbindgen_private |
1488 | } // namespace slint |
1489 | |
1490 | |
1491 | namespace slint::private_api { |
1492 | #define SLINT_DECL_ITEM(ItemName) \ |
1493 | extern const cbindgen_private::ItemVTable ItemName##VTable; \ |
1494 | extern SLINT_DLL_IMPORT const cbindgen_private::ItemVTable* slint_get_##ItemName##VTable(); |
1495 | |
1496 | extern "C" { |
1497 | SLINT_DECL_ITEM(Empty); |
1498 | SLINT_DECL_ITEM(Rectangle); |
1499 | SLINT_DECL_ITEM(BasicBorderRectangle); |
1500 | SLINT_DECL_ITEM(BorderRectangle); |
1501 | SLINT_DECL_ITEM(ImageItem); |
1502 | SLINT_DECL_ITEM(ClippedImage); |
1503 | SLINT_DECL_ITEM(TouchArea); |
1504 | SLINT_DECL_ITEM(FocusScope); |
1505 | SLINT_DECL_ITEM(Flickable); |
1506 | SLINT_DECL_ITEM(Text); |
1507 | SLINT_DECL_ITEM(Path); |
1508 | SLINT_DECL_ITEM(WindowItem); |
1509 | SLINT_DECL_ITEM(TextInput); |
1510 | SLINT_DECL_ITEM(Clip); |
1511 | SLINT_DECL_ITEM(BoxShadow); |
1512 | SLINT_DECL_ITEM(Rotate); |
1513 | SLINT_DECL_ITEM(Opacity); |
1514 | SLINT_DECL_ITEM(Layer); |
1515 | } |
1516 | |
1517 | #undef SLINT_DECL_ITEM |
1518 | } |
1519 | |