slint/internal/compiler/widgets/native/std-widgets.slint
Olivier Goffart 8a4d6a34ba Revert #1049
This breaks the printer demo USB page, it makes it impossible to
change the current item.
That's because the printer demo do `current-item: 1;` to preselect the cat.
But that breaks the property binding that makes current-item follow the
actual-current-item.

 * Revert "move actual-current-item to FocusScope"
   This reverts commit 8240531e6e.

 * Revert "reset StandardListView's current-item if it is out of bounds"
   This reverts commit 9d18882f9d.
2022-05-02 14:13:37 +02:00

170 lines
5.2 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;
}
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: -1;
for item[i] in model : NativeStandardListViewItem {
item: item;
index: i;
is-selected: current-item == i;
TouchArea {
clicked => { current-item = i; }
has-hover <=> parent.has-hover;
}
}
FocusScope {
key-pressed(event) => {
if (event.text == Keys.UpArrow && current-item > 0) {
current-item -= 1;
accept
} else if (event.text == Keys.DownArrow && current-item + 1 < model.length) {
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 { }
export TabImpl := NativeTab { }
export TabBarImpl := Rectangle {
// injected properties:
property<int> current; // The currently selected tab
property<int> current-focused: fs.has-focus ? current : -1; // The currently focused tab
property<int> num-tabs; // The total number of tabs
HorizontalLayout {
spacing: 0px; // Qt renders Tabs next to each other and renders "spacing" as part of the tab itself
alignment: NativeStyleMetrics.tab-bar-alignment;
@children
}
fs := FocusScope {
width: 0px; // Do not react on clicks
key-pressed(event) => {
if (event.text == Keys.LeftArrow) {
root.current = Math.max(root.current - 1, 0);
return accept;
}
if (event.text == Keys.RightArrow) {
root.current = Math.min(root.current + 1, num-tabs - 1);
return accept;
}
return reject;
}
}
}
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;
}