fix: widget unfocus on mouse click

This commit is contained in:
Michael Aaron Murphy 2024-07-20 05:55:03 +02:00 committed by Michael Murphy
parent 6f2c893cf5
commit 5474232796
3 changed files with 3 additions and 44 deletions

View file

@ -17,7 +17,6 @@ pub enum Message {
FocusNext,
FocusPrevious,
Fullscreen,
Unfocus,
Search,
}
@ -59,42 +58,9 @@ pub fn subscription() -> Subscription<Message> {
return Some(Message::Search);
}
Event::Mouse(mouse::Event::ButtonPressed { .. }) => {
return Some(Message::Unfocus);
}
_ => (),
}
None
})
}
/// Unfocuses any actively-focused widget.
pub fn unfocus<Message: 'static>() -> Command<Message> {
Command::<Message>::widget(unfocus_operation())
}
#[must_use]
fn unfocus_operation<T>() -> impl Operation<T> {
struct Unfocus {}
impl<T> Operation<T> for Unfocus {
fn focusable(&mut self, state: &mut dyn operation::Focusable, _id: Option<&Id>) {
if state.is_focused() {
state.unfocus();
}
}
fn container(
&mut self,
_id: Option<&Id>,
_bounds: Rectangle,
operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
) {
operate_on_children(self);
}
}
Unfocus {}
}