mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Expose the focused property on TextInput correctly
As per #55 introduce a has_focus property on the TextInput.
This commit is contained in:
parent
e5dfb3a4c0
commit
acb6eddeaf
7 changed files with 18 additions and 10 deletions
|
@ -648,6 +648,7 @@ impl TypeRegister {
|
|||
("text_cursor_width", Type::Length),
|
||||
("cursor_position", Type::Int32),
|
||||
("anchor_position", Type::Int32),
|
||||
("has_focus", Type::Bool),
|
||||
("accepted", Type::Signal { args: vec![] }),
|
||||
],
|
||||
&[
|
||||
|
|
|
@ -24,7 +24,7 @@ export GroupBox := NativeGroupBox {
|
|||
}
|
||||
export LineEdit := NativeLineEdit {
|
||||
property <string> text;
|
||||
property <bool> focused: true;
|
||||
property <bool> has_focus: true;
|
||||
property <string> accepted_text: input.text; // FIXME: remove when we can do two-way bindings
|
||||
signal accepted(string);
|
||||
GridLayout {
|
||||
|
|
|
@ -239,10 +239,10 @@ export GroupBox := GridLayout {
|
|||
export LineEdit := Rectangle {
|
||||
property <string> text;
|
||||
property <string> accepted_text: input.text; // FIXME: remove when we can do two-way bindings
|
||||
property <bool> focused: true;
|
||||
property <bool> has_focus: input.has_focus;
|
||||
signal accepted(string);
|
||||
|
||||
border_color: root.focused ? #556884 : #ffffff;
|
||||
border_color: root.has_focus ? #556884 : #ffffff;
|
||||
border_radius: 1lx;
|
||||
border_width: 2lx;
|
||||
|
||||
|
|
|
@ -889,6 +889,7 @@ pub struct TextInput {
|
|||
pub anchor_position: Property<i32>, // byte offset
|
||||
pub text_cursor_width: Property<f32>,
|
||||
pub cursor_visible: Property<bool>,
|
||||
pub has_focus: Property<bool>,
|
||||
pub accepted: Signal<()>,
|
||||
pub pressed: std::cell::Cell<bool>,
|
||||
pub cached_rendering_data: CachedRenderingData,
|
||||
|
@ -1006,7 +1007,7 @@ impl Item for TextInput {
|
|||
self.as_ref().pressed.set(true);
|
||||
self.as_ref().anchor_position.set(clicked_offset);
|
||||
self.as_ref().cursor_position.set(clicked_offset);
|
||||
if !Self::FIELD_OFFSETS.focused.apply_pin(self).get() {
|
||||
if !Self::FIELD_OFFSETS.has_focus.apply_pin(self).get() {
|
||||
window.set_focus_item(app_component, self);
|
||||
}
|
||||
}
|
||||
|
@ -1098,8 +1099,14 @@ impl Item for TextInput {
|
|||
|
||||
fn focus_event(self: Pin<&Self>, event: &FocusEvent, window: &ComponentWindow) {
|
||||
match event {
|
||||
FocusEvent::FocusIn(_) | FocusEvent::WindowReceivedFocus => self.show_cursor(window),
|
||||
FocusEvent::FocusOut | FocusEvent::WindowLostFocus => self.hide_cursor(),
|
||||
FocusEvent::FocusIn(_) | FocusEvent::WindowReceivedFocus => {
|
||||
self.has_focus.set(true);
|
||||
self.show_cursor(window);
|
||||
}
|
||||
FocusEvent::FocusOut | FocusEvent::WindowLostFocus => {
|
||||
self.has_focus.set(false);
|
||||
self.hide_cursor()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ TestCase := Rectangle {
|
|||
height: 200px;
|
||||
}
|
||||
|
||||
property<bool> input1_focused: input1.focused;
|
||||
property<bool> input1_focused: input1.has_focus;
|
||||
property<string> input1_text: input1.text;
|
||||
property<bool> input2_focused: input2.focused;
|
||||
property<bool> input2_focused: input2.has_focus;
|
||||
property<string> input2_text: input2.text;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ TestCase := TextInput {
|
|||
property<int> test_cursor_pos: self.cursor_position;
|
||||
property<int> test_anchor_pos: self.anchor_position;
|
||||
property<bool> has_selection: self.cursor_position != self.anchor_position;
|
||||
property<bool> input_focused: self.focused;
|
||||
property<bool> input_focused: self.has_focus;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -14,7 +14,7 @@ TestCase := TextInput {
|
|||
property<int> test_cursor_pos: self.cursor_position;
|
||||
property<int> test_anchor_pos: self.anchor_position;
|
||||
property<bool> has_selection: self.cursor_position != self.anchor_position;
|
||||
property<bool> input_focused: self.focused;
|
||||
property<bool> input_focused: self.has_focus;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue