Skip to content

Commit 2a3bc3f

Browse files
authored
nuon: Clear focus of dead widgets (#414)
1 parent 38c9013 commit 2a3bc3f

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

nuon/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub struct ImageRenderElement {
274274
pub struct Ui {
275275
pub hovered: Option<Id>,
276276
pub active: Option<Id>,
277+
pub active_widget_is_still_alive: bool,
277278

278279
pointer_pos: Point,
279280
pointer_pos_delta: Point,
@@ -296,6 +297,7 @@ impl Ui {
296297
Self {
297298
hovered: None,
298299
active: None,
300+
active_widget_is_still_alive: false,
299301
pointer_pos: Point::new(-1.0, -1.0),
300302
pointer_pos_delta: Point::new(0.0, 0.0),
301303
mouse_pressed: false,
@@ -337,6 +339,12 @@ impl Ui {
337339
self.layers.clear();
338340
self.mouse_pressed = false;
339341
self.pointer_pos_delta = Point::zero();
342+
if std::mem::take(&mut self.active_widget_is_still_alive) {
343+
// Active widget will overwrite this to true if it is still alive next frame
344+
} else {
345+
// Active widget died
346+
self.active = None;
347+
}
340348
}
341349
}
342350

@@ -936,11 +944,16 @@ impl ClickArea {
936944

937945
if ui.mouse_pressed && mouseover && ui.active.is_none() {
938946
ui.active = Some(id);
947+
ui.active_widget_is_still_alive = true;
939948
return ClickAreaEvent::PressStart;
940949
}
941950

942951
let pressed = ui.active == Some(id);
943952

953+
if pressed {
954+
ui.active_widget_is_still_alive = true;
955+
}
956+
944957
if !ui.mouse_down && pressed {
945958
ui.active = None;
946959
ClickAreaEvent::PressEnd { clicked: mouseover }

0 commit comments

Comments
 (0)