Do not eat all keypresses in SpinBox

This commit is contained in:
Tobias Hunger 2022-03-22 17:16:47 +01:00 committed by Tobias Hunger
parent 626f7c64fc
commit 24d325a53b
2 changed files with 12 additions and 6 deletions

View file

@ -1,6 +1,8 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
// cSpell: ignore standardbutton
import { LineEditInner, TextEdit, AboutSlint } from "../common/common.slint";
import { StandardButton } from "../common/standardbutton.slint";
import { StyleMetrics, ScrollView, Button, Palette } from "std-widgets-impl.slint";
@ -163,14 +165,17 @@ export SpinBox := FocusScope {
: has-focus ? Palette.themeSecondary
: Palette.neutralDark;
}
key-pressed(event) => {
if (enabled && event.text == Keys.UpArrow && value < maximum) {
value += 1;
accept
} else if (enabled && event.text == Keys.DownArrow && value > minimum) {
value -= 1;
accept
} else {
reject
}
accept
}
}

View file

@ -18,7 +18,7 @@ export StandardButton := NativeButton {
export CheckBox := NativeCheckBox { }
export SpinBox := NativeSpinBox {
property<length> font-size;
key-pressed(event) => {
if (enabled && event.text == Keys.UpArrow && value < maximum) {
value += 1;
@ -84,12 +84,13 @@ export StandardListView := ListView {
key-pressed(event) => {
if (event.text == Keys.UpArrow && current-item > 0) {
actual-current-item -= 1;
return accept;
accept
} else if (event.text == Keys.DownArrow && current-item + 1 < model.length) {
actual-current-item += 1;
return accept;
accept
} else {
reject
}
reject
}
}
}