// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 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.
 */

component Empty {
    //-is_internal
}

component Rectangle inherits Empty {
    in property <brush> background;
    in property <brush> color <=> background;
}

component BasicBorderRectangle inherits Rectangle {
    in property <length> border-width;
    in property <length> border-radius;
    in property <brush> border-color;
}

component BorderRectangle inherits BasicBorderRectangle {
    in property <length> border-top-left-radius;
    in property <length> border-top-right-radius;
    in property <length> border-bottom-left-radius;
    in property <length> border-bottom-right-radius;
    //-default_size_binding:expands_to_parent_geometry
}

export { BorderRectangle as Rectangle }

component ImageItem inherits Empty {
    in property <length> width;
    in property <length> height;
    in property <image> source;
    in property <ImageFit> image-fit;
    in property <ImageRendering> image-rendering;
    in property <brush> colorize;
}

export component ClippedImage inherits ImageItem {
    in property <int> source-clip-x;
    in property <int> source-clip-y;
    in property <int> source-clip-width;
    in property <int> source-clip-height;
    //-default_size_binding:implicit_size

    in property <ImageHorizontalAlignment> horizontal-alignment;
    in property <ImageVerticalAlignment> vertical-alignment;
    in property <ImageTiling> horizontal-tiling;
    in property <ImageTiling> vertical-tiling;
    // TODO: sets both horizontal-tiling and vertical-tiling at the same time.
    // in property <ImageTiling> tiling;

}

export { ClippedImage as Image }

export component ComponentContainer inherits Empty {
    in property <component-factory> component-factory;
    out property <bool> has-component;

    in-out property <length> width;
    in-out property <length> height;
}

