pub struct Scope<V> { /* private fields */ }Expand description
有状态视图渲染上下文 Scope<V>。
通过 #[repr(transparent)] 与 Deref<Target = FrameScope> 保证与 FrameScope 内存布局 100% 一致,
自动兼容所有接受 &FrameScope 的 .child(cx, ...) 调用。
Implementations§
Source§impl<V> Scope<V>
impl<V> Scope<V>
Sourcepub fn set_current_pod(&mut self, id: PodId)
pub fn set_current_pod(&mut self, id: PodId)
设置当前所属的 PodId。
Sourcepub fn arena(&self) -> &ScratchArena
pub fn arena(&self) -> &ScratchArena
获取帧内存池引用。
Source§impl<V: View> Scope<V>
impl<V: View> Scope<V>
Sourcepub fn listener<'a, E, F>(
&'a self,
handler: F,
) -> &'a dyn Fn(E, &mut ActionScope<'_>)
pub fn listener<'a, E, F>( &'a self, handler: F, ) -> &'a dyn Fn(E, &mut ActionScope<'_>)
将组件状态变更闭包分配至 ScratchArena 中,并在事件触发时自动路由回当前 PodId 对应的 V 实例。
默认在可变回调结束后自动标记当前有状态 PodId 为脏(消除逐字节读取未初始化 Padding 的 UB,并正确捕获 Vec/String 等堆内修改);
若回调仅做只读判断无需重绘,可调用 ActionScope::skip_notify。
Sourcepub fn action<'a, F>(&'a self, handler: F) -> &'a dyn Fn(&mut ActionScope<'_>)
pub fn action<'a, F>(&'a self, handler: F) -> &'a dyn Fn(&mut ActionScope<'_>)
构造无需事件参数的动作回调 &'a dyn Fn(&mut ActionScope)(直接用于 on_dismiss / on_focus / on_click_raw,消除手动 arena.alloc 包装)。
默认在可变回调结束后自动标记当前有状态 PodId 为脏;若无需重绘可调用 ActionScope::skip_notify。
Methods from Deref<Target = FrameScope>§
Sourcepub fn ime_preedit(&self) -> Option<&str>
pub fn ime_preedit(&self) -> Option<&str>
获取当前正在组合输入的 IME 预编辑字符串(无预编辑内容时返回 None)。
Sourcepub fn ime_preedit_state(&self) -> ImePreedit
pub fn ime_preedit_state(&self) -> ImePreedit
获取当前帧上下文中的完整 IME 预编辑状态(含可选光标区间)。
Sourcepub fn safe_area(&self) -> SafeAreaInsets
pub fn safe_area(&self) -> SafeAreaInsets
获取当前屏幕安全区域内边距(状态栏、刘海屏、底部 Home Indicator)。
Sourcepub fn keyboard_inset(&self) -> i16
pub fn keyboard_inset(&self) -> i16
获取当前屏幕软键盘占用的底部像素高度(0 表示未弹出)。
Sourcepub fn read<'s, T: View>(
&'s self,
handle: Handle<T>,
) -> Option<PodReadGuard<'s, T>>
pub fn read<'s, T: View>( &'s self, handle: Handle<T>, ) -> Option<PodReadGuard<'s, T>>
在渲染期安全读取另一个子视图/兄弟视图 Handle<T> 的只读状态,返回局部借用守卫 super::PodReadGuard。
守卫通过 Deref 将引用生命周期严格限制在守卫存活的局部作用域内(不可泄漏为 'a 存入 Element<'a>),
且在守卫析构前阻止目标槽位进入可变借用或 View::render。
Sourcepub fn read_with<T: View, R>(
&self,
handle: Handle<T>,
f: impl FnOnce(&T) -> R,
) -> Option<R>
pub fn read_with<T: View, R>( &self, handle: Handle<T>, f: impl FnOnce(&T) -> R, ) -> Option<R>
在渲染期通过闭包安全读取另一个 Handle<T> 视图并提取计算结果。
Sourcepub fn arena(&self) -> &ScratchArena
pub fn arena(&self) -> &ScratchArena
获取瞬态帧内存池引用。
Sourcepub fn locale(&self) -> Locale
pub fn locale(&self) -> Locale
返回当前生效的语言区域(若渲染期调用了 Self::override_locale 则优先返回覆盖值)。
Sourcepub fn text_direction(&self) -> TextDirection
pub fn text_direction(&self) -> TextDirection
返回当前语言的默认书写方向(Ltr 或 Rtl)。
Sourcepub fn override_locale(&self, locale: Locale)
pub fn override_locale(&self, locale: Locale)
在当前帧渲染期间覆盖活跃语言区域(与 Self::override_theme 对称,零可变别名风险)。
Sourcepub fn override_i18n_catalog(&self, catalog: &'static StaticCatalog)
pub fn override_i18n_catalog(&self, catalog: &'static StaticCatalog)
在当前帧渲染期间临时覆盖静态词典集合(例如根视图挂载应用级词典)。
Sourcepub fn t_or<'a>(&'a self, key: &str, fallback: &'a str) -> StrRef<'a>
pub fn t_or<'a>(&'a self, key: &str, fallback: &'a str) -> StrRef<'a>
翻译无参数文本键,若未命中任何词典则返回显式默认值 fallback。
Sourcepub fn t_args<'a>(
&'a self,
key: &str,
args: &[(&str, I18nArg<'_>)],
) -> StrRef<'a>
pub fn t_args<'a>( &'a self, key: &str, args: &[(&str, I18nArg<'_>)], ) -> StrRef<'a>
翻译带命名/位置参数的文本键并在 ScratchArena 中零堆完成插值(如 cx.t_args("greeting", &[("name", "Velox".into())]))。
Sourcepub fn t_plural<'a>(&'a self, key: &str, count: i64) -> StrRef<'a>
pub fn t_plural<'a>(&'a self, key: &str, count: i64) -> StrRef<'a>
按 CLDR 复数规则翻译文本键并自动注入 {count} 参数(如 cx.t_plural("files", 3))。
Sourcepub fn push_id(&self, seed: u32)
pub fn push_id(&self, seed: u32)
压入一层作用域 ID 种子(ImGui / egui 风格 Scoped ID Stack,最多支持 8 层嵌套)。
同一页面中多次复用相同子组件或列表项模板时,通过 push_id / with_id 自动隔离所有内部交互与动画 ID。
Sourcepub fn pop_id(&self)
pub fn pop_id(&self)
弹出当前最顶层的作用域 ID 种子(与 Self::push_id 配对使用)。
Sourcepub fn with_id<'a, R>(&'a self, seed: u32, f: impl FnOnce(&'a Self) -> R) -> R
pub fn with_id<'a, R>(&'a self, seed: u32, f: impl FnOnce(&'a Self) -> R) -> R
在指定作用域 ID 种子内执行渲染闭包,退出时自动弹栈恢复外层作用域。
Sourcepub fn scoped_id(&self, local_id: u32) -> u32
pub fn scoped_id(&self, local_id: u32) -> u32
基于当前作用域 ID 栈与局部 ID 派生全局唯一、不与用户显式 ID 撞车的稳定 u32 元素 ID。
Sourcepub fn override_theme(&self, theme: CoreTheme)
pub fn override_theme(&self, theme: CoreTheme)
在当前帧渲染期间覆盖活跃主题配色(分配在 ScratchArena 中,零可变别名风险)。
Sourcepub fn current_pod(&self) -> PodId
pub fn current_pod(&self) -> PodId
获取当前正在渲染的 PodId。
Sourcepub fn request_frame(&self)
pub fn request_frame(&self)
请求引擎在下一帧继续重新渲染(用于由 now_ms() 驱动的连续动画,如旋转加载指示器)。
Sourcepub fn keep_animating(&self, running: bool) -> bool
pub fn keep_animating(&self, running: bool) -> bool
若 running 为真则请求下一帧,并原样返回 running(便于 cx.keep_animating(tween.is_running(now)))。
Sourcepub fn is_frame_requested(&self) -> bool
pub fn is_frame_requested(&self) -> bool
本帧渲染期间是否有视图请求了下一帧(request_frame() / keep_animating(true))。
Trait Implementations§
Auto Trait Implementations§
impl<V> !Freeze for Scope<V>
impl<V> !RefUnwindSafe for Scope<V>
impl<V> !Send for Scope<V>
impl<V> !Sync for Scope<V>
impl<V> !UnwindSafe for Scope<V>
impl<V> Forget for Scope<V>
impl<V> Move for Scope<V>
impl<V> Unpin for Scope<V>where
PhantomData<V>: Unpin,
impl<V> UnsafeUnpin for Scope<V>where
PhantomData<V>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。