diff --git a/CHANGELOG.md b/CHANGELOG.md index dd29e645..f71fd7a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,10 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w * Added linked axis support for plots via `plot::LinkedAxisGroup` ([#1184](https://github.com/emilk/egui/pull/1184)). * Added `Response::on_hover_text_at_pointer` as a convenience akin to `Response::on_hover_text` ([1179](https://github.com/emilk/egui/pull/1179)). * Added `ui.weak(text)`. +* Added `Context::move_to_top` and `Context::top_most_layer` for managing the layer on the top ([#1242](https://github.com/emilk/egui/pull/1242)). * Added plot pointer coordinates with `Plot::coordinates_formatter`. ([#1235](https://github.com/emilk/egui/pull/1235)). * Added `Slider::step_by` ([1255](https://github.com/emilk/egui/pull/1225)). -* Added ability to scroll an UI into view without specifying an alignment ([1247](https://github.com/emilk/egui/pull/1247)) +* Added ability to scroll an UI into view without specifying an alignment ([1247](https://github.com/emilk/egui/pull/1247)). ### Changed 🔧 * ⚠️ `Context::input` and `Ui::input` now locks a mutex. This can lead to a dead-lock is used in an `if let` binding! diff --git a/egui/src/context.rs b/egui/src/context.rs index 3695b91c..8e50432c 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -889,6 +889,17 @@ impl Context { self.memory().layer_id_at(pos, resize_grab_radius_side) } + /// The overall top-most layer. When an area is clicked on or interacted + /// with, it is moved above all other areas. + pub fn top_most_layer(&self) -> Option { + self.memory().top_most_layer() + } + + /// Moves the given area to the top. + pub fn move_to_top(&self, layer_id: LayerId) { + self.memory().areas.move_to_top(layer_id); + } + pub(crate) fn rect_contains_pointer(&self, layer_id: LayerId, rect: Rect) -> bool { let pointer_pos = self.input().pointer.interact_pos(); if let Some(pointer_pos) = pointer_pos { diff --git a/egui/src/memory.rs b/egui/src/memory.rs index b5cdfe7b..80eb1f15 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -329,6 +329,12 @@ impl Memory { self.areas.layer_id_at(pos, resize_interact_radius_side) } + /// The overall top-most layer. When an area is clicked on or interacted + /// with, it is moved above all other areas. + pub fn top_most_layer(&self) -> Option { + self.areas.order().last().copied() + } + pub(crate) fn had_focus_last_frame(&self, id: Id) -> bool { self.interaction.focus.id_previous_frame == Some(id) }