Skip to main content

ActionScope

Struct ActionScope 

Source
pub struct ActionScope<'p> { /* private fields */ }
Expand description

事件回调执行期上下文(支持 cx.notify() 触发当前 PodId 局部脏标记与 stop_propagation() 阻断冒泡)。

Implementations§

Source§

impl<'p> ActionScope<'p>

Source

pub fn handle<V: View>(&self) -> Option<Handle<V>>

获取当前正在执行事件回调的视图句柄 Handle<V>(带 ABA 代号与运行时类型校验;全平台 #![no_std] 可用)。

Source

pub fn spawn<V, T, F, Fut>(&mut self, f: F) -> Task<T> ⓘ
where V: View, T: 'static, F: FnOnce(Handle<V>, AsyncApp) -> Fut, Fut: Future<Output = T> + 'static,

在当前事件回调中派生绑定到当前视图的 UI 前景异步任务(与 GPUI cx.spawn(async move |this, cx| ...) 对齐)。

返回 RAII crate::async_rt::Task<T>:存入视图字段可在覆盖或视图卸载时自动取消,或调用 .detach() 独立运行。

Source

pub fn spawn_app<T, F, Fut>(&mut self, f: F) -> Task<T> ⓘ
where T: 'static, F: FnOnce(AsyncApp) -> Fut, Fut: Future<Output = T> + 'static,

在当前事件回调中派生不绑定特定视图句柄的 UI 前景异步任务(闭包接收 crate::async_rt::AsyncApp)。

Source

pub fn background_executor(&self) -> BackgroundExecutor

获取绑定到当前引擎调度器后端的后台异步执行器句柄(用于 .spawn(...) / .timer(Duration))。

Source

pub fn background_spawn<T, Fut>(&self, fut: Fut) -> Task<T> ⓘ
where T: Send + 'static, Fut: Future<Output = T> + Send + 'static,

在当前引擎配置的后台调度器中直接派生 CPU 密集型计算或阻塞 I/O 任务。

Source

pub fn timer(&self, duration: Duration) -> Timer ⓘ

创建由当前引擎调度器时钟驱动的非阻塞异步定时器。

Source

pub fn defer<F>(&mut self, f: F)
where F: FnOnce(&mut ActionScope<'_>) + 'static,

排入一个延迟到当前事件冒泡结束后在 UI 主线程执行的回调(避免与当前视图可变借用冲突)。

Source

pub fn defer_self<V, F>(&mut self, f: F)
where V: View, F: FnOnce(&mut V, &mut ActionScope<'_>) + 'static,

排入一个延迟到当前事件冒泡结束后在当前视图上执行的回调(提供直接 &mut V 引用,与 GPUI cx.defer 对齐)。

Source

pub fn notify(&mut self)

标记当前正在处理事件的组件视图(PodId)为脏,将其压入局部重绘队列。

Source

pub fn skip_notify(&mut self)

显式声明本次 listener / action / update 回调未更改视图状态,跳过默认自动标脏。

Source

pub fn flush_signal_dirty_pods(&mut self)

将当前响应式信号(Signal<T>)收集到的脏 PodId 刷入 PodPool 脏队列。

Source

pub fn stop_propagation(&mut self)

阻止当前事件继续向父级容器冒泡传递。

Source

pub const fn is_propagation_stopped(&self) -> bool

当前事件是否已调用 stop_propagation() 停止冒泡。

Source

pub fn notify_handle<T: View>(&mut self, handle: Handle<T>)

标记指定句柄对应的子视图为脏。

Source

pub fn read<'s, T: View>(&'s self, handle: Handle<T>) -> Option<&'s T>

在事件回调中读取另一个 Handle<T> 的只读状态(若目标视图已被可变借用则返回 None)。

Source

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。

Source

pub const fn click_position(&self) -> (i16, i16)

获取当前点击事件的屏幕坐标。

Source

pub const fn drag_event(&self) -> DragEvent

获取当前拖拽事件详情。

Source

pub const fn now_ms(&self) -> u32

事件触发时刻的引擎动画时钟(毫秒,与渲染期 FrameScope::now_ms() 同源,用于启动 Tween / Presence)。

Source

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

Source§

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

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
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> 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.