mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
LineEdit: fixes cursor draws out of bounds (#6382)
This commit is contained in:
parent
2e15a35afe
commit
b3f19e446e
5 changed files with 147 additions and 141 deletions
|
@ -3,68 +3,69 @@
|
|||
|
||||
export component LineEditBase inherits Rectangle {
|
||||
in property <string> placeholder-text;
|
||||
in property <length> font-size <=> i-text-input.font-size;
|
||||
in-out property <string> text <=> i-text-input.text;
|
||||
in property <length> font-size <=> text-input.font-size;
|
||||
in-out property <string> text <=> text-input.text;
|
||||
in-out property <brush> placeholder-color;
|
||||
in property <bool> enabled <=> i-text-input.enabled;
|
||||
out property <bool> has-focus: i-text-input.has-focus;
|
||||
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 <int> font-weight <=> i-text-input.font-weight;
|
||||
in property <bool> enabled <=> text-input.enabled;
|
||||
out property <bool> has-focus: text-input.has-focus;
|
||||
in property <InputType> input-type <=> text-input.input-type;
|
||||
in property <TextHorizontalAlignment> horizontal-alignment <=> text-input.horizontal-alignment;
|
||||
in property <bool> read-only <=> text-input.read-only;
|
||||
in property <int> font-weight <=> 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 <color> selection-background-color <=> text-input.selection-background-color;
|
||||
in property <color> selection-foreground-color <=> text-input.selection-foreground-color;
|
||||
in property <length> margin;
|
||||
|
||||
callback accepted( /* text */ string);
|
||||
callback accepted(/* text */ string);
|
||||
callback edited(/* text */ string);
|
||||
|
||||
public function set-selection-offsets(start: int, end: int) {
|
||||
i-text-input.set-selection-offsets(start, end);
|
||||
text-input.set-selection-offsets(start, end);
|
||||
}
|
||||
|
||||
public function select-all() {
|
||||
i-text-input.select-all();
|
||||
text-input.select-all();
|
||||
}
|
||||
|
||||
public function clear-selection() {
|
||||
i-text-input.clear-selection();
|
||||
text-input.clear-selection();
|
||||
}
|
||||
|
||||
public function cut() {
|
||||
i-text-input.cut();
|
||||
text-input.cut();
|
||||
}
|
||||
|
||||
public function copy() {
|
||||
i-text-input.copy();
|
||||
text-input.copy();
|
||||
}
|
||||
|
||||
public function paste() {
|
||||
i-text-input.paste();
|
||||
text-input.paste();
|
||||
}
|
||||
|
||||
min-height: i-text-input.preferred-height;
|
||||
min-width: max(50px, i-placeholder.min-width);
|
||||
// on width < 1px or if the `TextInput` is clipped it cannot be focused therefore min-width 1px
|
||||
min-width: 1px;
|
||||
min-height: text-input.preferred-height;
|
||||
clip: true;
|
||||
forward-focus: i-text-input;
|
||||
forward-focus: text-input;
|
||||
|
||||
i-placeholder := Text {
|
||||
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;
|
||||
text: (root.text == "" && text-input.preedit-text == "") ? root.placeholder-text : "";
|
||||
font-size: text-input.font-size;
|
||||
font-italic: text-input.font-italic;
|
||||
font-weight: text-input.font-weight;
|
||||
font-family: text-input.font-family;
|
||||
color: root.placeholder-color;
|
||||
horizontal-alignment: root.horizontal-alignment;
|
||||
// the label is set on the LineEdit itself
|
||||
accessible-role: none;
|
||||
}
|
||||
|
||||
i-text-input := TextInput {
|
||||
text-input := TextInput {
|
||||
property <length> computed-x;
|
||||
|
||||
x: min(0px, max(parent.width - self.width - self.text-cursor-width, self.computed-x));
|
||||
|
@ -74,16 +75,20 @@ export component LineEditBase inherits Rectangle {
|
|||
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.text-cursor-width) {
|
||||
self.computed_x = parent.width - cpos.x - root.margin - self.text-cursor-width;
|
||||
cursor-position-changed(cursor-position) => {
|
||||
if cursor-position.x + self.computed_x < root.margin {
|
||||
self.computed_x = - cursor-position.x + root.margin;
|
||||
} else if cursor-position.x + self.computed_x > parent.width - root.margin - self.text-cursor-width {
|
||||
self.computed_x = parent.width - cursor-position.x - root.margin - self.text-cursor-width;
|
||||
}
|
||||
}
|
||||
|
||||
accepted => { root.accepted(self.text); }
|
||||
accepted => {
|
||||
root.accepted(self.text);
|
||||
}
|
||||
|
||||
edited => { root.edited(self.text); }
|
||||
edited => {
|
||||
root.edited(self.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue