Skip to content

Commit

Permalink
Give focus back (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton authored Mar 17, 2024
1 parent 77a3bae commit 0bf0a29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 0bf0a29

Please sign in to comment.