Files
qbz/crates/vendor/i-slint-common-1.16.1/builtin_structs.rs
T
vicrodh fa3ee1e410 fix(fonts): pre-register macOS CJK fallback families in vendored i-slint-common
fontique's CoreText-based Han-script fallback fails to resolve a family on
modern macOS (the suggested PingFang is not always in the scanned family
map), so Japanese kanji rendered blank while kana worked. Vendor
i-slint-common 1.16.1 and pre-register Hiragino / PingFang / Apple SD
Gothic Neo / Arial Unicode MS in the fallback map at collection creation
(Japanese-biased default; the map takes priority over the CoreText query).
macOS-only cfg; Linux keeps its working fontconfig fallback. Type-checked
against aarch64-apple-darwin.

cc
2026-07-03 10:00:31 -06:00

221 lines
9.3 KiB
Rust

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
//! This module contains all builtin structures exposed in the .slint language.
/// Call a macro with every builtin structures exposed in the .slint language
///
/// ## Example
/// ```rust
/// macro_rules! print_builtin_structs {
/// ($(
/// $(#[$struct_attr:meta])*
/// struct $Name:ident {
/// @name = $inner_name:expr,
/// export {
/// $( $(#[$pub_attr:meta])* $pub_field:ident : $pub_type:ty, )*
/// }
/// private {
/// $( $(#[$pri_attr:meta])* $pri_field:ident : $pri_type:ty, )*
/// }
/// }
/// )*) => {
/// $(println!("{} => export:[{}] private:[{}]", stringify!($Name), stringify!($($pub_field),*), stringify!($($pri_field),*));)*
/// };
/// }
/// i_slint_common::for_each_builtin_structs!(print_builtin_structs);
/// ```
#[macro_export]
macro_rules! for_each_builtin_structs {
($macro:ident) => {
$macro![
/// The `KeyboardModifiers` struct provides booleans to indicate possible modifier keys on a keyboard, such as Shift, Control, etc.
/// It is provided as part of `KeyEvent`'s `modifiers` field.
///
/// Keyboard shortcuts on Apple platforms typically use the Command key (⌘), such as Command+C for "Copy". On other platforms
/// the same shortcut is typically represented using Control+C. To make it easier to develop cross-platform applications, on macOS,
/// Slint maps the Command key to the control modifier, and the Control key to the meta modifier.
///
/// On Windows, the Windows key is mapped to the meta modifier.
#[non_exhaustive]
#[derive(Copy, Eq)]
struct KeyboardModifiers {
@name = BuiltinPublicStruct::KeyboardModifiers,
export {
/// Indicates the Alt key on a keyboard.
alt: bool,
/// Indicates the Control key on a keyboard, except on macOS, where it is the Command key (⌘).
control: bool,
/// Indicates the Shift key on a keyboard.
shift: bool,
/// Indicates the Control key on macos, and the Windows key on Windows.
meta: bool,
}
private {
}
}
/// Represents a Pointer event sent by the windowing system.
/// This structure is passed to the `pointer-event` callback of the `TouchArea` element.
struct PointerEvent {
@name = BuiltinPrivateStruct::PointerEvent,
export {
/// The button that was pressed or released
button: PointerEventButton,
/// The kind of the event
kind: PointerEventKind,
/// The keyboard modifiers pressed during the event
modifiers: KeyboardModifiers,
}
private {
/// The flag indicating whether the event was generated by a touch input
is_touch: bool,
}
}
/// Represents a Pointer scroll (or wheel) event sent by the windowing system.
/// This structure is passed to the `scroll-event` callback of the `TouchArea` element.
struct PointerScrollEvent {
@name = BuiltinPrivateStruct::PointerScrollEvent,
export {
/// The amount of pixel in the horizontal direction
delta_x: Coord,
/// The amount of pixel in the vertical direction
delta_y: Coord,
/// The keyboard modifiers pressed during the event
modifiers: KeyboardModifiers,
}
private {
}
}
/// This structure is generated and passed to the key press and release callbacks of the `FocusScope` element.
#[non_exhaustive]
struct KeyEvent {
@name = BuiltinPublicStruct::KeyEvent,
export {
/// The unicode representation of the key pressed.
text: SharedString,
/// The keyboard modifiers active at the time of the key press event.
modifiers: KeyboardModifiers,
/// This field is set to true for key press events that are repeated,
/// i.e. the key is held down. It's always false for key release events.
repeat: bool,
}
private {
}
}
/// This structure is passed to the callbacks of the `DropArea` element
struct DropEvent {
@name = BuiltinPrivateStruct::DropEvent,
export {
/// The mime type of the data being dragged
mime_type: SharedString,
/// The data being dragged
data: SharedString,
/// The current mouse position in coordinates of the `DropArea` element
position: LogicalPosition,
}
private {
}
}
/// Represents an item in a StandardListView and a StandardTableView.
#[non_exhaustive]
struct StandardListViewItem {
@name = BuiltinPublicStruct::StandardListViewItem,
export {
/// The text content of the item
text: SharedString,
}
private {
}
}
/// This is used to define the column and the column header of a TableView
#[non_exhaustive]
struct TableColumn {
@name = BuiltinPrivateStruct::TableColumn,
export {
/// The title of the column header
title: SharedString,
/// The minimum column width (logical length)
min_width: Coord,
/// The horizontal column stretch
horizontal_stretch: f32,
/// Sorts the column
sort_order: SortOrder,
/// the actual width of the column (logical length)
width: Coord,
}
private {
}
}
/// A structure to hold metrics of a font for a specified pixel size.
struct FontMetrics {
@name = BuiltinPrivateStruct::FontMetrics,
export {
/// The distance between the baseline and the top of the tallest glyph in the font.
ascent: Coord,
/// The distance between the baseline and the bottom of the tallest glyph in the font.
/// This is usually negative.
descent: Coord,
/// The distance between the baseline and the horizontal midpoint of the tallest glyph in the font,
/// or zero if not specified by the font.
x_height: Coord,
/// The distance between the baseline and the top of a regular upper-case glyph in the font,
/// or zero if not specified by the font.
cap_height: Coord,
}
private {
}
}
/// An item in the menu of a menu bar or context menu
struct MenuEntry {
@name = BuiltinPrivateStruct::MenuEntry,
export {
/// The text of the menu entry
title: SharedString,
/// the icon associated with the menu entry
icon: Image,
/// an opaque id that can be used to identify the menu entry
id: SharedString,
// keys: KeySequence,
/// whether the menu entry is enabled
enabled: bool,
/// whether the menu entry is checkable
checkable: bool,
/// whether the menu entry is checked
checked: bool,
/// Sub menu
has_sub_menu: bool,
/// The menu entry is a separator
is_separator: bool,
/// The shortcut keys
shortcut: Keys,
}
private {}
}
/// A structure representing the four edges of an axis-aligned rectangle
struct Edges {
@name = BuiltinPrivateStruct::Edges,
export {
/// The left edge value
left: Coord,
/// The top edge value
top: Coord,
/// The right edge value
right: Coord,
/// The bottom edge value
bottom: Coord,
}
private {}
}
];
};
}