pub struct ActionScope<'p> { /* private fields */ }Expand description
事件回调执行期上下文(支持 cx.notify() 触发当前 PodId 局部脏标记与 stop_propagation() 阻断冒泡)。
Implementations§
Source§impl<'p> ActionScope<'p>
impl<'p> ActionScope<'p>
Sourcepub fn handle<V: View>(&self) -> Option<Handle<V>>
pub fn handle<V: View>(&self) -> Option<Handle<V>>
获取当前正在执行事件回调的视图句柄 Handle<V>(带 ABA 代号与运行时类型校验;全平台 #![no_std] 可用)。
Sourcepub fn spawn<V, T, F, Fut>(&mut self, f: F) -> Task<T> ⓘ
pub fn spawn<V, T, F, Fut>(&mut self, f: F) -> Task<T> ⓘ
在当前事件回调中派生绑定到当前视图的 UI 前景异步任务(与 GPUI cx.spawn(async move |this, cx| ...) 对齐)。
返回 RAII crate::async_rt::Task<T>:存入视图字段可在覆盖或视图卸载时自动取消,或调用 .detach() 独立运行。
Sourcepub fn spawn_app<T, F, Fut>(&mut self, f: F) -> Task<T> ⓘ
pub fn spawn_app<T, F, Fut>(&mut self, f: F) -> Task<T> ⓘ
在当前事件回调中派生不绑定特定视图句柄的 UI 前景异步任务(闭包接收 crate::async_rt::AsyncApp)。
Sourcepub fn background_executor(&self) -> BackgroundExecutor
pub fn background_executor(&self) -> BackgroundExecutor
获取绑定到当前引擎调度器后端的后台异步执行器句柄(用于 .spawn(...) / .timer(Duration))。
Sourcepub fn background_spawn<T, Fut>(&self, fut: Fut) -> Task<T> ⓘ
pub fn background_spawn<T, Fut>(&self, fut: Fut) -> Task<T> ⓘ
在当前引擎配置的后台调度器中直接派生 CPU 密集型计算或阻塞 I/O 任务。
Sourcepub fn defer<F>(&mut self, f: F)where
F: FnOnce(&mut ActionScope<'_>) + 'static,
pub fn defer<F>(&mut self, f: F)where
F: FnOnce(&mut ActionScope<'_>) + 'static,
排入一个延迟到当前事件冒泡结束后在 UI 主线程执行的回调(避免与当前视图可变借用冲突)。
Sourcepub fn defer_self<V, F>(&mut self, f: F)
pub fn defer_self<V, F>(&mut self, f: F)
排入一个延迟到当前事件冒泡结束后在当前视图上执行的回调(提供直接 &mut V 引用,与 GPUI cx.defer 对齐)。
Sourcepub fn skip_notify(&mut self)
pub fn skip_notify(&mut self)
显式声明本次 listener / action / update 回调未更改视图状态,跳过默认自动标脏。
Sourcepub fn flush_signal_dirty_pods(&mut self)
pub fn flush_signal_dirty_pods(&mut self)
将当前响应式信号(Signal<T>)收集到的脏 PodId 刷入 PodPool 脏队列。
Sourcepub fn stop_propagation(&mut self)
pub fn stop_propagation(&mut self)
阻止当前事件继续向父级容器冒泡传递。
Sourcepub const fn is_propagation_stopped(&self) -> bool
pub const fn is_propagation_stopped(&self) -> bool
当前事件是否已调用 stop_propagation() 停止冒泡。
Sourcepub fn notify_handle<T: View>(&mut self, handle: Handle<T>)
pub fn notify_handle<T: View>(&mut self, handle: Handle<T>)
标记指定句柄对应的子视图为脏。
Sourcepub fn read<'s, T: View>(&'s self, handle: Handle<T>) -> Option<&'s T>
pub fn read<'s, T: View>(&'s self, handle: Handle<T>) -> Option<&'s T>
在事件回调中读取另一个 Handle<T> 的只读状态(若目标视图已被可变借用则返回 None)。
Sourcepub fn update<T: View, R>(
&mut self,
handle: Handle<T>,
f: impl FnOnce(&mut T, &mut ActionScope<'_>) -> R,
) -> Option<R>
pub fn update<T: View, R>( &mut self, handle: Handle<T>, f: impl FnOnce(&mut T, &mut ActionScope<'_>) -> R, ) -> Option<R>
在事件回调中安全更新另一个 Handle<T> 视图的状态并自动标记其局部脏区。
若发生 A -> B -> A 循环重入,内层对已借用视图的 update 将安全返回 None,彻底杜绝双 &mut 别名 UB。
Sourcepub const fn click_position(&self) -> (i16, i16)
pub const fn click_position(&self) -> (i16, i16)
获取当前点击事件的屏幕坐标。
Sourcepub const fn drag_event(&self) -> DragEvent
pub const fn drag_event(&self) -> DragEvent
获取当前拖拽事件详情。
Sourcepub const fn now_ms(&self) -> u32
pub const fn now_ms(&self) -> u32
事件触发时刻的引擎动画时钟(毫秒,与渲染期 FrameScope::now_ms() 同源,用于启动 Tween / Presence)。
Sourcepub const fn modifiers(&self) -> KeyModifiers
pub const fn modifiers(&self) -> KeyModifiers
事件触发时刻的键盘修饰键状态(Shift / Ctrl / Alt / Logo)。
Auto Trait Implementations§
impl<'p> !RefUnwindSafe for ActionScope<'p>
impl<'p> !Send for ActionScope<'p>
impl<'p> !Sync for ActionScope<'p>
impl<'p> !UnwindSafe for ActionScope<'p>
impl<'p> Forget for ActionScope<'p>
impl<'p> Freeze for ActionScope<'p>
impl<'p> Move for ActionScope<'p>
impl<'p> Unpin for ActionScope<'p>
impl<'p> UnsafeUnpin for ActionScope<'p>
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) 时执行闭包修饰自身,否则原样返回。