Skip to content

Commit

Permalink
Fix bug in determining wether to remove focus from a widget (#4272)
Browse files Browse the repository at this point in the history
* Closes #4206
  • Loading branch information
emilk authored Mar 30, 2024
1 parent 810135c commit a7c5eb4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,8 +1113,6 @@ impl Context {
changed: false,
};

let clicked_elsewhere = res.clicked_elsewhere();

self.write(|ctx| {
let viewport = ctx.viewports.entry(ctx.viewport_id()).or_default();

Expand Down Expand Up @@ -1157,15 +1155,22 @@ impl Context {
}

let clicked = Some(id) == viewport.interact_widgets.clicked;
let mut any_press = false;

for pointer_event in &input.pointer.pointer_events {
if let PointerEvent::Released { click, .. } = pointer_event {
if enabled && sense.click && clicked && click.is_some() {
res.clicked = true;
match pointer_event {
PointerEvent::Moved(_) => {}
PointerEvent::Pressed { .. } => {
any_press = true;
}
PointerEvent::Released { click, .. } => {
if enabled && sense.click && clicked && click.is_some() {
res.clicked = true;
}

res.is_pointer_button_down_on = false;
res.dragged = false;
res.is_pointer_button_down_on = false;
res.dragged = false;
}
}
}

Expand All @@ -1188,14 +1193,10 @@ impl Context {
res.hovered = false;
}

if clicked_elsewhere && memory.has_focus(id) {
let pointer_pressed_elsewhere = any_press && !res.hovered;
if pointer_pressed_elsewhere && memory.has_focus(id) {
memory.surrender_focus(id);
}

if res.dragged() && !memory.has_focus(id) {
// e.g.: remove focus from a widget when you drag something else
memory.stop_text_input();
}
});

res
Expand Down

0 comments on commit a7c5eb4

Please sign in to comment.