Skip to main content

UiBuilder

Struct UiBuilder 

Source
pub struct UiBuilder {
Show 14 fields pub id_source: Option<IdSource>, pub ui_stack_info: UiStackInfo, pub layer_id: Option<LayerId>, pub max_rect: Option<Rect>, pub layout: Option<Layout>, pub disabled: bool, pub invisible: bool, pub sizing_pass: bool, pub style: Option<Arc<Style>>, pub sense: Option<Sense>, pub accessibility_parent: Option<Id>, pub accessibility_label: Option<String>, pub accessibility_role: Option<Role>, pub classes: Classes,
}
Available on crate feature egui only.
Expand description

The properties specified when creating a top-level or child Ui.

By default, everything is inherited from the parent, except for max_rect which by default is set to the parent Ui::available_rect_before_wrap.

See also Ui::new and Ui::new_child for uses.

Fields§

§id_source: Option<IdSource>§ui_stack_info: UiStackInfo§layer_id: Option<LayerId>§max_rect: Option<Rect>§layout: Option<Layout>§disabled: bool§invisible: bool§sizing_pass: bool§style: Option<Arc<Style>>§sense: Option<Sense>§accessibility_parent: Option<Id>§accessibility_label: Option<String>§accessibility_role: Option<Role>§classes: Classes

Implementations§

Source§

impl UiBuilder

Source

pub fn new() -> UiBuilder

Source

pub fn id_salt(self, id_salt: impl AsIdSalt) -> UiBuilder

Seed the child Ui with this id_salt, which will be mixed with the Ui::scope_id of the parent.

You should give each Ui an id_salt that is unique within the parent, or give it none at all.

Source

pub fn scope_id(self, scope_id: Id) -> UiBuilder

Set the Ui::scope_id of the new Ui to something independent of the parent Ui. This way child widgets can be moved in the ui tree without losing state. You have to ensure that in a frame the child widgets do not get rendered in multiple places.

You should set the same unique scope_id at every place in the ui tree where you want the child widgets to share state. If the child widgets are not moved in the ui tree, use UiBuilder::id_salt instead.

The scope_id is also used as the Ui::unique_id of the new Ui, so it must be globally unique.

Source

pub fn id(self, id: Id) -> UiBuilder

👎Deprecated:

Renamed to UiBuilder::scope_id

Renamed to Self::scope_id.

Source

pub fn ui_stack_info(self, ui_stack_info: UiStackInfo) -> UiBuilder

Provide some information about the new Ui being built.

Source

pub fn layer_id(self, layer_id: LayerId) -> UiBuilder

Show the Ui in a different LayerId from its parent.

Source

pub fn max_rect(self, max_rect: Rect) -> UiBuilder

Set the max rectangle, within which widgets will go.

New widgets will try to fit within this rectangle.

Text labels will wrap to fit within max_rect. Separator lines will span the max_rect.

If a new widget doesn’t fit within the max_rect then the Ui will make room for it by expanding both min_rect and

If not set, this will be set to the parent Ui::available_rect_before_wrap.

Source

pub fn layout(self, layout: Layout) -> UiBuilder

Override the layout.

Will otherwise be inherited from the parent.

Source

pub fn disabled(self) -> UiBuilder

Make the new Ui disabled, i.e. grayed-out and non-interactive.

Note that if the parent Ui is disabled, the child will always be disabled.

See also crate::Ui::add_enabled, crate::Ui::add_enabled_ui and crate::Ui::is_enabled.

Source

pub fn invisible(self) -> UiBuilder

Make the contents invisible.

Will also disable the Ui (see Self::disabled).

If the parent Ui is invisible, the child will always be invisible.

Source

pub fn sizing_pass(self) -> UiBuilder

Set to true in special cases where we do one frame where we size up the contents of the Ui, without actually showing it.

If the sizing_pass flag is set on the parent, the child will inherit it automatically.

Source

pub fn style(self, style: impl Into<Arc<Style>>) -> UiBuilder

Override the style.

Otherwise will inherit the style of the parent.

Source

pub fn sense(self, sense: Sense) -> UiBuilder

Set if you want sense clicks and/or drags. Default is Sense::hover.

The sense will be registered below the Senses of any widgets contained in this Ui, so if the user clicks a button contained within this Ui, that button will receive the click instead.

The response can be read early with Ui::response.

Source

pub fn closable(self) -> UiBuilder

Make this Ui closable.

