Skip to main content

BuildOwner

Struct BuildOwner 

Source
pub struct BuildOwner { /* private fields */ }
Expand description

Manager class for the widgets framework.

This class tracks which widgets need rebuilding, and handles other tasks that apply to widget trees as a whole, such as managing the inactive element list for the tree and triggering the “reassemble” command when necessary during hot reload when debugging.

The main build owner is typically owned by the WidgetsBinding, and is driven from the operating system along with the rest of the build/layout/paint pipeline.

Additional build owners can be built to manage off-screen widget trees.

To assign a build owner to a tree, use the RootElementMixin::assign_owner method on the root element of the widget tree.

Implementations§

Source§

impl BuildOwner

Source

pub fn new( app: &mut App, on_build_scheduled: Option<Rc<dyn Fn(&mut App, AnyElement)>>, ) -> Retained<Handle<BuildOwner>>

Creates an object that manages widgets.

This constructs a new FocusManager and registers its global input handlers via FocusManager::register_global_handlers, which will modify static state. Callers wishing to avoid altering this state can explicitly pass a focus manager to with_focus_manager, Dart’s focusManager argument.

Source

pub fn with_focus_manager( app: &mut App, on_build_scheduled: Option<Rc<dyn Fn(&mut App, AnyElement)>>, focus_manager: Retained<Handle<FocusManager>>, ) -> Retained<Handle<BuildOwner>>

Creates an object that manages widgets, with the FocusManager Dart’s focusManager argument supplies; its global input handlers are not registered.

Source

pub fn focus_manager( self: Handle<BuildOwner>, app: &App, ) -> Handle<FocusManager>

The object in charge of the focus tree.

Rarely used directly. Instead, consider using FocusScope::of to obtain the FocusScopeNode for a given BuildContext.

Source

pub fn set_focus_manager( self: Handle<BuildOwner>, app: &mut App, focus_manager: Retained<Handle<FocusManager>>, )

Replaces the object in charge of the focus tree (Dart’s mutable focusManager field).

Source

pub fn set_on_build_scheduled( self: Handle<BuildOwner>, app: &mut App, callback: Option<Rc<dyn Fn(&mut App, AnyElement)>>, )

Replaces the on_build_scheduled callback.

Source

pub fn schedule_build_for( self: Handle<BuildOwner>, app: &mut App, element: AnyElement, )

Adds an element to the dirty elements list so that it will be rebuilt when WidgetsBinding::draw_frame calls build_scope.

Source

pub fn debug_building(self: Handle<BuildOwner>, app: &App) -> bool

Whether this widget tree is in the build phase.

Only valid when asserts are enabled.

Source

pub fn lock_state( self: Handle<BuildOwner>, app: &mut App, callback: impl FnOnce(&mut App), )

Establishes a scope in which calls to State::set_state are forbidden, and calls the given callback.

This mechanism is used to ensure that, for instance, State::dispose does not call State::set_state.

Source

pub fn build_scope( self: Handle<BuildOwner>, app: &mut App, context: AnyElement, callback: Option<Box<dyn FnOnce(&mut App)>>, )

Establishes a scope for updating the widget tree, and calls the given callback, if any. Then, builds all the elements that were marked as dirty using schedule_build_for, in depth order.

This mechanism prevents build methods from transitively requiring other build methods to run, potentially causing infinite loops.

The dirty list is processed after callback returns, building all the elements that were marked as dirty using schedule_build_for, in depth order. If elements are marked as dirty while this method is running, they must be deeper than the context node, and deeper than any previously-built node in this pass.

To flush the current dirty list without performing any other work, this function can be called with no callback. This is what the framework does each frame, in WidgetsBinding::draw_frame.

Only one build_scope can be active at a time.

A build_scope implies a lock_state scope as well.

Source

pub fn global_key_count(self: Handle<BuildOwner>, app: &App) -> usize

The number of GlobalKey instances that are currently associated with Elements that have been built by this build owner.

Source

pub fn global_key_element( self: Handle<BuildOwner>, app: &App, key: &GlobalKey, ) -> Option<AnyElement>

The element registered under a global key, if any.

Source

pub fn debug_inactive_contains( self: Handle<BuildOwner>, app: &App, element: AnyElement, ) -> bool

Whether element is on the inactive list; for tests.

Source

pub fn finalize_tree(self: Handle<BuildOwner>, app: &mut App)

Complete the element build pass by unmounting any elements that are no longer active.

This is called by WidgetsBinding::draw_frame.

In debug mode, this also runs some sanity checks, for example checking for duplicate global keys.

Auto Trait Implementations§

§

impl !RefUnwindSafe for BuildOwner

§

impl !Send for BuildOwner

§

impl !Sync for BuildOwner

§

impl !UnwindSafe for BuildOwner

§

impl Forget for BuildOwner

§

impl Freeze for BuildOwner
where *const RcInner<dyn Fn(&mut App, AnyElement)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement)>>: Freeze, NonZero<u32>: Freeze, PhantomData<fn() -> FocusManager>: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const u8 is !null: Freeze, PhantomData<(AnyElement, ())>: Freeze, PhantomData<(GlobalKey, AnyElement)>: Freeze, &'static ElementVTable: Freeze,

§

impl Move for BuildOwner

§

impl Unpin for BuildOwner
where Rc<dyn Fn(&mut App, AnyElement)>: Unpin, NonZero<u32>: Unpin, Rc<Keep>: Unpin, *const u8 is !null: Unpin, &'static ElementVTable: Unpin, Rc<dyn Key>: Unpin,

§

impl UnsafeUnpin for BuildOwner
where *const RcInner<dyn Fn(&mut App, AnyElement)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, PhantomData<fn() -> FocusManager>: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<(AnyElement, ())>: UnsafeUnpin, PhantomData<(GlobalKey, AnyElement)>: UnsafeUnpin, &'static ElementVTable: UnsafeUnpin,

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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