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
+7
View File
@@ -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();