make use of textinputbase (#4014)

This commit is contained in:
Florian Blasius 2023-11-27 08:50:29 +01:00 committed by GitHub
parent a3e48c4950
commit c00a21d651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 168 additions and 267 deletions

View file

@ -0,0 +1,82 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
export component LineEditBase inherits Rectangle {
in-out property <string> placeholder-text;
in-out property <length> font-size <=> i-text-input.font-size;
in-out property <string> text <=> i-text-input.text;
in-out property <brush> placeholder-color;
in-out property <bool> enabled <=> i-text-input.enabled;
in-out property <bool> has-focus: i-text-input.has-focus;
in-out property <InputType> input-type <=> i-text-input.input-type;
in-out property <TextHorizontalAlignment> horizontal-alignment <=> i-text-input.horizontal-alignment;
in-out property <bool> read-only <=> i-text-input.read-only;
in property <int> font-weight <=> i-text-input.font-weight;
in property <brush> text-color;
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 <length> margin;
callback accepted( /* text */ string);
callback edited(/* text */ string);
public function select-all() {
i-text-input.select-all();
}
public function clear-selection() {
i-text-input.clear-selection();
}
public function cut() {
i-text-input.cut();
}
public function copy() {
i-text-input.copy();
}
public function paste() {
i-text-input.paste();
}
min-height: i-text-input.preferred-height;
min-width: max(50px, i-placeholder.min-width);
clip: true;
forward-focus: i-text-input;
i-placeholder := Text {
width: 100%;
height: 100%;
vertical-alignment: center;
text: (root.text == "" && i-text-input.preedit-text == "") ? root.placeholder-text : "";
font-size: i-text-input.font-size;
font-italic: i-text-input.font-italic;
font-weight: i-text-input.font-weight;
font-family: i-text-input.font-family;
color: root.placeholder-color;
}
i-text-input := TextInput {
property <length> computed-x;
x: min(0px, max(parent.width - self.width, self.computed-x));
width: max(parent.width, self.preferred-width);
height: 100%;
vertical-alignment: center;
single-line: true;
color: root.text-color;
cursor-position-changed(cpos) => {
if (cpos.x + self.computed_x < root.margin) {
self.computed_x = - cpos.x + root.margin;
} else if (cpos.x + self.computed_x > parent.width - root.margin) {
self.computed_x = parent.width - cpos.x - root.margin;
}
}
accepted => { root.accepted(self.text); }
edited => { root.edited(self.text); }
}
}