export component Rotate inherits Empty {
    in property <angle> rotation-angle;
    in property <length> rotation-origin-x;
    in property <length> rotation-origin-y;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

export component Text inherits Empty {
    in property <length> width;
    in property <length> height;
    in property <string> text;
    in property <string> font-family;
    in property <length> font-size;
    in property <bool> font-italic;
    in property <int> font-weight;
    in property <brush> color;  // StyleMetrics.default-text-color  set in apply_default_properties_from_style
    in property <TextHorizontalAlignment> horizontal-alignment;
    in property <TextVerticalAlignment> vertical-alignment;
    in property <TextOverflow> overflow;
    in property <TextWrap> wrap;
    in property <length> letter-spacing;
    in property <brush> stroke;
    in property <length> stroke-width;
    in property <TextStrokeStyle> stroke-style;
    //-default_size_binding:implicit_size
}

export component TouchArea {
    in property <bool> enabled: true;
    out property <bool> pressed;
    out property <bool> has_hover;
    out property <length> mouse_x;
    out property <length> mouse_y;
    out property <length> pressed_x;
    out property <length> pressed_y;
    in property <MouseCursor> mouse-cursor;
    callback clicked;
    callback double-clicked;
    callback moved;
    callback pointer-event(PointerEvent);
    callback scroll-event(PointerScrollEvent) -> EventResult;
    //-default_size_binding:expands_to_parent_geometry
}

export component FocusScope {
    in property <bool> enabled: true;
    out property <bool> has-focus;
    callback key_pressed(KeyEvent) -> EventResult;
    callback key_released(KeyEvent) -> EventResult;
    callback focus_changed_event();
    //-default_size_binding:expands_to_parent_geometry
    //-accepts_focus
}

export component Flickable inherits Empty {
    in property <length> viewport-height;
    in property <length> viewport-width;
    in-out property <length> viewport-x;
    in-out property <length> viewport-y;
    in property <bool> interactive: true;
    callback flicked();
    //-default_size_binding:expands_to_parent_geometry
}

component WindowItem {
    in-out property <length> width;
    in-out property <length> height;
    in property <brush> background; // StyleMetrics.window_background  set in apply_default_properties_from_style
    in property <brush> color <=> background;
    in property <string> title: "Slint Window";
    in property <bool> no-frame;
    in property <bool> always-on-top;
    in property <string> default-font-family;
    in-out property <length> default-font-size; // <=> StyleMetrics.default-font-size  set in apply_default_properties_from_style
    in property <int> default-font-weight;
    in property <image> icon;
}

export component Window inherits WindowItem {}

export component BoxShadow inherits Empty {
    in property <length> border_radius;
    in property <length> offset_x;
    in property <length> offset_y;
    in property <color> color;
    in property <length> blur;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

export component TextInput {
    in-out property <string> text;
    in property <string> font-family;
    in property <length> font-size;
    in property <bool> font-italic;
    in property <int> font-weight;
    in property <brush> color; // StyleMetrics.default-text-color  set in apply_default_properties_from_style
    in property <color> selection-foreground-color: #000;
    in property <color> selection-background-color: #808080;
    in property <TextHorizontalAlignment> horizontal-alignment;
    in property <TextVerticalAlignment> vertical-alignment;
    in property <TextWrap> wrap;
    in property <length> letter-spacing;
    in property <length> width;
    in property <length> height;
    in property <length> text-cursor-width; // StyleMetrics.text-cursor-width  set in apply_default_properties_from_style
    in property <InputType> input-type;
    // Internal, undocumented property, only exposed for tests.
    out property <int> cursor-position_byte-offset;
    // Internal, undocumented property, only exposed for tests.
    out property <int> anchor-position-byte-offset;
    out property <bool> has-focus;
    callback accepted;
    callback edited;
    callback cursor_position_changed(Point);
    in property <bool> enabled: true;
    in property <bool> single-line: true;
    in property <bool> read-only: false;
    // Internal, undocumented property, only exposed for IME.
    out property <string> preedit-text;
    //-default_size_binding:expands_to_parent_geometry
    //-accepts_focus
    function set-selection-offsets(start: int, end: int) {}
    function select-all() {}
    function clear-selection() {}
    function cut() {}
    function copy() {}
    function paste() {}
}

export component Clip {
    in property <length> border-top-left-radius;
    in property <length> border-top-right-radius;
    in property <length> border-bottom-left-radius;
    in property <length> border-bottom-right-radius;
    in property <length> border-width;
    in property <bool> clip;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

export component Opacity {
    in property <float> opacity: 1;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

export component Layer inherits Empty {
    in property <bool> cache-rendering-hint;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

component Row {
    //-is_non_item_type
}

// Note: layouts are not NativeClass, but this is lowered in lower_layout
export component GridLayout {
    in property <length> spacing-horizontal;
    in property <length> spacing-vertical;
    in property <length> spacing;

    // Additional accepted child
    Row { }
}

export component VerticalLayout {
    in property <length> spacing;
    in property <LayoutAlignment> alignment;
}

export component HorizontalLayout {
    in property <length> spacing;
    in property <LayoutAlignment> alignment;
}

component MoveTo {
    in property <float> x;
    in property <float> y;

    //-rust_type_constructor:slint::re_exports::PathElement::MoveTo(PathMoveTo{{}})
    //-cpp_type:slint::private_api::PathMoveTo
    //-is_non_item_type
}

component LineTo {
    in property <float> x;
    in property <float> y;

    //-rust_type_constructor:slint::re_exports::PathElement::LineTo(PathLineTo{{}})
    //-cpp_type:slint::private_api::PathLineTo
    //-is_non_item_type
}

component ArcTo {
    in property <float> x;
    in property <float> y;
    in property <float> radius-x;
    in property <float> radius-y;
    in property <float> x-rotation;
    in property <bool> large_arc;
    in property <bool> sweep;

    //-rust_type_constructor:slint::re_exports::PathElement::ArcTo(PathArcTo{{}})
    //-cpp_type:slint::private_api::PathArcTo
    //-is_non_item_type
}

component CubicTo {
    in property <float> control-1-x;
    in property <float> control-1-y;
    in property <float> control-2-x;
    in property <float> control-2-y;
    in property <float> x;
    in property <float> y;

    //-rust_type_constructor:slint::re_exports::PathElement::CubicTo(PathCubicTo{{}})
    //-cpp_type:slint::private_api::PathCubicTo
    //-is_non_item_type
}

component QuadraticTo {
    in property <float> control-x;
    in property <float> control-y;
    in property <float> x;
    in property <float> y;

    //-rust_type_constructor:slint::re_exports::PathElement::QuadraticTo(PathQuadraticTo{{}})
    //-cpp_type:slint::private_api::PathQuadraticTo
    //-is_non_item_type
}

component Close {
    //-rust_type_constructor:slint::re_exports::PathElement::Close
    //-cpp_type:slint::private_api::PathClose
    //-is_non_item_type
    //-is_non_item_type
}

export component Path {
    in property <brush> fill;
    in property <FillRule> fill-rule;
    in property <brush> stroke;
    in property <length> stroke-width;
    in property <string> commands;
    in property <float> viewbox-x;
    in property <float> viewbox-y;
    in property <float> viewbox-width;
    in property <float> viewbox-height;
    in property <bool> clip;

    //-disallow_global_types_as_child_elements
    MoveTo {}
    LineTo {}
    ArcTo {}
    CubicTo {}
    QuadraticTo {}
    Close {}

    //-default_size_binding:expands_to_parent_geometry
}

component Tab {
    in property <string> title;
}

// Note: not a native class, handled in the lower_tabs pass
export component TabWidget {
    in-out property <int> current-index;

    //-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 component PopupWindow {
    //property <length> x;
    //property <length> y;
    in property <length> width;
    in property <length> height;
    /*property <length> anchor_x;
    in property <length> anchor_y;
    in property <length> anchor_height;
    in property <length> anchor_width;*/
    in property <bool> close-on-click: true;  // constexpr hardcoded in typeregister.rs
    //show() is hardcoded in typeregister.rs
}

export component Dialog inherits WindowItem {}

component PropertyAnimation {
    in property <duration> delay;
    in property <duration> duration;
    in property <easing> easing;
    in property <float> iteration-count: 1.0;
    //-is_non_item_type
}

export global TextInputInterface {
    in property <bool> text-input-focused;
}

export component NativeButton {
    in property <string> text;
    in property <image> icon;
    out property <bool> pressed;
    in property <bool> checkable;
    in-out property <bool> checked;
    out property <bool> has-focus;
    in property <bool> primary;
    in property <bool> colorize-icon;
    callback clicked;
    in property <bool> enabled: true;
    in property <StandardButtonKind> standard-button-kind;
    in property <bool> is-standard-button;
    //-is_internal
    //-accepts_focus
}

export component NativeCheckBox {
    in property <bool> enabled: true;
    in property <string> text;
    in-out property <bool> checked;
    out property <bool> has-focus;
    callback toggled;
    //-is_internal
    //-accepts_focus
}

export component NativeSpinBox {
    in property <bool> enabled: true;
    out property <bool> has-focus;
    in-out property <int> value;
    in property <int> minimum;
    in property <int> maximum: 100;
    callback edited(int /* value */);
    //-is_internal
    //-accepts_focus
}

export component NativeSlider {
    in property <bool> enabled: true;
    out property <bool> has-focus;
    in-out property <float> value;
    in property <float> minimum;
    in property <float> maximum: 100;
    in property <Orientation> orientation: Orientation.horizontal;
    callback changed(float);
    callback released(float);
    //-is_internal
    //-accepts_focus
}

export component NativeProgressIndicator {
    in property <bool> indeterminate;
    in property <float> progress;
    //-is_internal
}

export component NativeGroupBox {
    in property <bool> enabled: true;
    in property <string> title;
    out property <length> native-padding-left;
    out property <length> native-padding-right;
    out property <length> native-padding-top;
    out property <length> native-padding-bottom;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

export component NativeLineEdit {
    out property <length> native-padding-left;
    out property <length> native-padding-right;
    out property <length> native-padding-top;
    out property <length> native-padding-bottom;
    in property <bool> has-focus;
    in property <bool> enabled: true;
    //-is_internal
}

export component NativeScrollView {
    in property <length> horizontal-max;
    in property <length> horizontal-page-size;
    in property <length> horizontal-value;
    in property <length> vertical-max;
    in property <length> vertical-page-size;
    in-out property <length> vertical-value;
    out property <length> native-padding-left;
    out property <length> native-padding-right;
    out property <length> native-padding-top;
    out property <length> native-padding-bottom;
    in property <bool> has_focus;
    in property <bool> enabled: true;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

export component NativeStandardListViewItem {
    in property <int> index;
    in property <StandardListViewItem> item;
    in-out property <bool> is_selected;
    in property <bool> has_hover;
    in property <bool> has_focus;
    in property <bool> pressed;
    in property <bool> combobox;
    in property <length> pressed-x;
    in property <length> pressed-y;
    //-is_internal
}

export component NativeTableHeaderSection {
    in property <int> index;
    in property <TableColumn> item;
    in property <bool> has_hover;
    //-is_internal
}

export component NativeComboBox {
    in-out property <string> current_value;
    in property <bool> enabled: true;
    in property <bool> has-focus;
    //-is_internal
}

export component NativeComboBoxPopup {
    //-is_internal
}

export component NativeTabWidget {
    in property <length> width;
    in property <length> height;

    out property <length> content-x;
    out property <length> content-y;
    out property <length> content-height;
    out property <length> content-width;
    out property <length> tabbar-x;
    out property <length> tabbar-y;
    out property <length> tabbar-height;
    out property <length> tabbar-width;
    in property <length> tabbar-preferred-height;
    in property <length> tabbar-preferred-width;
    in property <length> content-min-height;
    in property <length> content-min-width;

    in property <int> current-index;
    in property <int> current-focused;
    //-default_size_binding:expands_to_parent_geometry
    //-is_internal
}

export component NativeTab {
    in property<string> title;
    in property<image> icon;
    in property<bool> enabled : true;
    in-out property<int> current; // supposed to be a binding to the tab
    in property<int> tab-index;
    in property<int> current-focused;
    in property<int> num-tabs;
    //-is_internal
}

export global NativeStyleMetrics {
    out property <length> layout-spacing;
    out property <length> layout-padding;
    out property <length> text-cursor-width;
    out property <color> window-background;
    out property <color> default-text-color;
    out property <length> default-font-size;
    out property <color> textedit-background;
    out property <color> textedit-text-color;
    out property <color> textedit-background-disabled;
    out property <color> textedit-text-color-disabled;

    out property <bool> dark-color-scheme;

    // specific to the Native one
    out property <color> placeholder-color;
    out property <color> placeholder-color-disabled;

    // Tab Bar metrics:
    out property <LayoutAlignment> tab-bar-alignment;

    //-is_non_item_type
    //-is_internal
}

export global NativePalette {
    out property <brush> background;
    out property <brush> foreground;
    out property <brush> alternate-background;
    out property <brush> alternate-foreground;
    out property <brush> control-background;
    out property <brush> control-foreground;
    out property <brush> accent-background;
    out property <brush> accent-foreground;
    out property <brush> selection-background;
    out property <brush> selection-foreground;
    out property <brush> border;
    in-out property <ColorScheme> color-scheme;

    //-is_non_item_type
    //-is_internal
}
