Skip to content

Commit

Permalink
Add UiBuilder::layer_id
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 30, 2024
1 parent 15d3d43 commit 9782997
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl Ui {
let UiBuilder {
id_salt,
ui_stack_info,
layer_id,
max_rect,
layout,
disabled,
Expand All @@ -262,6 +263,9 @@ impl Ui {
let max_rect = max_rect.unwrap_or_else(|| self.available_rect_before_wrap());
let mut layout = layout.unwrap_or(*self.layout());
let enabled = self.enabled && !disabled && !invisible;
if let Some(layer_id) = layer_id {
painter.set_layer_id(layer_id);
}
if invisible {
painter.set_invisible();
}
Expand Down Expand Up @@ -2311,10 +2315,7 @@ impl Ui {
layer_id: LayerId,
add_contents: impl FnOnce(&mut Self) -> R,
) -> InnerResponse<R> {
self.scope(|ui| {
ui.painter.set_layer_id(layer_id);
add_contents(ui)
})
self.scope_builder(UiBuilder::new().layer_id(layer_id), add_contents)
}

/// A [`CollapsingHeader`] that starts out collapsed.
Expand Down
10 changes: 9 additions & 1 deletion crates/egui/src/ui_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{hash::Hash, sync::Arc};

use crate::{Id, Layout, Rect, Sense, Style, UiStackInfo};
use crate::{Id, LayerId, Layout, Rect, Sense, Style, UiStackInfo};

#[allow(unused_imports)] // Used for doclinks
use crate::Ui;
Expand All @@ -15,6 +15,7 @@ use crate::Ui;
pub struct UiBuilder {
pub id_salt: Option<Id>,
pub ui_stack_info: UiStackInfo,
pub layer_id: Option<LayerId>,
pub max_rect: Option<Rect>,
pub layout: Option<Layout>,
pub disabled: bool,
Expand Down Expand Up @@ -48,6 +49,13 @@ impl UiBuilder {
self
}

/// Show the [`Ui`] in a different [`LayerId`] from its parent.
#[inline]
pub fn layer_id(mut self, layer_id: LayerId) -> Self {
self.layer_id = Some(layer_id);
self
}

/// Set the max rectangle, within which widgets will go.
///
/// New widgets will *try* to fit within this rectangle.
Expand Down

0 comments on commit 9782997

Please sign in to comment.