mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-09 13:18:58 +00:00
119 lines
No EOL
4.2 KiB
Text
119 lines
No EOL
4.2 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.0 OR LicenseRef-Slint-commercial
|
|
|
|
import { Typography, Palette } from "styling.slint";
|
|
|
|
export component LineEdit {
|
|
callback accepted(string /* text */);
|
|
callback edited(string /* text */);
|
|
|
|
in property <bool> enabled <=> i-text-input.enabled;
|
|
in property <InputType> input-type <=> i-text-input.input-type;
|
|
in property <TextHorizontalAlignment> horizontal-alignment <=> i-text-input.horizontal-alignment;
|
|
in property <bool> read-only <=> i-text-input.read-only;
|
|
in property <length> font-size <=> i-text-input.font-size;
|
|
in property <string> placeholder-text <=> i-placeholder.text;
|
|
out property <bool> has-focus <=> i-text-input.has-focus;
|
|
in-out property <string> text <=> i-text-input.text;
|
|
|
|
vertical-stretch: 0;
|
|
horizontal-stretch: 1;
|
|
min-width: max(160px, i-layout.min-height);
|
|
min-height: max(32px, i-layout.min-height);
|
|
forward-focus: i-text-input;
|
|
|
|
i-background := Rectangle {
|
|
border-radius: 4px;
|
|
background: Palette.control-default;
|
|
border-width: 1px;
|
|
border-color: Palette.text-control-border;
|
|
|
|
i-layout := HorizontalLayout {
|
|
padding-left: 12px;
|
|
padding-right: 12px;
|
|
|
|
Rectangle {
|
|
clip: true;
|
|
|
|
i-placeholder := Text {
|
|
width: 100%;
|
|
height: 100%;
|
|
color: Palette.text-secondary;
|
|
font-size: Typography.body.font-size;
|
|
font-weight: Typography.body.font-weight;
|
|
visible: root.text == "";
|
|
vertical-alignment: center;
|
|
}
|
|
|
|
i-text-input := TextInput {
|
|
property <length> computed_x;
|
|
property <length> padding-outer: i-layout.padding-left + i-layout.padding-right;
|
|
|
|
x: min(0px, max(parent.width - self.width, self.computed_x));
|
|
width: max(parent.width, self.preferred-width);
|
|
height: 100%;
|
|
color: Palette.text-primary;
|
|
vertical-alignment: center;
|
|
font-size: Typography.body.font-size;
|
|
font-weight: Typography.body.font-weight;
|
|
selection-background-color: Palette.accent-selected-text;
|
|
selection-foreground-color: self.color;
|
|
|
|
accepted => {
|
|
root.accepted(self.text);
|
|
}
|
|
|
|
edited => {
|
|
root.edited(self.text);
|
|
}
|
|
|
|
cursor-position-changed(cpos) => {
|
|
if (cpos.x + self.computed_x < self.padding-outer) {
|
|
self.computed_x = - cpos.x + self.padding-outer;
|
|
} else if (cpos.x + self.computed_x > parent.width - self.padding-outer) {
|
|
self.computed_x = parent.width - cpos.x - self.padding-outer;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
i-focus-border := Rectangle {
|
|
x: parent.border-radius;
|
|
y: parent.height - self.height;
|
|
width: parent.width - 2 * parent.border-radius;
|
|
height: 2px;
|
|
}
|
|
}
|
|
|
|
public function select-all() {
|
|
i-text-input.select-all();
|
|
}
|
|
|
|
public function cut() {
|
|
i-text-input.cut();
|
|
}
|
|
|
|
public function copy() {
|
|
i-text-input.copy();
|
|
}
|
|
|
|
public function paste() {
|
|
i-text-input.paste();
|
|
}
|
|
|
|
states [
|
|
disabled when !root.enabled : {
|
|
i-background.background: Palette.control-disabled;
|
|
i-background.border-color: Palette.control-stroke;
|
|
i-text-input.color: Palette.text-disabled;
|
|
i-placeholder.color: Palette.text-disabled;
|
|
}
|
|
focused when root.has-focus : {
|
|
i-background.background: Palette.control-input-active;
|
|
i-background.border-color: Palette.control-stroke;
|
|
i-focus-border.background: Palette.accent-default;
|
|
i-placeholder.color: Palette.text-tertiary;
|
|
}
|
|
]
|
|
} |