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

source code of slint/target/debug/build/slint-cpp-f9a20ca53236b43d/out/generated_include/slint_internal.h