fix: widget unfocus on mouse click
This commit is contained in:
parent
6f2c893cf5
commit
5474232796
3 changed files with 3 additions and 44 deletions
|
|
@ -371,9 +371,6 @@ impl<T: Application> Cosmic<T> {
|
|||
}
|
||||
|
||||
Message::KeyboardNav(message) => match message {
|
||||
keyboard_nav::Message::Unfocus => {
|
||||
return keyboard_nav::unfocus().map(super::Message::Cosmic)
|
||||
}
|
||||
keyboard_nav::Message::FocusNext => {
|
||||
return iced::widget::focus_next().map(super::Message::Cosmic)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1210,19 +1210,15 @@ where
|
|||
let state = state();
|
||||
let is_clicked = cursor_position.is_over(text_layout.bounds()) && on_input.is_some();
|
||||
|
||||
state.is_focused = if is_clicked {
|
||||
state.is_focused.or_else(|| {
|
||||
if is_clicked {
|
||||
state.is_focused = state.is_focused.or_else(|| {
|
||||
let now = Instant::now();
|
||||
Some(Focus {
|
||||
updated_at: now,
|
||||
now,
|
||||
})
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
});
|
||||
|
||||
if is_clicked {
|
||||
let Some(pos) = cursor_position.position() else {
|
||||
return event::Status::Ignored;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue