1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 14:49:06 -04:00

Improve UiBuilder docs (#8132)

Previously, the doc for `Ui::scope_builder` read

> Create a child, add content to it, and then allocate only what was
used in the parent `Ui`.

which I understood as meaning that "only what was used in the parent
`UI`" would be allocated (in the child or parent), which makes no sense
(in either case).

I rewrote it and some related docs.

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Josie Elliston
2026-05-26 06:53:55 -07:00
committed by GitHub
parent 8d5a7b4557
commit 37a7ee448a
2 changed files with 10 additions and 3 deletions

View File

@@ -2180,11 +2180,16 @@ impl Ui {
/// }); /// });
/// # }); /// # });
/// ``` /// ```
///
/// See also [`Self::scope_builder`] for more options.
pub fn scope<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> { pub fn scope<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
self.scope_dyn(UiBuilder::new(), Box::new(add_contents)) self.scope_dyn(UiBuilder::new(), Box::new(add_contents))
} }
/// Create a child, add content to it, and then allocate only what was used in the parent `Ui`. /// Create a scoped child ui, inheriting properties from the parent as specified by the [`UiBuilder`].
/// In contrast to [`Self::new_child`], this allocates the space used by the child.
///
/// See also [`Self::scope`] and [`Self::scope_dyn`].
pub fn scope_builder<R>( pub fn scope_builder<R>(
&mut self, &mut self,
ui_builder: UiBuilder, ui_builder: UiBuilder,
@@ -2193,7 +2198,7 @@ impl Ui {
self.scope_dyn(ui_builder, Box::new(add_contents)) self.scope_dyn(ui_builder, Box::new(add_contents))
} }
/// Create a child, add content to it, and then allocate only what was used in the parent `Ui`. /// [`Self::scope_builder`] but with dynamic dispatch.
pub fn scope_dyn<'c, R>( pub fn scope_dyn<'c, R>(
&mut self, &mut self,
ui_builder: UiBuilder, ui_builder: UiBuilder,

View File

@@ -7,11 +7,13 @@ use crate::{
widget_style::{Classes, HasClasses}, widget_style::{Classes, HasClasses},
}; };
/// Build a [`Ui`] as the child of another [`Ui`]. /// The properties specified when creating a top-level or child [`Ui`].
/// ///
/// By default, everything is inherited from the parent, /// By default, everything is inherited from the parent,
/// except for `max_rect` which by default is set to /// except for `max_rect` which by default is set to
/// the parent [`Ui::available_rect_before_wrap`]. /// the parent [`Ui::available_rect_before_wrap`].
///
/// See also [`Ui::new`] and [`Ui::new_child`] for uses.
#[must_use] #[must_use]
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct UiBuilder { pub struct UiBuilder {