Add axis-aware scroll constraints and per-mount limits
Verify Tessera GUI / verify (push) Failing after 7m38s
Verify Tessera GUI / verify (push) Failing after 7m38s
This commit is contained in:
+4
-2
@@ -20,10 +20,10 @@
|
||||
| tabs.rs | Immutable tab chrome, shared draw/hit geometry, overflow navigation, drag gaps/anchors/insertion markers and opaque published Page identities |
|
||||
| window.rs | Typed native Window queries/effects, construction/close, context ownership, ordered Page roots, read-only guards, Page reordering, physical desktop placement and coalesced GUI projections |
|
||||
| vm_sequence.rs | Shared validated call-sequence builder and EXTENDED_ARG-aware same-frame repetition for layout, event and lifecycle work |
|
||||
| source_layout.rs | Read-only source layout, repeated constraint/geometry solving with cycle detection, per-Mount measurement caches with subcall dependencies, viewport constraints, typed/slot validation, concrete intrinsic recognition and occurrence geometry |
|
||||
| source_layout.rs | Read-only source layout, repeated constraint/geometry solving with cycle detection, per-Mount measurement caches with subcall dependencies and actual scroll-viewport cross-axis constraints, viewport constraints, typed/slot validation, concrete intrinsic recognition and occurrence geometry |
|
||||
| source_hit.rs | Read-only source/native pointer target selectors, reverse paint order, strict Bool results and matching press/release targets |
|
||||
| source_paint.rs | Read-only source paint dispatch with concrete intrinsic recognition, shared VM budget, paired text-wrap bounds and checked command conversion and versioned object dependencies |
|
||||
| native_visual.rs | Managed native visual protocol queries with resolved type/read-only signatures, occurrence validation, concrete implementation/operation identity, value conversion and bounded results |
|
||||
| native_visual.rs | Managed native visual protocol queries with resolved type/read-only signatures, occurrence validation, concrete implementation/operation identity, arranged-viewport child constraints, value conversion and bounded results |
|
||||
| object_list.rs | Typed factory envelopes, read-only indexed access and traced results shared by Mount queries and visual protocol results |
|
||||
| layout.rs | Shared native geometry/paint functions, iterative measurement/arrangement, stable occurrence IDs, measurement cache, solve-pass counters, geometry budgets and width-sensitive native text measurement |
|
||||
| document.rs | Published source/AST/UI snapshot, revisions, invalidation, frame validation, single-line fault banner (full cause retained in Frame), validated optional text-wrap bounds and display commands |
|
||||
@@ -135,3 +135,5 @@ NativeCallable implementations publish positional metadata, including internal l
|
||||
Native TextBlock measurement and painting now share width-sensitive shaping. Column/Button cross-axis constraints feed both the native fast path and source base calls; direct base measurement also uses its supplied viewport. RenderCommand text has optional wrap_bounds, converted to a clipped WrappedText primitive. Source PaintCommand uses paired wrapWidth/wrapHeight and legacy text remains unwrapped when both are absent. Source-arranged dimensions now participate in repeated constraint solving; general flex allocation, resumable work and axis-specific ScrollBlock wrapping remain future work.
|
||||
|
||||
Layout convergence uses exact finite snapshots of constraints/sizes/bounds and source-selected limits. The same immutable driver loops within one shared VM budget, clears all provisional measurement geometry between passes and rejects nonconsecutive repeated states. Aster ReadAccess distinguishes annotation validation from normal reads; the bridge skips only validation-only Mount reads after independently validating the live Mount/owner context. Actual Mount reads remain volatile; all other recorded dependencies are retained.
|
||||
|
||||
ScrollBlock.axis is stored in its managed properties and projected into the visual snapshot. Axis-aware child constraints use constructor/clamped size for initial measurement and actual occurrence bounds after arrangement. Scroll projection clamps disabled offsets/limits; the same geometry feeds paint and input.
|
||||
|
||||
@@ -1115,6 +1115,8 @@ Native input POST /events is a transport envelope, not Endor source. Each frame
|
||||
sends current session, layout_version and Mount identity; stale positions fail without calling a callback. Pointer clicks also include point and press_point [x,y] in logical page coordinates. Both targets are resolved through read-only hitTest, with fallback behind a rejected candidate; a click is dispatched only when both resolve to the same Mount. Keyboard/code clicks omit coordinates and remain semantic activation. GET /code also exposes X-Tessera-Session and X-Tessera-Layout-Version headers for transport clients. Native mouse, Tab, Enter and Space delegate to the same
|
||||
managed click/focus methods used by code. Events appear in Network, not Console source history.
|
||||
|
||||
ScrollBlock.axis is a managed visual attribute: "both" (default), "vertical" or "horizontal". The default preserves two-axis unconstrained content. Vertical restricts content width to the actual occurrence viewport minus padding; horizontal restricts height. Source-arranged viewport dimensions are used in subsequent measurement. The disabled scroll axis has zero offset/limit and is clamped after updates. Composition remains vertical; a Row child can arrange horizontal content. See examples/scroll-axis.endor.
|
||||
|
||||
## UI host object
|
||||
|
||||
Positional arguments only:
|
||||
|
||||
+13
-3
@@ -117,6 +117,7 @@ pub struct Data {
|
||||
pub children: Vec<Child>,
|
||||
pub padding: f32,
|
||||
pub gap: f32,
|
||||
pub scroll_axis: crate::scroll::Axis,
|
||||
pub next_slot: u64,
|
||||
pub history: Vec<ObjectRef>,
|
||||
pub history_index: usize,
|
||||
@@ -142,6 +143,7 @@ impl Data {
|
||||
.collect(),
|
||||
padding,
|
||||
gap,
|
||||
scroll_axis: crate::scroll::Axis::Both,
|
||||
next_slot,
|
||||
history: vec![],
|
||||
history_index: 0,
|
||||
@@ -329,9 +331,11 @@ pub fn native_properties(data: &Data) -> Vec<(&'static str, Value)> {
|
||||
("radius", number(*radius)),
|
||||
("color", Value::Text(color.clone())),
|
||||
]),
|
||||
Kind::Scroll { width, height } => {
|
||||
fields.extend([("width", number(*width)), ("height", number(*height))])
|
||||
}
|
||||
Kind::Scroll { width, height } => fields.extend([
|
||||
("width", number(*width)),
|
||||
("height", number(*height)),
|
||||
("axis", Value::Text(data.scroll_axis.name().into())),
|
||||
]),
|
||||
Kind::Spacer(size) => fields.push(("size", number(*size))),
|
||||
_ => {}
|
||||
}
|
||||
@@ -390,6 +394,12 @@ pub fn apply_visual_property(data: &mut Data, name: &str, value: &Value) -> Resu
|
||||
crate::document::parse_color(value).map_err(|_| bad())?;
|
||||
color.clone_from(value);
|
||||
}
|
||||
(Kind::Scroll { .. }, "axis") => {
|
||||
let Value::Text(name) = value else {
|
||||
return Err(bad());
|
||||
};
|
||||
data.scroll_axis = crate::scroll::Axis::parse(name)?;
|
||||
}
|
||||
(Kind::Scroll { width, .. }, "width") => *width = number()?,
|
||||
(Kind::Scroll { height, .. }, "height") => *height = number()?,
|
||||
(Kind::Rect { width, .. }, "width") => *width = number()?,
|
||||
|
||||
@@ -3889,6 +3889,141 @@ page.render(block)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scroll_axes_wrap_shared_text_and_clamp_only_the_enabled_offsets() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
include_str!("../examples/scroll-axis.endor"),
|
||||
"app.main",
|
||||
260,
|
||||
1,
|
||||
)
|
||||
.unwrap();
|
||||
initial.validate().unwrap();
|
||||
for expression in [
|
||||
"vertical.mounts().at(0).scrollPosition().maxX",
|
||||
"horizontal.mounts().at(0).scrollPosition().maxY",
|
||||
] {
|
||||
assert_eq!(session.execute(expression, "app.main").unwrap().value, "0");
|
||||
}
|
||||
session
|
||||
.execute(
|
||||
"vertical.mounts().at(0).scrollTo(100, 60)\nhorizontal.mounts().at(0).scrollTo(60, 100)",
|
||||
"app.main",
|
||||
)
|
||||
.unwrap();
|
||||
for (expression, expected) in [
|
||||
("vertical.mounts().at(0).scrollPosition().x", "0"),
|
||||
("vertical.mounts().at(0).scrollPosition().y", "60"),
|
||||
("horizontal.mounts().at(0).scrollPosition().x", "60"),
|
||||
("horizontal.mounts().at(0).scrollPosition().y", "0"),
|
||||
] {
|
||||
assert_eq!(
|
||||
session.execute(expression, "app.main").unwrap().value,
|
||||
expected
|
||||
);
|
||||
}
|
||||
let vertical_width: f32 = session
|
||||
.execute("paragraph.mounts().at(0).bounds().width", "app.main")
|
||||
.unwrap()
|
||||
.value
|
||||
.parse()
|
||||
.unwrap();
|
||||
let horizontal_width: f32 = session
|
||||
.execute("paragraph.mounts().at(1).bounds().width", "app.main")
|
||||
.unwrap()
|
||||
.value
|
||||
.parse()
|
||||
.unwrap();
|
||||
assert!(vertical_width <= 244.0);
|
||||
assert!(horizontal_width > vertical_width);
|
||||
session
|
||||
.execute("horizontal.axis = \"vertical\"", "app.main")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("horizontal.mounts().at(0).scrollPosition().x", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"0"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scroll_axis_defaults_to_both_and_rejects_unknown_policy() {
|
||||
let mut session = ReplSession::new(262).unwrap();
|
||||
session
|
||||
.execute(
|
||||
"scroller = ScrollBlock(20, 10, TextBlock(\"default\"))",
|
||||
"app.main",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session.execute("scroller.axis", "app.main").unwrap().value,
|
||||
"\"both\""
|
||||
);
|
||||
let error = ReplSession::load(
|
||||
r#"
|
||||
scroller = ScrollBlock(20, 10, TextBlock("bad"))
|
||||
scroller.axis = "diagonal"
|
||||
page = Page()
|
||||
page.render(scroller)
|
||||
"#,
|
||||
"app.main",
|
||||
263,
|
||||
1,
|
||||
)
|
||||
.err()
|
||||
.expect("invalid axis");
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("ScrollBlock.axis expects both, vertical or horizontal"),
|
||||
"{error:#}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scroll_axis_uses_source_allocated_viewport_instead_of_constructor_width() {
|
||||
let source = r#"
|
||||
class Allocator: Column {
|
||||
function arrange(self: Allocator, mount: Mount, geometry: Bounds): Arrangement {
|
||||
result = Column.arrange(self, mount, geometry)
|
||||
result.children.at(0).width = 120
|
||||
return result
|
||||
}
|
||||
}
|
||||
text = TextBlock("This text must wrap inside the allocated viewport, not the original constructor width. This text must wrap inside the allocated viewport.")
|
||||
scroller = ScrollBlock(300, 80, text)
|
||||
scroller.padding = 10
|
||||
scroller.axis = "vertical"
|
||||
page = Page()
|
||||
page.render(Allocator(0, 0, scroller))
|
||||
"#;
|
||||
let (mut session, initial) = ReplSession::load(source, "app.main", 261, 1).unwrap();
|
||||
initial.validate().unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("scroller.mounts().at(0).bounds().width", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"120"
|
||||
);
|
||||
let width: f32 = session
|
||||
.execute("text.mounts().at(0).bounds().width", "app.main")
|
||||
.unwrap()
|
||||
.value
|
||||
.parse()
|
||||
.unwrap();
|
||||
assert!(width <= 100.0);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("scroller.mounts().at(0).scrollPosition().maxX", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"0"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_scroll_into_view_and_source_paint_share_clipped_geometry() {
|
||||
let mut session = ReplSession::new(241).unwrap();
|
||||
|
||||
+28
-2
@@ -65,8 +65,12 @@ pub fn root_constraints(viewport: Option<Size>) -> [f32; 4] {
|
||||
[0.0, 0.0, size.width, size.height]
|
||||
}
|
||||
pub fn child_constraints(node: &UiNode, parent: [f32; 4]) -> [f32; 4] {
|
||||
if matches!(node.kind, UiKind::Scroll { .. }) {
|
||||
return [0.0, 0.0, MAX_DIMENSION as f32, MAX_DIMENSION as f32];
|
||||
if let UiKind::Scroll { width, height, .. } = node.kind {
|
||||
return arranged_child_constraints(
|
||||
node,
|
||||
parent,
|
||||
constrained(Size { width, height }, parent),
|
||||
);
|
||||
}
|
||||
match container(node) {
|
||||
Some((true, padding, _)) => [
|
||||
@@ -84,6 +88,28 @@ pub fn child_constraints(node: &UiNode, parent: [f32; 4]) -> [f32; 4] {
|
||||
None => parent,
|
||||
}
|
||||
}
|
||||
/// Scroll cross-axis constraints come from this occurrence's actual viewport,
|
||||
/// including a source parent's allocation rather than only constructor size.
|
||||
pub fn arranged_child_constraints(node: &UiNode, available: [f32; 4], bounds: Size) -> [f32; 4] {
|
||||
if let UiKind::Scroll { padding, axis, .. } = node.kind {
|
||||
return [
|
||||
0.0,
|
||||
0.0,
|
||||
if axis.horizontal() {
|
||||
MAX_DIMENSION as f32
|
||||
} else {
|
||||
(bounds.width - padding * 2.0).max(0.0)
|
||||
},
|
||||
if axis.vertical() {
|
||||
MAX_DIMENSION as f32
|
||||
} else {
|
||||
(bounds.height - padding * 2.0).max(0.0)
|
||||
},
|
||||
];
|
||||
}
|
||||
child_constraints(node, available)
|
||||
}
|
||||
|
||||
pub fn constrained(size: Size, constraints: [f32; 4]) -> Size {
|
||||
Size {
|
||||
width: size.width.clamp(constraints[0], constraints[2]),
|
||||
|
||||
@@ -213,7 +213,11 @@ impl NativeCallable for Method {
|
||||
.map(|child| {
|
||||
size(
|
||||
child,
|
||||
layout::child_constraints(&node, [0.0, 0.0, width, height]),
|
||||
layout::arranged_child_constraints(
|
||||
&node,
|
||||
[0.0, 0.0, width, height],
|
||||
Size { width, height },
|
||||
),
|
||||
)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
|
||||
+47
-2
@@ -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;
|
||||
|
||||
@@ -248,6 +248,7 @@ impl RenderCache {
|
||||
color: color.clone(),
|
||||
},
|
||||
Kind::Scroll { width, height } => UiKind::Scroll {
|
||||
axis: data.scroll_axis,
|
||||
width: *width,
|
||||
height: *height,
|
||||
padding: data.padding,
|
||||
|
||||
@@ -487,7 +487,11 @@ impl NativeCallable for Settle {
|
||||
if height != plan.sizes[index].height {
|
||||
available[3] = height;
|
||||
}
|
||||
let base = layout::child_constraints(&plan.nodes[index], available);
|
||||
let base = layout::arranged_child_constraints(
|
||||
&plan.nodes[index],
|
||||
available,
|
||||
Size { width, height },
|
||||
);
|
||||
for child in children {
|
||||
let mut constraints = base;
|
||||
if let Some(width) = plan.allocations[*child][0] {
|
||||
|
||||
+4
-1
@@ -124,6 +124,7 @@ impl UiNode {
|
||||
(UiKind::Spacer(a), UiKind::Spacer(b)) => a == b,
|
||||
(
|
||||
UiKind::Scroll {
|
||||
axis: aa,
|
||||
width: a,
|
||||
height: b,
|
||||
padding: pa,
|
||||
@@ -131,13 +132,14 @@ impl UiNode {
|
||||
children: _,
|
||||
},
|
||||
UiKind::Scroll {
|
||||
axis: ab,
|
||||
width: c,
|
||||
height: d,
|
||||
padding: pb,
|
||||
gap: gb,
|
||||
children: _,
|
||||
},
|
||||
) => a == c && b == d && pa == pb && ga == gb && same_children(),
|
||||
) => aa == ab && a == c && b == d && pa == pb && ga == gb && same_children(),
|
||||
(
|
||||
UiKind::Column {
|
||||
padding: a, gap: b, ..
|
||||
@@ -197,6 +199,7 @@ pub enum UiKind {
|
||||
},
|
||||
Spacer(f32),
|
||||
Scroll {
|
||||
axis: crate::scroll::Axis,
|
||||
width: f32,
|
||||
height: f32,
|
||||
padding: f32,
|
||||
|
||||
Reference in New Issue
Block a user