slint/internal/compiler/widgets/common/spinbox-base.slint
Aurindam Jana 0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00

84 lines
No EOL
2.4 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial
export component SpinBoxBase {
in property <int> minimum;
in property <int> maximum: 100;
in property <bool> enabled: true;
in property <brush> color <=> i-text-input.color;
in property <length> font-size <=> i-text-input.font-size;
in property <int> font-weight <=> i-text-input.font-weight;
in property <color> selection-background-color <=> i-text-input.selection-background-color;
in property <color> selection-foreground-color <=> i-text-input.selection-foreground-color;
in property <TextHorizontalAlignment> horizontal-alignment <=> i-text-input.horizontal-alignment;
out property <bool> has-focus <=> i-text-input.has-focus;
in-out property <int> value;
callback edited(/* value */ int);
public function update-value(value: int) {
if (value >= root.minimum && value <= root.maximum) {
root.value = value;
root.edited(value);
}
i-text-input.text = root.value;
}
public function increment() {
root.update-value(root.value + 1);
}
public function decrement() {
root.update-value(root.value - 1);
}
private property <length> scroll-delta: 2px;
forward-focus: i-text-input;
i-text-input := TextInput {
vertical-alignment: center;
horizontal-alignment: left;
text: root.value;
enabled: root.enabled;
width: 100%;
height: 100%;
accepted => {
if (!self.text.is-float()) {
self.text = root.value;
}
}
edited => {
if (self.text.is-float() && self.text.to-float() != root.value) {
root.update-value(self.text.to-float());
} else if (!self.text.is-float()) {
self.text = root.value;
}
}
}
TouchArea {
enabled: root.enabled;
scroll-event(event) => {
if (event.delta-y > 0) {
root.increment();
return accept;
}
if (event.delta-y < 0) {
root.decrement();
return accept;
}
return reject;
}
clicked => {
i-text-input.focus();
}
}
}