Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add move_to_top and top_most_layer #1242

Merged
merged 5 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
10 changes: 10 additions & 0 deletions egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,16 @@ impl Context {
self.memory().layer_id_at(pos, resize_grab_radius_side)
}

/// Top-most layer.
Copy link
Contributor

@Mingun Mingun Feb 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see an explanation, what is the top-most layer instead of this useless doc. The doc should answer to question when I should use it? What is its features? What this layer is contain?

Copy link
Contributor Author

@Friz64 Friz64 Feb 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

Returns the id of the top-most area. When an area is clicked on or interacted with, it will be moved above all other areas.

My personal use case is synchronizing the selected item in a list of open windows with the window that last got focus. This is a very specific use case, but it wasn't possible to do before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit changing it to

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<LayerId> {
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 {
Expand Down
5 changes: 5 additions & 0 deletions egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ impl Memory {
self.areas.layer_id_at(pos, resize_interact_radius_side)
}

/// Top-most layer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

pub fn top_most_layer(&self) -> Option<LayerId> {
self.areas.order().last().copied()
}

pub(crate) fn had_focus_last_frame(&self, id: Id) -> bool {
self.interaction.focus.id_previous_frame == Some(id)
}
Expand Down