docs: explain hit selection and scroll viewport projection order

This commit is contained in:
2026-11-12 20:43:30 +08:00
parent 45b0b53d4f
commit afff46c0a8
4 changed files with 17 additions and 0 deletions
+4
View File
@@ -1,5 +1,6 @@
//! 逐 Mount 的滚动状态、裁剪和输入目标选择。
//! 共享组件的不同出现保留独立偏移。嵌套滚动先选择可接收位移的内层,偏移在实际内容范围内钳制。
//! UiBridge 完成布局后先调用 project,viewport::project 再附相机/面板变换;Mount 方法调用 set/into_view 只写请求,等待下一轮投影。
//!
//! Per-occurrence scroll state and a single geometry/clip projection shared by
//! native paint, source paint and input. No business object is copied.
@@ -309,6 +310,7 @@ pub fn set(
point
};
mount.scroll_offset = [next[0].clamp(0.0, bounds[2]), next[1].clamp(0.0, bounds[3])];
// 这里使用上次提交的滚动上限;若业务内容随后缩短,新一轮 project 会再次钳制,几何提交再保存新的有效偏移。
// 写入前确认窗口仍存活,升级根由 NativeContext 临时管理;失效时不替换 Mount 偏移。
let desktop = cx
.upgrade(desktop)?
@@ -389,6 +391,7 @@ pub fn into_view(
/// 按逆出现顺序选择指针处可处理当前滚动方向的最内层容器。
// shell/app 在滚轮路由时调用,输入点已经进入页面坐标;返回出现 ID 后仍由所属 VM 执行滚动更新。
pub fn wheel_target(frame: &Frame, point: Point, delta: [f32; 2]) -> Option<u64> {
// shell 只借返回 ID 构造输入信封;本函数不运行源 hitTest、不校验 session/fault,也不直接修改任何滚动 owner。
// 按 ID 建立只读祖先查找,候选搜索选定最上层命中出现后只沿这一条父链移动。
let indices: HashMap<_, _> = frame.mounts.iter().map(|mount| (mount.id, mount)).collect();
// 逆序先取最上层命中的出现,再沿其祖先寻找能消费位移的滚动容器。
@@ -407,6 +410,7 @@ pub fn wheel_target(frame: &Frame, point: Point, delta: [f32; 2]) -> Option<u64>
return Some(mount.id);
}
// 只向命中出现的祖先回退,不改为搜索下层兄弟,也不把一次 delta 拆给多个容器。
// 一旦内层任一轴能移动就选它;未消费的另一轴或超出边界的剩余量不会在本次选择中继续分发给外层。
current = mount.parent.and_then(|id| indices.get(&id).copied());
}
None