pub struct PositionedRenderObject {
pub offset: Point,
pub signal: Option<Signal<Point>>,
/* private fields */
}Expand description
在父容器内按指定 offset 摆放子节点(不影响父容器布局)
阶段 5-G 扩展:可选 signal: Signal<Point> 用于外部驱动位置。
None→ 静态位置(self.offset)Some(signal)→ paint/hit_test 走enter_subscriber(ro_id) + signal.get()实时读值,并自动让 RO 作为 signal 的 subscriber(signal.set 触发 RO 所在 element dirty → paint 重跑)。
Fields§
§offset: Point§signal: Option<Signal<Point>>Implementations§
Source§impl PositionedRenderObject
impl PositionedRenderObject
pub fn new(offset: Point, child: impl RenderObject + 'static) -> Self
Sourcepub fn new_dynamic(
offset: Point,
signal: Signal<Point>,
child: impl RenderObject + 'static,
) -> Self
pub fn new_dynamic( offset: Point, signal: Signal<Point>, child: impl RenderObject + 'static, ) -> Self
阶段 5-G:动态位置(外部 Signal 驱动)
Sourcepub fn set_ro_subscriber_id(&mut self, id: SubscriberId)
pub fn set_ro_subscriber_id(&mut self, id: SubscriberId)
ElementTree 在 mount 时调用,把 element 的 SubscriberId 注入 RO, 让 paint/hit_test 走 enter_subscriber + signal.get() 时 RO 成为 signal 的 subscriber(从而 Signal::set 触发 element dirty)。
Trait Implementations§
Source§impl RenderObject for PositionedRenderObject
impl RenderObject for PositionedRenderObject
Source§fn child_slots(&self) -> Vec<(Point, SharedRO)>
fn child_slots(&self) -> Vec<(Point, SharedRO)>
阶段 2-E:element_origin 遍历用 — child 在当前 offset 处
Source§fn push_child(&mut self, offset: Point, child: SharedRO)
fn push_child(&mut self, offset: Point, child: SharedRO)
阶段 4-D:Positioned 包装一层, push_child 在原 offset 上再加一层 但 push_child 调用时 caller 应该传 final position,我们这里覆盖 offset 简化:push 时如果 self.offset 是 0,用 caller 的 offset;否则保留 self.offset 实际 mount 时 caller 知道完整 offset,所以这里支持 caller offset
Source§fn set_subscriber_id(&mut self, id: SubscriberId)
fn set_subscriber_id(&mut self, id: SubscriberId)
阶段 5-G:必须放在 impl RenderObject for PositionedRenderObject 块内
(在 impl PositionedRenderObject 块里只是 inherent method,不会覆盖 trait 默认 noop,
导致 Box<dyn RenderObject>::set_subscriber_id 调到这里走 noop,Signal 订阅链路断裂)
Source§fn apply_state(&mut self, state: &mut dyn Any) -> StateApply
fn apply_state(&mut self, state: &mut dyn Any) -> StateApply
属性动画:从 AnimatedOffsetState 就地读当前呈现 offset 写进 self.offset。
paint / hit_test / child_slots 三处都走 current_offset(),signal=None 时
返回 self.offset —— 写它即可保证像素、命中、语义 origin 三处同源(语义
origin 还需要 state 的 tick_changes_geometry=true 触发 origin_cache 失效)。
幂等:值未变返回 Unchanged。
Source§fn layout(
&mut self,
constraints: BoxConstraints,
ctx: &mut LayoutContext,
) -> Size
fn layout( &mut self, constraints: BoxConstraints, ctx: &mut LayoutContext, ) -> Size
Source§fn content_size(&self) -> Size
fn content_size(&self) -> Size
Source§fn paint(&self, offset: Point, painter: &mut PaintList)
fn paint(&self, offset: Point, painter: &mut PaintList)
painter;offset 是本 RO 原点在目标坐标系中的位置。Source§fn hit_test(&self, position: Point, offset: Point) -> Option<ElementId>
fn hit_test(&self, position: Point, offset: Point) -> Option<ElementId>
position 为目标坐标系,offset 为本 RO 原点;返回命中的 element id。Source§fn propagate_element_ids(
&mut self,
child_ids: &[ElementId],
stateful_ros: &mut [SharedRO],
)
fn propagate_element_ids( &mut self, child_ids: &[ElementId], stateful_ros: &mut [SharedRO], )
Source§fn for_each_child(&self, f: &mut dyn FnMut(Point, &SharedRO))
fn for_each_child(&self, f: &mut dyn FnMut(Point, &SharedRO))
Source§fn children_count(&self) -> usize
fn children_count(&self) -> usize
Source§fn scrollbar_lane_hit(&self, _local: Point) -> bool
fn scrollbar_lane_hit(&self, _local: Point) -> bool
local = 相对本 RO 原点)。 Read moreSource§fn set_element_id(&mut self, _id: ElementId)
fn set_element_id(&mut self, _id: ElementId)
RRectRenderObject 有 element_id 字段,其他 RO 默认 noop。