Add axis-aware scroll constraints and per-mount limits
Verify Tessera GUI / verify (push) Failing after 7m38s

This commit is contained in:
2026-10-22 19:35:38 +08:00
parent 2b20976658
commit 1885693f7c
13 changed files with 277 additions and 14 deletions
+47 -2
View File
@@ -11,6 +11,39 @@ use anyhow::{Result, bail};
use endor_core::{NativeContext, ObjectRef, Value, Vm, VmError, WeakObjectRef};
use std::collections::HashMap;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum Axis {
#[default]
Both,
Vertical,
Horizontal,
}
impl Axis {
pub fn name(self) -> &'static str {
match self {
Self::Both => "both",
Self::Vertical => "vertical",
Self::Horizontal => "horizontal",
}
}
pub fn parse(name: &str) -> Result<Self, VmError> {
match name {
"both" => Ok(Self::Both),
"vertical" => Ok(Self::Vertical),
"horizontal" => Ok(Self::Horizontal),
_ => Err(VmError::InvalidArgument(
"ScrollBlock.axis expects both, vertical or horizontal",
)),
}
}
pub fn horizontal(self) -> bool {
self != Self::Vertical
}
pub fn vertical(self) -> bool {
self != Self::Horizontal
}
}
fn intersection(a: [f32; 4], b: [f32; 4]) -> [f32; 4] {
let x = a[0].max(b[0]);
let y = a[1].max(b[1]);
@@ -75,9 +108,21 @@ pub fn project(vm: &mut Vm, table: &MountTable, root: &UiNode, frame: &mut Frame
UiKind::Scroll { padding, .. } => padding,
_ => 0.0,
};
let axis = match nodes[m.block_id.as_str()].kind {
UiKind::Scroll { axis, .. } => axis,
_ => Axis::Both,
};
let limits = [
(extent[i].0 + padding - m.x - m.width).max(0.0),
(extent[i].1 + padding - m.y - m.height).max(0.0),
if axis.horizontal() {
(extent[i].0 + padding - m.x - m.width).max(0.0)
} else {
0.0
},
if axis.vertical() {
(extent[i].1 + padding - m.y - m.height).max(0.0)
} else {
0.0
},
];
m.x -= dx;
m.y -= dy;