From b80c23fd9423a8ce4a168779ec753970311be50f Mon Sep 17 00:00:00 2001 From: edwloef Date: Tue, 11 Feb 2025 15:47:08 +0100 Subject: add unfocus operation --- core/src/widget/operation/focusable.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'core/src') diff --git a/core/src/widget/operation/focusable.rs b/core/src/widget/operation/focusable.rs index 8f66e575..cb0c7845 100644 --- a/core/src/widget/operation/focusable.rs +++ b/core/src/widget/operation/focusable.rs @@ -61,6 +61,33 @@ pub fn focus(target: Id) -> impl Operation { Focus { target } } +/// Produces an [`Operation`] that unfocuses the focused widget +pub fn unfocus() -> impl Operation { + struct Unfocus; + + impl Operation for Unfocus { + fn focusable( + &mut self, + _id: Option<&Id>, + _bounds: Rectangle, + state: &mut dyn Focusable, + ) { + state.unfocus(); + } + + fn container( + &mut self, + _id: Option<&Id>, + _bounds: Rectangle, + operate_on_children: &mut dyn FnMut(&mut dyn Operation), + ) { + operate_on_children(self); + } + } + + Unfocus +} + /// Produces an [`Operation`] that generates a [`Count`] and chains it with the /// provided function to build a new [`Operation`]. pub fn count() -> impl Operation { -- cgit