diff --git a/examples/focus.rs b/examples/focus.rs index de9e0af..20a030a 100644 --- a/examples/focus.rs +++ b/examples/focus.rs @@ -20,7 +20,7 @@ fn main() -> gooey::Result { .on_accept_focus(|context| context.enabled()) .on_redraw(|context| { context.fill(context.theme().secondary.color); - if context.focused() { + if context.focused(true) { context.draw_focus_ring(); } }) diff --git a/src/context.rs b/src/context.rs index c898c88..20a16d0 100644 --- a/src/context.rs +++ b/src/context.rs @@ -979,7 +979,7 @@ impl<'context, 'window> WidgetContext<'context, 'window> { /// Widget events relating to focus changes are deferred until after the all /// contexts for the currently firing event are dropped. pub fn blur(&mut self) -> bool { - if self.focused() { + if self.focused(true) { self.clear_focus(); true } else { @@ -1052,8 +1052,9 @@ impl<'context, 'window> WidgetContext<'context, 'window> { /// Returns true if this widget is currently focused for user input. #[must_use] - pub fn focused(&self) -> bool { + pub fn focused(&self, check_window: bool) -> bool { self.pending_state.focus == Some(self.current_node.id()) + && (!check_window || self.window.focused().get_tracking_refresh(self)) } /// Returns true if this widget is the target to activate when the user diff --git a/src/widgets/button.rs b/src/widgets/button.rs index 2c71fed..da49aa6 100644 --- a/src/widgets/button.rs +++ b/src/widgets/button.rs @@ -343,7 +343,7 @@ impl Widget for Button { let two_lp_stroke = StrokeOptions::lp_wide(Lp::points(2)); context.stroke_outline(style.outline, two_lp_stroke); - if context.focused() { + if context.focused(true) { if current_style == ButtonKind::Transparent { let two_lp_stroke = two_lp_stroke.into_px(context.gfx.scale()); let focus_color = context.get(&HighlightColor); diff --git a/src/widgets/input.rs b/src/widgets/input.rs index 496bab1..c4f21fe 100644 --- a/src/widgets/input.rs +++ b/src/widgets/input.rs @@ -1023,7 +1023,7 @@ where let cache = self.layout_text(Some(size.width.into_signed()), context); - let highlight = if context.focused() && window_focused { + let highlight = if context.focused(false) && window_focused { context.draw_focus_ring(); context.get(&HighlightColor) } else { @@ -1032,7 +1032,7 @@ where outline_color }; - if context.focused() { + if context.focused(false) { context.set_ime_allowed(true); context.set_ime_purpose(if cache.masked { ImePurpose::Password diff --git a/src/widgets/slider.rs b/src/widgets/slider.rs index d89eeae..8699e12 100644 --- a/src/widgets/slider.rs +++ b/src/widgets/slider.rs @@ -219,7 +219,7 @@ where // Draw the knob if spec.knob_size > 0 { - let focus = context.focused().then_some(self.focused_knob).flatten(); + let focus = context.focused(true).then_some(self.focused_knob).flatten(); Self::draw_knobs( self.flip_pt_if_vertical(Point::new(end + spec.half_knob, spec.half_knob) + inset), spec.end.map(|_| {