Skip to main content

BuildContext

Struct BuildContext 

Source
pub struct BuildContext<'a> {
    pub element_id: ElementId,
    /* private fields */
}
Expand description

BuildContext — state.build() 的参数,提供 depend_on + 主题/方向/Locale 访问。

生命周期:ctx 由 ElementTree::children_with_positions_of 在 build 前构造, build 后立即 drop,生命周期不长于 build 调用栈。

Fields§

§element_id: ElementId

当前 build 的 element id

Implementations§

Source§

impl<'a> BuildContext<'a>

Source

pub fn depend_on<T: InheritedWidget>(&mut self) -> &T

沿 ancestor 链找最近的 T 类型 InheritedElement,返回其 widget 引用 + 注册 dependent。

Source

pub fn try_theme_rc(&mut self) -> Option<Rc<ThemeData>>

便捷方法 — 拿 ThemeData + 注册依赖;没有 ThemeWidget 祖先时返回 None (不会 panic)。返回 Rc 共享引用:State 缓存主题时零拷贝。

Source

pub fn try_theme(&mut self) -> Option<&ThemeData>

便捷方法 — 以借用形式拿 ThemeData(不缓存整份主题的调用方使用)。

Source

pub fn theme(&mut self) -> &ThemeData

便捷方法 — 拿 ThemeData + 注册依赖(没有 ThemeWidget 祖先时 panic)

Source

pub fn direction(&mut self) -> Direction

便捷方法 — 拿 Direction + 注册依赖

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for BuildContext<'a>

§

impl<'a> !Send for BuildContext<'a>

§

impl<'a> !Sync for BuildContext<'a>

§

impl<'a> !UnwindSafe for BuildContext<'a>

§

impl<'a> Freeze for BuildContext<'a>

§

impl<'a> Unpin for BuildContext<'a>

§

impl<'a> UnsafeUnpin for BuildContext<'a>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.