Add per-Mount scrolling with shared paint and input clipping
Verify Tessera GUI / verify (push) Failing after 7m33s

This commit is contained in:
2026-10-21 22:05:08 +08:00
parent 7acc5783a5
commit 6e69c5e5ce
18 changed files with 784 additions and 33 deletions
+100 -2
View File
@@ -27,6 +27,7 @@ pub const TYPE_NAMES: &[&str] = &[
"Presentable",
"Block",
"ContainerBlock",
"ScrollBlock",
"TextBlock",
"RectBlock",
"Spacer",
@@ -69,7 +70,8 @@ impl UiNode {
match &self.kind {
UiKind::Column { children, .. }
| UiKind::Row { children, .. }
| UiKind::Button { children, .. } => children,
| UiKind::Button { children, .. }
| UiKind::Scroll { children, .. } => children,
_ => &[],
}
}
@@ -118,6 +120,22 @@ impl UiNode {
},
) => (a, b, c, d) == (e, f, g, h),
(UiKind::Spacer(a), UiKind::Spacer(b)) => a == b,
(
UiKind::Scroll {
width: a,
height: b,
padding: pa,
gap: ga,
children: _,
},
UiKind::Scroll {
width: c,
height: d,
padding: pb,
gap: gb,
children: _,
},
) => a == c && b == d && pa == pb && ga == gb && same_children(),
(
UiKind::Column {
padding: a, gap: b, ..
@@ -176,6 +194,13 @@ pub enum UiKind {
children: Vec<Arc<UiNode>>,
},
Spacer(f32),
Scroll {
width: f32,
height: f32,
padding: f32,
gap: f32,
children: Vec<Arc<UiNode>>,
},
}
#[derive(Debug)]
@@ -232,6 +257,7 @@ enum Operation {
Text,
Rect,
Spacer,
Scroll,
Row,
Column,
Button,
@@ -428,6 +454,7 @@ fn new_typed_block(
Kind::Text { .. } => "TextBlock",
Kind::Rect { .. } => "RectBlock",
Kind::Spacer(_) => "Spacer",
Kind::Scroll { .. } => "ScrollBlock",
Kind::Row => "Row",
Kind::Column => "Column",
Kind::Button => "Button",
@@ -659,6 +686,7 @@ impl NativeCallable for Function {
State | StateSet => (1, 1),
Increment => (0, 0),
TextOf => (2, 4),
Scroll => (3, 3),
Text => (1, 3),
Rect => (2, 4),
MoveWindow | OpenValue | Spacer | SetText | SetColor | Append | Remove | Render
@@ -931,6 +959,15 @@ impl NativeCallable for Function {
)?)));
}
let constructor = match self.operation {
Scroll => Some(Data::new(
Kind::Scroll {
width: dimension(args.first())?,
height: dimension(args.get(1))?,
},
vec![object(args.get(2))?],
0.0,
0.0,
)),
Text => Some(Data::new(
Kind::Text {
value: text(args.first())?,
@@ -1674,9 +1711,56 @@ impl UiBridge {
.ok_or_else(|| anyhow::anyhow!("Mount is no longer active"))?,
state.desktop,
state.mounts.ordered(),
state.layout.viewport,
state.layout.viewport.map(|size| crate::layout::Size {
width: size.width,
height: (size.height - crate::tabs::height(&state.last_tabs)).max(0.0),
}),
)
};
if input.kind == "scroll" {
let mount = vm
.upgrade(weak)?
.ok_or_else(|| anyhow::anyhow!("scroll Mount expired"))?;
let result = (|| {
let data = vm.payload::<crate::mount::Mount>(mount, "Mount")?;
let point = input
.point
.ok_or_else(|| anyhow::anyhow!("scroll has no pointer"))?;
if !data.mounted
|| data.version != input.layout_version
|| viewport
.is_some_and(|size| point[0] >= size.width || point[1] >= size.height)
|| !data
.geometry
.contains(crate::geometry::Point::new(point[0], point[1]))
{
bail!("scroll targets an obsolete or clipped Mount");
}
let delta = input
.delta
.ok_or_else(|| anyhow::anyhow!("scroll has no delta"))?;
let method = vm.bind_attr(mount, "scrollBy")?;
let result = match method {
Value::Object(function) => vm.call_with_limits(
function,
&[
Value::Number((delta[0] as f64).into()),
Value::Number((delta[1] as f64).into()),
],
endor_core::ExecutionLimits {
max_frames: 128,
max_instructions: 100_000,
},
),
_ => Err(invalid("scrollBy is not callable")),
};
vm.release_value(method)?;
vm.release_value(result?)?;
Ok(())
})();
vm.release(mount)?;
return result;
}
let mount = if let (Some(press), Some(release)) = (input.press_point, input.point) {
if viewport.is_some_and(|size| {
[press, release]
@@ -1830,6 +1914,10 @@ impl UiBridge {
let changed = state.pending.is_some()
|| !same
|| focus_changed
|| matches!(
vm.get_attr(state.desktop, "scrollRequested"),
Ok(Value::Bool(true))
)
|| state.force_frame
|| tabs != state.last_tabs;
if changed {
@@ -1863,6 +1951,7 @@ impl UiBridge {
}
vm.set_attr(state.desktop, "pending", Value::Nil)?;
vm.set_attr(state.desktop, "focusRequested", Value::Bool(false))?;
vm.set_attr(state.desktop, "scrollRequested", Value::Bool(false))?;
state.force_frame = false;
state.last_snapshot = snapshot;
state.last_tabs = frame.tabs.clone();
@@ -2025,6 +2114,13 @@ impl UiBridge {
&mut layout,
&mut cache,
)?;
{
let state = self
.session
.lock()
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
crate::scroll::project(vm, &state.mounts, &root, &mut frame)?;
}
// Native layout may replace the structural Frame; attach chrome only
// after either layout path has produced the final page geometry.
frame.tabs = tabs;
@@ -2161,6 +2257,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
("TextBlock", "Block", Some("text")),
("RectBlock", "Block", Some("rect")),
("Spacer", "Block", Some("spacer")),
("ScrollBlock", "ContainerBlock", Some("scroll")),
("Row", "ContainerBlock", Some("row")),
("Column", "ContainerBlock", Some("column")),
("Button", "ContainerBlock", Some("button")),
@@ -2200,6 +2297,7 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
"text" => Operation::Text,
"rect" => Operation::Rect,
"spacer" => Operation::Spacer,
"scroll" => Operation::Scroll,
"row" => Operation::Row,
"column" => Operation::Column,
"button" => Operation::Button,