Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't change focus to on_click under other on_click #379

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ impl<'a> EventCx<'a> {
return EventPropagation::Stop;
}

let mut is_down_and_has_click = false;

match &event {
Event::PointerDown(event) => {
self.app_state.clicking.insert(id);
Expand All @@ -723,6 +725,7 @@ impl<'a> EventCx<'a> {
if self.has_event_listener(id, EventListener::Click) {
let view_state = self.app_state.view_state(id);
view_state.last_pointer_down = Some(event.clone());
is_down_and_has_click = true;
}

let bottom_left = {
Expand Down Expand Up @@ -945,6 +948,10 @@ impl<'a> EventCx<'a> {
}
}

if is_down_and_has_click {
return EventPropagation::Stop;
}

EventPropagation::Continue
}

Expand Down
16 changes: 16 additions & 0 deletions src/window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,22 @@ impl WindowHandle {
}
}
}

if let Event::PointerDown(event) = &event {
if cx.app_state.focus.is_none() {
if let Some(id) = was_focused {
let layout = cx.app_state.get_layout_rect(id);
if layout.contains(event.pos) {
// if the event is pointer down
// and the focus hasn't been set to anything new
// and the pointer down event is inside the previously focusd view
// we then set the focus back to that view
cx.app_state.focus = Some(id);
}
}
}
}

if was_focused != cx.app_state.focus {
cx.app_state.focus_changed(was_focused, cx.app_state.focus);
}
Expand Down
Loading