diff --git a/sixtyfps_compiler/typeregister.rs b/sixtyfps_compiler/typeregister.rs index ab7906a77..0194d0cb9 100644 --- a/sixtyfps_compiler/typeregister.rs +++ b/sixtyfps_compiler/typeregister.rs @@ -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![] }), ], &[ diff --git a/sixtyfps_compiler/widgets/native/sixtyfps_widgets.60 b/sixtyfps_compiler/widgets/native/sixtyfps_widgets.60 index 059e14cd0..1e23adce4 100644 --- a/sixtyfps_compiler/widgets/native/sixtyfps_widgets.60 +++ b/sixtyfps_compiler/widgets/native/sixtyfps_widgets.60 @@ -24,7 +24,7 @@ export GroupBox := NativeGroupBox { } export LineEdit := NativeLineEdit { property text; - property focused: true; + property has_focus: true; property accepted_text: input.text; // FIXME: remove when we can do two-way bindings signal accepted(string); GridLayout { diff --git a/sixtyfps_compiler/widgets/ugly/sixtyfps_widgets.60 b/sixtyfps_compiler/widgets/ugly/sixtyfps_widgets.60 index 935be7d3a..3539ef8dd 100644 --- a/sixtyfps_compiler/widgets/ugly/sixtyfps_widgets.60 +++ b/sixtyfps_compiler/widgets/ugly/sixtyfps_widgets.60 @@ -239,10 +239,10 @@ export GroupBox := GridLayout { export LineEdit := Rectangle { property text; property accepted_text: input.text; // FIXME: remove when we can do two-way bindings - property focused: true; + property 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; diff --git a/sixtyfps_runtime/corelib/items.rs b/sixtyfps_runtime/corelib/items.rs index 229d7b388..4d7ac4ced 100644 --- a/sixtyfps_runtime/corelib/items.rs +++ b/sixtyfps_runtime/corelib/items.rs @@ -889,6 +889,7 @@ pub struct TextInput { pub anchor_position: Property, // byte offset pub text_cursor_width: Property, pub cursor_visible: Property, + pub has_focus: Property, pub accepted: Signal<()>, pub pressed: std::cell::Cell, 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() + } } } } diff --git a/tests/cases/focus_change.60 b/tests/cases/focus_change.60 index cc4eab721..ac7765239 100644 --- a/tests/cases/focus_change.60 +++ b/tests/cases/focus_change.60 @@ -22,9 +22,9 @@ TestCase := Rectangle { height: 200px; } - property input1_focused: input1.focused; + property input1_focused: input1.has_focus; property input1_text: input1.text; - property input2_focused: input2.focused; + property input2_focused: input2.has_focus; property input2_text: input2.text; } diff --git a/tests/cases/textinput_cursor_move.60 b/tests/cases/textinput_cursor_move.60 index 1449574d1..e3271cf11 100644 --- a/tests/cases/textinput_cursor_move.60 +++ b/tests/cases/textinput_cursor_move.60 @@ -14,7 +14,7 @@ TestCase := TextInput { property test_cursor_pos: self.cursor_position; property test_anchor_pos: self.anchor_position; property has_selection: self.cursor_position != self.anchor_position; - property input_focused: self.focused; + property input_focused: self.has_focus; } /* diff --git a/tests/cases/textinput_surrogate_cursor.60 b/tests/cases/textinput_surrogate_cursor.60 index 1bbdecf90..cde340a41 100644 --- a/tests/cases/textinput_surrogate_cursor.60 +++ b/tests/cases/textinput_surrogate_cursor.60 @@ -14,7 +14,7 @@ TestCase := TextInput { property test_cursor_pos: self.cursor_position; property test_anchor_pos: self.anchor_position; property has_selection: self.cursor_position != self.anchor_position; - property input_focused: self.focused; + property input_focused: self.has_focus; } /*