Calling Ui::close in a child Ui will mark this Ui for closing. After Ui::close was called, Ui::should_close and crate::Response::should_close will return true (for this frame).

This works by adding a ClosableTag to the UiStackInfo.

Source

pub fn accessibility_parent(self, parent_id: Id) -> UiBuilder

Set the accessibility parent for this Ui.

Pass Ui::unique_id or Response::id, not Ui::scope_id.

This will override the automatic parent assignment for accessibility purposes. If not set, the parent Ui’s ID will be used as the accessibility parent.

Source

pub fn accessibility_label(self, label: impl Into<String>) -> UiBuilder

Name this Ui in the accessibility tree.

Every Ui is a node there, with a role from its UiKind. A name lets a screen reader, or a test, tell this panel, popup or region from the others.

Source

pub fn accessibility_role(self, role: Role) -> UiBuilder

Give this Ui’s node a role other than the one its UiKind implies, e.g. Role::Alert for a toast.

Trait Implementations§

Source§

impl Clone for UiBuilder

Source§

fn clone(&self) -> UiBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for UiBuilder

Source§

fn default() -> UiBuilder

Returns the “default value” for a type. Read more
Source§

impl HasClasses for UiBuilder

Source§

fn classes(&self) -> &Classes

Source§

fn classes_mut(&mut self) -> &mut Classes

Source§

fn has_class(&self, class: &str) -> bool

True if the class is present.
Source§

fn add_class(&mut self, class: impl Into<ClassName>) -> &mut Self
where Self: Sized,

Add the given class in-place.
Source§

fn set_class(&mut self, class: impl Into<ClassName>, present: bool) -> &mut Self
where Self: Sized,

Add the given class in-place if present, remove it otherwise. Read more
Source§

fn remove_class(&mut self, class: impl Into<ClassName>) -> &mut Self
where Self: Sized,

Remove the given class in-place.
Source§

fn with_class(self, class: impl Into<ClassName>) -> Self
where Self: Sized,

Add the given class by consuming self.
Source§

fn add_classes(&mut self, classes: Classes) -> &mut Self

Append all the given classes at the end, deduplicating them.
Source§

fn with_classes(self, classes: Classes) -> Self
where Self: Sized,

Append all the given classes at the end, deduplicating them. Consuming self.
Source§

fn add_class_if( &mut self, class: impl Into<ClassName>, condition: bool, ) -> &mut Self
where Self: Sized,

Add a class to the list if the condition is true. Read more
Source§

fn with_class_if(self, class: impl Into<ClassName>, condition: bool) -> Self
where Self: Sized,

Add the given class by consuming self if the condition is true. Read more
Source§

fn iter_classes(&self) -> Iter<'_, ClassName> ⓘ

Iterate over the classes, in the order they were added.
Source§

fn classes_as_slice(&self) -> &[ClassName]

Return the classes as a slice.

Auto Trait Implementations§

§

impl !RefUnwindSafe for UiBuilder

§

impl !UnwindSafe for UiBuilder

§

impl Forget for UiBuilder

§

impl Freeze for UiBuilder
where NonZero<u64>: Freeze, *const u8 is !null: Freeze, PhantomData<(String, Option<Arc<dyn Any + Sync + Send>>)>: Freeze, *const ArcInner<Style> is !null: Freeze, PhantomData<ArcInner<Style>>: Freeze, PhantomData<u8>: Freeze, &'static str: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, *const ClassName is !null: Freeze, PhantomData<ClassName>: Freeze,

§

impl Move for UiBuilder

§

impl Send for UiBuilder
where NonZero<u64>: Send, RawTable<(String, Option<Arc<dyn Any + Sync + Send>>)>: Send, Arc<Style>: Send, RawVecInner: Send, SmallVec<[ClassName; 5]>: Send,

§

impl Sync for UiBuilder
where NonZero<u64>: Sync, RawTable<(String, Option<Arc<dyn Any + Sync + Send>>)>: Sync, Arc<Style>: Sync, RawVecInner: Sync, SmallVecData<[ClassName; 5]>: Sync, ClassName: Sync,

§

impl Unpin for UiBuilder
where NonZero<u64>: Unpin, *const u8 is !null: Unpin, Arc<dyn Any + Sync + Send>: Unpin, Arc<Style>: Unpin, &'static str: Unpin, Arc<str>: Unpin, *const ClassName is !null: Unpin, ClassName: Unpin,

§

impl UnsafeUnpin for UiBuilder

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more