slint/internal/compiler/builtins.slint
Simon Hausmann 39121994ca Always set Window.default-font-size
Permit the style metrics to provide a `default-font-size` and bind that
to the `Window` if set. If not provided, then the backend can set a
`default-font-size`. By ensuring that the value is non-zero at run-time,
we can later introduce a rem unit that can act as factor relative to
this non-zero font size.
2022-11-03 17:15:44 +01:00

633 lines
19 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
// cSpell: ignore langtype typeregister
/**
This file contains the definition off all builtin items
It is parsed with the normal .slint parser, but the semantic.
`_` means that that this is a langtype::NativeClass with no parent.
Exported components are added to the as BuiltinElement.
comments starting by `//-` have some meanings
Properties with two way bindings (aliases) are deprecated in favor of the property they point to
Properties can have default binding which must be an expression without any reference to
another properties. These binding will be then set by the compiler.
`output` property mean that the property can be modified by the native Item,
otherwise it is assumed the native item don't write to that property.
*/
import { _ } from ""; // just to silence many errors in the LSP
Empty := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
Rectangle := Empty {
input property <brush> background;
input property <brush> color <=> background;
}
BorderRectangle := Rectangle {
input property <length> border-width;
input property <length> border-radius;
input property <brush> border-color;
//-default_size_binding:expands_to_parent_geometry
}
export { BorderRectangle as Rectangle }
ImageItem := Empty {
input property <image> source;
input property <ImageFit> image-fit;
input property <ImageRendering> image-rendering;
}
export ClippedImage := ImageItem {
input property <int> source-clip-x;
input property <int> source-clip-y;
input property <int> source-clip-width;
input property <int> source-clip-height;
input property <brush> colorize;
//-default_size_binding:implicit_size
}
export { ClippedImage as Image }
export Rotate := Empty {
input property <angle> rotation-angle;
input property <length> rotation-origin-x;
input property <length> rotation-origin-y;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
export Text := Empty {
input property <string> text;
input property <string> font-family;
input property <length> font-size;
input property <int> font-weight;
input property <brush> color; // StyleMetrics.default-text-color set in apply_default_properties_from_style
input property <TextHorizontalAlignment> horizontal-alignment;
input property <TextVerticalAlignment> vertical-alignment;
input property <TextOverflow> overflow;
input property <TextWrap> wrap;
input property <length> letter-spacing;
//-default_size_binding:implicit_size
}
export struct PointerEvent := {
//-name:slint::private_api::PointerEvent
button: PointerEventButton,
kind: PointerEventKind,
}
export TouchArea := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <bool> enabled: true;
output property <bool> pressed;
output property <bool> has_hover;
output property <length> mouse_x;
output property <length> mouse_y;
output property <length> pressed_x;
output property <length> pressed_y;
input property <MouseCursor> mouse-cursor;
callback clicked;
callback moved;
callback pointer-event(PointerEvent);
//-default_size_binding:expands_to_parent_geometry
}
export struct KeyboardModifiers := {
//-name:slint::private_api::KeyboardModifiers
alt: bool,
control: bool,
shift: bool,
meta: bool,
}
export struct KeyEvent := {
//-name:slint::private_api::KeyEvent
text: string,
modifiers: KeyboardModifiers,
}
export FocusScope := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <bool> enabled: true;
output property <bool> has-focus;
callback key_pressed(KeyEvent) -> EventResult;
callback key_released(KeyEvent) -> EventResult;
//-default_size_binding:expands_to_parent_geometry
//-accepts_focus
}
export Flickable := Empty {
// These properties are actually going to be forwarded to the viewport by the
// code generator
input property <length> viewport-height;
input property <length> viewport-width;
input output property <length> viewport-x;
input output property <length> viewport-y;
input property <bool> interactive: true;
//-default_size_binding:expands_to_parent_geometry
}
WindowItem := _ {
input output property <length> width;
input output property <length> height;
input property <brush> background; // StyleMetrics.window_background set in apply_default_properties_from_style
input property <brush> color <=> background;
input property <string> title: "Slint Window";
input property <bool> no-frame;
input property <string> default-font-family;
input output property <length> default-font-size; // <=> StyleMetrics.default-font-size set in apply_default_properties_from_style
input property <int> default-font-weight;
input property <image> icon;
}
export Window := WindowItem {}
export BoxShadow := Empty {
input property <length> border_radius;
input property <length> offset_x;
input property <length> offset_y;
input property <color> color;
input property <length> blur;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
export struct Point := {
//-name:slint::private_api::Point
x: length,
y: length,
}
export TextInput := _ {
input output property <string> text;
input property <string> font-family;
input property <length> font-size;
input property <int> font-weight;
input property <brush> color; // StyleMetrics.default-text-color set in apply_default_properties_from_style
input property <color> selection-foreground-color: #000;
input property <color> selection-background-color: #808080;
input property <TextHorizontalAlignment> horizontal-alignment;
input property <TextVerticalAlignment> vertical-alignment;
input property <TextWrap> wrap;
input property <length> letter-spacing;
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <length> text-cursor-width; // StyleMetrics.text-cursor-width set in apply_default_properties_from_style
input property <InputType> input-type;
// Internal, undocumented property, only exposed for tests.
output property <int> cursor-position_byte-offset;
// Internal, undocumented property, only exposed for tests.
output property <int> anchor-position-byte-offset;
output property <bool> has-focus;
callback accepted;
callback edited;
callback cursor_position_changed(Point);
input property <bool> enabled: true;
input property <bool> single-line: true;
input property <bool> read-only: false;
output property <string> preedit-text;
//-default_size_binding:expands_to_parent_geometry
//-accepts_focus
}
export Clip := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <length> border-radius;
input property <length> border-width;
input property <bool> clip;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
export Opacity := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <float> opacity: 1;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
export Layer := Empty {
input property <bool> cache-rendering-hint;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
Row := _ {
//-is_non_item_type
}
// Note: layouts are not NativeClass, but this is lowered in lower_layout
export GridLayout := _ {
input property <length> spacing;
// Additional accepted child
Row { }
}
export VerticalLayout := _ {
input property <length> spacing;
input property <LayoutAlignment> alignment;
}
export HorizontalLayout := _ {
input property <length> spacing;
input property <LayoutAlignment> alignment;
}
MoveTo := _ {
input property <float> x;
input property <float> y;
//-rust_type_constructor:slint::re_exports::PathElement::MoveTo(PathMoveTo{{}})
//-cpp_type:slint::private_api::PathMoveTo
//-is_non_item_type
}
LineTo := _ {
input property <float> x;
input property <float> y;
//-rust_type_constructor:slint::re_exports::PathElement::LineTo(PathLineTo{{}})
//-cpp_type:slint::private_api::PathLineTo
//-is_non_item_type
}
ArcTo := _ {
input property <float> x;
input property <float> y;
input property <float> radius-x;
input property <float> radius-y;
input property <float> x-rotation;
input property <bool> large_arc;
input property <bool> sweep;
//-rust_type_constructor:slint::re_exports::PathElement::ArcTo(PathArcTo{{}})
//-cpp_type:slint::private_api::PathArcTo
//-is_non_item_type
}
CubicTo := _ {
input property <float> control-1-x;
input property <float> control-1-y;
input property <float> control-2-x;
input property <float> control-2-y;
input property <float> x;
input property <float> y;
//-rust_type_constructor:slint::re_exports::PathElement::CubicTo(PathCubicTo{{}})
//-cpp_type:slint::private_api::PathCubicTo
//-is_non_item_type
}
QuadraticTo := _ {
input property <float> control-x;
input property <float> control-y;
input property <float> x;
input property <float> y;
//-rust_type_constructor:slint::re_exports::PathElement::QuadraticTo(PathQuadraticTo{{}})
//-cpp_type:slint::private_api::PathQuadraticTo
//-is_non_item_type
}
Close := _ {
//-rust_type_constructor:slint::re_exports::PathElement::Close
//-cpp_type:slint::private_api::PathClose
//-is_non_item_type
//-is_non_item_type
}
export Path := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <brush> fill;
input property <FillRule> fill-rule;
input property <brush> stroke;
input property <length> stroke-width;
input property <string> commands;
input property <float> viewbox-x;
input property <float> viewbox-y;
input property <float> viewbox-width;
input property <float> viewbox-height;
input property <bool> clip;
//-disallow_global_types_as_child_elements
MoveTo {}
LineTo {}
ArcTo {}
CubicTo {}
QuadraticTo {}
Close {}
//-default_size_binding:expands_to_parent_geometry
}
export PathLayout := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <string> commands;
input property <float> offset;
MoveTo {}
LineTo {}
ArcTo {}
CubicTo {}
QuadraticTo {}
Close {}
}
Tab := _ {
input property <string> title;
}
// Note: not a native class, handled in the lower_tabs pass
export TabWidget := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <int> current-index;
input property <int> current-focused;
//-disallow_global_types_as_child_elements
Tab {}
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
// Note: not a native class, handled in the lower_popups pass
export PopupWindow := _ {
//property <length> x;
//property <length> y;
input property <length> width;
input property <length> height;
/*property <length> anchor_x;
input property <length> anchor_y;
input property <length> anchor_height;
input property <length> anchor_width;*/
//show() is hardcoded in typeregister.rs
}
export Dialog := WindowItem {}
PropertyAnimation := _ {
input property <duration> delay;
input property <duration> duration;
input property <easing> easing;
input property <float> iteration-count: 1.0;
//-is_non_item_type
}
export struct StandardListViewItem := {
//-name:slint::private_api::StandardListViewItem
text: string
}
export struct StateInfo := {
//-name:slint::private_api::StateInfo
current_state: int,
previous_state: int,
//change_time: duration,
//-is_internal
}
export NativeButton := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <string> text;
input property <image> icon;
output property <bool> pressed;
input property <bool> checkable;
input output property <bool> checked;
output property <bool> has-focus;
callback clicked;
input property <bool> enabled: true;
input property <StandardButtonKind> standard-button-kind;
input property <bool> is-standard-button;
//-is_internal
}
export NativeCheckBox := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <bool> enabled: true;
input property <string> text;
input output property <bool> checked;
output property <bool> has-focus;
callback toggled;
//-is_internal
}
export NativeSpinBox := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <bool> enabled: true;
output property <bool> has-focus;
input output property <int> value;
input property <int> minimum;
input property <int> maximum: 100;
//-is_internal
}
export NativeSlider := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <bool> enabled: true;
input output property <float> value;
input property <float> minimum;
input property <float> maximum: 100;
callback changed(float);
//-is_internal
}
export NativeGroupBox := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <bool> enabled: true;
input property <string> title;
output property <length> native-padding-left;
output property <length> native-padding-right;
output property <length> native-padding-top;
output property <length> native-padding-bottom;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
export NativeLineEdit := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
output property <length> native-padding-left;
output property <length> native-padding-right;
output property <length> native-padding-top;
output property <length> native-padding-bottom;
input property <bool> has-focus;
input property <bool> enabled: true;
//-is_internal
}
export NativeScrollView := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <length> horizontal-max;
input property <length> horizontal-page-size;
input property <length> horizontal-value;
input property <length> vertical-max;
input property <length> vertical-page-size;
input output property <length> vertical-value;
output property <length> native-padding-left;
output property <length> native-padding-right;
output property <length> native-padding-top;
output property <length> native-padding-bottom;
input property <bool> has_focus;
input property <bool> enabled: true;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
export NativeStandardListViewItem := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <int> index;
input property <StandardListViewItem> item;
input output property <bool> is_selected;
input property <bool> has_hover;
//-is_internal
}
export NativeComboBox := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property <string> current_value;
input output property <bool> is_open;
input property <bool> enabled: true;
callback open_popup;
//-is_internal
}
export NativeComboBoxPopup := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
//-is_internal
}
export NativeTabWidget := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
output property <length> content-x;
output property <length> content-y;
output property <length> content-height;
output property <length> content-width;
output property <length> tabbar-x;
output property <length> tabbar-y;
output property <length> tabbar-height;
output property <length> tabbar-width;
input property <length> tabbar-preferred-height;
input property <length> tabbar-preferred-width;
input property <length> content-min-height;
input property <length> content-min-width;
input property <int> current-index;
input property <int> current-focused;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}
export NativeTab := _ {
input property <length> x;
input property <length> y;
input property <length> width;
input property <length> height;
input property<string> title;
input property<image> icon;
input property<bool> enabled : true;
output property<bool> pressed;
output property<int> current; // supposed to be a binding to the tab
input property<int> tab-index;
input property<int> current-focused;
input property<int> num-tabs;
//-is_internal
}
export global NativeStyleMetrics := {
output property <length> layout-spacing;
output property <length> layout-padding;
output property <length> text-cursor-width;
output property <color> window-background;
output property <color> default-text-color;
output property <length> default-font-size;
output property <color> textedit-background;
output property <color> textedit-text-color;
output property <color> textedit-background-disabled;
output property <color> textedit-text-color-disabled;
output property <bool> dark-color-scheme;
// specific to the Native one
output property <color> placeholder-color;
output property <color> placeholder-color-disabled;
// Tab Bar metrics:
output property <LayoutAlignment> tab-bar-alignment;
//-is_non_item_type
//-is_internal
}