mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 12:54:45 +00:00
155 lines
4.8 KiB
Text
155 lines
4.8 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
|
|
|
import { LineEditInner, TextEdit, AboutSlint } from "../common/common.slint";
|
|
import { StyleMetrics, ScrollView } from "std-widgets-impl.slint";
|
|
export { StyleMetrics, ScrollView, TextEdit, AboutSlint, AboutSlint as AboutSixtyFPS }
|
|
|
|
// FIXME: the font-size should be removed but is required right now to compile the printer-demo
|
|
export Button := NativeButton {
|
|
property<length> font-size;
|
|
enabled: true;
|
|
}
|
|
|
|
export StandardButton := NativeButton {
|
|
property<StandardButtonKind> kind <=> self.standard-button-kind;
|
|
is-standard-button: true;
|
|
}
|
|
export CheckBox := NativeCheckBox { }
|
|
export SpinBox := NativeSpinBox {
|
|
property<length> font-size;
|
|
|
|
key-pressed(event) => {
|
|
if (enabled && event.text == Keys.UpArrow && value < maximum) {
|
|
value += 1;
|
|
} else if (enabled && event.text == Keys.DownArrow && value > minimum) {
|
|
value -= 1;
|
|
}
|
|
accept
|
|
}
|
|
}
|
|
export Slider := NativeSlider { }
|
|
export GroupBox := NativeGroupBox {
|
|
GridLayout {
|
|
padding-left: root.native-padding-left;
|
|
padding-right: root.native-padding-right;
|
|
padding-top: root.native-padding-top;
|
|
padding-bottom: root.native-padding-bottom;
|
|
@children
|
|
}
|
|
}
|
|
export LineEdit := NativeLineEdit {
|
|
property <length> font-size <=> inner.font-size;
|
|
property <string> text <=> inner.text;
|
|
property <string> placeholder-text <=> inner.placeholder-text;
|
|
property input-type <=> inner.input-type;
|
|
enabled: true;
|
|
has-focus <=> inner.has-focus;
|
|
forward-focus: inner;
|
|
callback accepted <=> inner.accepted;
|
|
callback edited <=> inner.edited;
|
|
horizontal-stretch: 1;
|
|
vertical-stretch: 0;
|
|
|
|
HorizontalLayout {
|
|
padding-left: root.native-padding-left;
|
|
padding-right: root.native-padding-right;
|
|
padding-top: root.native-padding-top;
|
|
padding-bottom: root.native-padding-bottom;
|
|
inner := LineEditInner {
|
|
placeholder-color: enabled ? StyleMetrics.placeholder-color : StyleMetrics.placeholder-color-disabled;
|
|
enabled <=> root.enabled;
|
|
}
|
|
}
|
|
}
|
|
|
|
export ListView := ScrollView {
|
|
@children
|
|
}
|
|
|
|
export StandardListView := ListView {
|
|
property<[StandardListViewItem]> model;
|
|
property<int> current-item: min(fs.actual-current-item, model.length - 1);
|
|
for item[i] in model : NativeStandardListViewItem {
|
|
item: item;
|
|
index: i;
|
|
is-selected: current-item == i;
|
|
TouchArea {
|
|
clicked => { fs.actual-current-item = i; }
|
|
has-hover <=> parent.has-hover;
|
|
}
|
|
}
|
|
fs := FocusScope {
|
|
property<int> actual-current-item: -1;
|
|
key-pressed(event) => {
|
|
if (event.text == Keys.UpArrow && current-item > 0) {
|
|
actual-current-item -= 1;
|
|
accept
|
|
} else if (event.text == Keys.DownArrow && current-item + 1 < model.length) {
|
|
actual-current-item += 1;
|
|
accept
|
|
} else {
|
|
reject
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
export ComboBox := NativeComboBox {
|
|
property <[string]> model;
|
|
property <int> current-index : -1;
|
|
enabled: true;
|
|
open-popup => { popup.show(); }
|
|
callback selected(string);
|
|
|
|
popup := PopupWindow {
|
|
Rectangle { background: NativeStyleMetrics.window-background; }
|
|
NativeComboBoxPopup {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
y: root.height;
|
|
width: root.width;
|
|
VerticalLayout {
|
|
spacing: 0px;
|
|
for value[i] in root.model: NativeStandardListViewItem {
|
|
item: { text: value };
|
|
is-selected: current-index == i;
|
|
TouchArea {
|
|
has-hover <=> parent.has-hover;
|
|
clicked => {
|
|
if (root.enabled) {
|
|
current-index = i;
|
|
current-value = value;
|
|
selected(current-value);
|
|
}
|
|
//is-open = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export TabWidgetImpl := NativeTabWidget {
|
|
property <int> current-index;
|
|
}
|
|
export TabImpl := NativeTab {}
|
|
export TabBarImpl := HorizontalLayout {
|
|
alignment: start;
|
|
}
|
|
export TabWidget := TabWidget {}
|
|
|
|
export VerticalBox := VerticalLayout {
|
|
spacing: NativeStyleMetrics.layout-spacing;
|
|
padding: NativeStyleMetrics.layout-spacing;
|
|
}
|
|
export HorizontalBox := HorizontalLayout {
|
|
spacing: NativeStyleMetrics.layout-spacing;
|
|
padding: NativeStyleMetrics.layout-spacing;
|
|
}
|
|
export GridBox := GridLayout {
|
|
spacing: NativeStyleMetrics.layout-spacing;
|
|
padding: NativeStyleMetrics.layout-spacing;
|
|
}
|