docs: explain hit selection and scroll viewport projection order
This commit is contained in:
@@ -136,6 +136,7 @@ impl DisplayList {
|
||||
/// 按设备比例缩放命令,文字、边框和矩形不能分别使用不一致比例。
|
||||
pub fn scale(&mut self, scale: f32) {
|
||||
// 原地累计缩放:重复调用会相乘,并非设置绝对缩放值。调用方负责提供有效设备比例。
|
||||
// scene 合成宿主 chrome 时调用;只改视口/局部几何,不重新解码 Image 或重建 Scene3D 世界数据。
|
||||
for command in &mut self.commands {
|
||||
// 先处理各变体独有的长度(字体、圆角、描边),再把公共矩形交给下方统一缩放。
|
||||
let rect = match command {
|
||||
@@ -231,6 +232,7 @@ impl DisplayList {
|
||||
/// 按原顺序合并另一组绘制命令,不在这里重排层次。
|
||||
// 消费另一个列表并移动其命令,不复制字符串或场景数据,也不在连接处补裁剪指令。
|
||||
pub fn extend(&mut self, other: DisplayList) {
|
||||
// 连接处不自动隔离 Clear 或裁剪状态;scene 合并页面时会自行跳过额外 Clear,并用外层 PushClip/PopClip 限制页面区域。
|
||||
self.commands.extend(other.commands);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//! 通过真正的源/原生 hitTest 协议确定指针目标。
|
||||
//! 按逆绘制顺序筛选候选,并在同一只读 VM 调用与预算中比较按下、释放目标;透明或未命中的子项可以继续回退。
|
||||
//! UiBridge::dispatch 已验证窗口、发布版本和页面可见范围,再把有序 Mount 弱表交给 resolve;这里不自行选择窗口。
|
||||
//! 两个点都按本次调用的当前几何和方法重新检查,不保存鼠标按下时的旧业务快照,也不在本模块派发 click。
|
||||
//!
|
||||
//! Resolve pointer targets in paint order through source/native hitTest methods.
|
||||
//! Both press and release selectors share one read-only VM call and budget.
|
||||
@@ -152,6 +154,7 @@ fn selector(
|
||||
/ 2) as u32;
|
||||
// 先调用 hitTest(block, mount, local),再把结果传给 validate。
|
||||
// true 立即返回本 Mount;false 继续下一个候选,实现透明区域向下穿透。
|
||||
// 两次 PushNull 占据 Call 的空接收者槽;block/mount/local 已显式加载,不能让 VM 再插入一次 receiver。
|
||||
instructions.extend([
|
||||
Instruction::new(Opcode::LoadConst, 0),
|
||||
Instruction::simple(Opcode::PushNull),
|
||||
@@ -276,6 +279,7 @@ pub fn resolve(
|
||||
// 先保存调用结果再释放入口根,因此 VM 返回错误时也能完成入口清理。
|
||||
vm.release(prepare)?;
|
||||
// 只取选择值,丢弃只读依赖集合;一次性输入命中不建立绘制或布局的持久失效依赖。
|
||||
// 命中期间的只读限制作用于已有业务对象,准备器仍可分配 Point/驱动函数等临时结果,不能把 ReadOnly 解释成禁止任何分配。
|
||||
let (value, _) = result.map_err(|error| crate::endor_host::runtime_error(vm, error))?;
|
||||
// 接受 Mount 或 Nil 两类驱动结果,其他值先释放其可能拥有根,再报告内部协议错误。
|
||||
match value {
|
||||
|
||||
@@ -37,7 +37,9 @@ pub struct CameraView {
|
||||
pub identity: String,
|
||||
// 相机在世界空间的左上位置,投影时先从内容坐标中扣除,再乘 zoom。
|
||||
pub x: f32,
|
||||
// 世界纵向左上偏移,和 x 一样在投影前扣除,不是视口盒子的布局原点。
|
||||
pub y: f32,
|
||||
// 已校验 0.01..100 的相机倍率;嵌套后的累计倍率另受 Transform.valid 预算约束。
|
||||
pub zoom: f32,
|
||||
}
|
||||
|
||||
@@ -169,7 +171,9 @@ pub fn fit(
|
||||
pub struct Transform {
|
||||
// 均匀缩放,point/rect 正向乘此值,inverse 撤销时除以此值;累计变换须经 valid。
|
||||
pub zoom: f32,
|
||||
// 缩放之后叠加的目标空间横向平移;then 组合时此值还须乘外层 zoom。
|
||||
pub x: f32,
|
||||
// 同一目标空间的纵向平移,不等同于 CameraView.y 的世界偏移。
|
||||
pub y: f32,
|
||||
}
|
||||
impl Default for Transform {
|
||||
@@ -258,6 +262,7 @@ pub fn project(
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
// 按 Block 身份建立语义视觉索引;多个 Mount 可查到同一节点,但每个出现单独组合视图。
|
||||
// scroll::project 已把祖先滚动量计入 Mount.x/y;此处只附相机/面板映射,不能再从相机平移中重复扣滚动偏移。
|
||||
let mut nodes = HashMap::new();
|
||||
let mut work = vec![root];
|
||||
// 显式栈只展开视觉节点树,不以此遍历顺序决定绘制或输入优先级。
|
||||
@@ -309,6 +314,7 @@ pub fn project(
|
||||
mount.clip = clip;
|
||||
mount.viewport_clip = None;
|
||||
// 当前出现使用继承的 view/clip;仅其子树才叠加本层相机或本层子裁剪。
|
||||
// 因此相机移动场景内容,但视口本身的外框和内容裁剪仍固定在父布局分配的位置。
|
||||
let mut child_view = view;
|
||||
let mut child_clip = clip;
|
||||
let inset = crate::layout::insets(node);
|
||||
@@ -409,6 +415,7 @@ pub fn project(
|
||||
contexts.insert(mount.id, (child_view, child_clip, panel));
|
||||
}
|
||||
// 投影完成后按命令 owner 查回对应出现,重建平行元数据;此时不再修改 Mount 几何。
|
||||
// 这里只准备当前默认命令的投影;后续 source_paint 替换命令时也必须按出现归属维护对应元数据,不能沿用旧命令下标。
|
||||
let mounts: HashMap<_, _> = frame.mounts.iter().map(|mount| (mount.id, mount)).collect();
|
||||
// 按每条命令的 Mount 归属重建 view/clip,确保源绘制、默认绘制和输入都使用这一轮最终投影。
|
||||
frame.command_views.clear();
|
||||
|
||||
Reference in New Issue
Block a user