From 0551a2dde260168db84d5427969bbf932a2a172a Mon Sep 17 00:00:00 2001 From: Friz64 Date: Sat, 12 Feb 2022 12:24:03 +0100 Subject: [PATCH 1/3] Add `move_to_top` and `top_most_layer` --- egui/src/context.rs | 10 ++++++++++ egui/src/memory.rs | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/egui/src/context.rs b/egui/src/context.rs index 3695b91c026e..497bd24788ca 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -889,6 +889,16 @@ impl Context { self.memory().layer_id_at(pos, resize_grab_radius_side) } + /// Top-most layer. + 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 4809f2de5145..33ab1edd6193 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -329,6 +329,11 @@ impl Memory { self.areas.layer_id_at(pos, resize_interact_radius_side) } + /// Top-most layer. + 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) } From 2f990ea00019dfbfdd28df8176b280ae2b3e5b55 Mon Sep 17 00:00:00 2001 From: Friz64 Date: Sat, 12 Feb 2022 12:33:41 +0100 Subject: [PATCH 2/3] Changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eeb02be9a551..5e7d4b7aab59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ 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)). ### Changed 🔧 * ⚠️ `Context::input` and `Ui::input` now locks a mutex. This can lead to a dead-lock is used in an `if let` binding! From 205561f7a5840b9ef84e31a65fde78a063713997 Mon Sep 17 00:00:00 2001 From: Friz64 Date: Sun, 13 Feb 2022 09:30:17 +0100 Subject: [PATCH 3/3] Improve documentation of `top_most_layer` --- egui/src/context.rs | 3 ++- egui/src/memory.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/egui/src/context.rs b/egui/src/context.rs index 497bd24788ca..8e50432c3ce1 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -889,7 +889,8 @@ impl Context { self.memory().layer_id_at(pos, resize_grab_radius_side) } - /// Top-most layer. + /// 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() } diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 33ab1edd6193..ea9869a50190 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -329,7 +329,8 @@ impl Memory { self.areas.layer_id_at(pos, resize_interact_radius_side) } - /// Top-most layer. + /// 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() }