From 088300b3598215626fe1538317156720a11988cb Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Wed, 3 Mar 2021 14:52:18 -0500 Subject: [PATCH] Relax constraints on who can change focus Instead of just the focus widget this is now available to any of that widget's direct ancestors (such as a controller). This is needed for the new TextBox, since the widget with the logic (TextBox) is not the widget that necessarily has focus (the SharedComponent). --- druid/src/contexts.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/druid/src/contexts.rs b/druid/src/contexts.rs index 0c80957302..9ed3b4084f 100644 --- a/druid/src/contexts.rs +++ b/druid/src/contexts.rs @@ -576,10 +576,13 @@ impl EventCtx<'_, '_> { /// [`is_focused`]: struct.EventCtx.html#method.is_focused pub fn focus_next(&mut self) { trace!("focus_next"); - if self.is_focused() { + if self.has_focus() { self.widget_state.request_focus = Some(FocusChange::Next); } else { - warn!("focus_next can only be called by the currently focused widget"); + warn!( + "focus_next can only be called by the currently \ + focused widget or one of its ancestors." + ); } } @@ -592,10 +595,13 @@ impl EventCtx<'_, '_> { /// [`is_focused`]: struct.EventCtx.html#method.is_focused pub fn focus_prev(&mut self) { trace!("focus_prev"); - if self.is_focused() { + if self.has_focus() { self.widget_state.request_focus = Some(FocusChange::Previous); } else { - warn!("focus_prev can only be called by the currently focused widget"); + warn!( + "focus_prev can only be called by the currently \ + focused widget or one of its ancestors." + ); } } @@ -608,11 +614,12 @@ impl EventCtx<'_, '_> { /// [`is_focused`]: struct.EventCtx.html#method.is_focused pub fn resign_focus(&mut self) { trace!("resign_focus"); - if self.is_focused() { + if self.has_focus() { self.widget_state.request_focus = Some(FocusChange::Resign); } else { warn!( - "resign_focus can only be called by the currently focused widget ({:?})", + "resign_focus can only be called by the currently focused widget \ + or one of its ancestors. ({:?})", self.widget_id() ); }