Align native container children within allocated main-axis bounds
Verify Tessera GUI / verify (push) Failing after 7m55s
Verify Tessera GUI / verify (push) Failing after 7m55s
This commit is contained in:
@@ -487,3 +487,5 @@ Native layout/paint fast paths and the default event classification inspect the
|
||||
Block.click returns the generated Event and Block.dispatch returns the delivered Event, preserving the event object from the dispatch pipeline. Native return signatures match these actual results, including GUI activation.
|
||||
|
||||
Event dispatch/click and lifecycle entry points publish External as their allowed effect bound: handlers may mutate application state or use host I/O APIs. The built-in no-op bodies do not make the overridable handler contract ReadOnly. These entry points still reject invocation inside read-only rendering.
|
||||
|
||||
ContainerBlock.mainAlign is a managed attribute with start (default), center, end and space-between policies. It positions children in the allocated main-axis space after padding and the configured minimum gap. Center/end use remaining positive space; space-between adds it between two or more children. Overflow keeps start positions and existing sizes; alignment does not imply flex sizing. Native arrange queries and rendering use the same actual Bounds. Source arrange overrides retain their explicit placements.
|
||||
|
||||
@@ -137,3 +137,5 @@ Native TextBlock measurement and painting now share width-sensitive shaping. Col
|
||||
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.
|
||||
|
||||
Container mainAlign projects from managed properties into UiNode and its shallow equality. Native arrangement receives the actual allocated Size, computes positive remaining main-axis space and keeps child sizes unchanged.
|
||||
|
||||
@@ -1117,6 +1117,8 @@ managed click/focus methods used by code. Events appear in Network, not Console
|
||||
|
||||
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.
|
||||
|
||||
ContainerBlock.mainAlign accepts "start" (default), "center", "end" or "space-between". Native arrangement uses allocated Bounds after padding/minimum gap, distributes positive remaining main-axis space and keeps child sizes unchanged. Overflow keeps start placement. Explicit source arrange placements remain authoritative; this is alignment, not flex sizing.
|
||||
|
||||
## UI host object
|
||||
|
||||
Positional arguments only:
|
||||
|
||||
+14
-1
@@ -117,6 +117,7 @@ pub struct Data {
|
||||
pub children: Vec<Child>,
|
||||
pub padding: f32,
|
||||
pub gap: f32,
|
||||
pub main_align: crate::layout::MainAlign,
|
||||
pub scroll_axis: crate::scroll::Axis,
|
||||
pub next_slot: u64,
|
||||
pub history: Vec<ObjectRef>,
|
||||
@@ -143,6 +144,7 @@ impl Data {
|
||||
.collect(),
|
||||
padding,
|
||||
gap,
|
||||
main_align: crate::layout::MainAlign::Start,
|
||||
scroll_axis: crate::scroll::Axis::Both,
|
||||
next_slot,
|
||||
history: vec![],
|
||||
@@ -340,7 +342,11 @@ pub fn native_properties(data: &Data) -> Vec<(&'static str, Value)> {
|
||||
_ => {}
|
||||
}
|
||||
if data.is_container() {
|
||||
fields.extend([("padding", number(data.padding)), ("gap", number(data.gap))]);
|
||||
fields.extend([
|
||||
("padding", number(data.padding)),
|
||||
("gap", number(data.gap)),
|
||||
("mainAlign", Value::Text(data.main_align.name().into())),
|
||||
]);
|
||||
}
|
||||
fields
|
||||
}
|
||||
@@ -370,6 +376,13 @@ pub fn apply_visual_property(data: &mut Data, name: &str, value: &Value) -> Resu
|
||||
Ok(n)
|
||||
};
|
||||
let container = data.is_container();
|
||||
if container && name == "mainAlign" {
|
||||
let Value::Text(value) = value else {
|
||||
return Err(bad());
|
||||
};
|
||||
data.main_align = crate::layout::MainAlign::parse(value)?;
|
||||
return Ok(());
|
||||
}
|
||||
match (&mut data.kind, name) {
|
||||
(Kind::Text { value: text, .. }, "text") => {
|
||||
let Value::Text(value) = value else {
|
||||
|
||||
@@ -3889,6 +3889,52 @@ page.render(block)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn main_alignment_updates_live_geometry_without_changing_sizes() {
|
||||
let (mut session, initial) = ReplSession::load(r#"
|
||||
class Wide: Row {
|
||||
function measure(self: Wide, mount: Mount, constraints: Constraints): MeasureResult { return MeasureResult(300, 60) }
|
||||
}
|
||||
first = RectBlock(20, 20)
|
||||
second = RectBlock(40, 40)
|
||||
row = Wide(10, 10, first, second)
|
||||
page = Page()
|
||||
page.render(row)
|
||||
"#, "app.main", 264, 1).unwrap();
|
||||
initial.validate().unwrap();
|
||||
for (mode, first, second) in [
|
||||
("start", "10", "40"),
|
||||
("center", "115", "145"),
|
||||
("end", "220", "250"),
|
||||
("space-between", "10", "250"),
|
||||
] {
|
||||
session
|
||||
.execute(&format!("row.mainAlign = \"{mode}\""), "app.main")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("first.mounts().at(0).bounds().x", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
first
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("second.mounts().at(0).bounds().x", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
second
|
||||
);
|
||||
assert_eq!(
|
||||
session
|
||||
.execute("first.mounts().at(0).bounds().width", "app.main")
|
||||
.unwrap()
|
||||
.value,
|
||||
"20"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scroll_axes_wrap_shared_text_and_clamp_only_the_enabled_offsets() {
|
||||
let (mut session, initial) = ReplSession::load(
|
||||
|
||||
+57
-4
@@ -10,6 +10,36 @@ use std::collections::{HashMap, HashSet};
|
||||
|
||||
const MAX_LAYOUT_VISITS: usize = 10_000;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub enum MainAlign {
|
||||
#[default]
|
||||
Start,
|
||||
Center,
|
||||
End,
|
||||
SpaceBetween,
|
||||
}
|
||||
impl MainAlign {
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
Self::Start => "start",
|
||||
Self::Center => "center",
|
||||
Self::End => "end",
|
||||
Self::SpaceBetween => "space-between",
|
||||
}
|
||||
}
|
||||
pub fn parse(value: &str) -> Result<Self, endor_core::VmError> {
|
||||
match value {
|
||||
"start" => Ok(Self::Start),
|
||||
"center" => Ok(Self::Center),
|
||||
"end" => Ok(Self::End),
|
||||
"space-between" => Ok(Self::SpaceBetween),
|
||||
_ => Err(endor_core::VmError::InvalidArgument(
|
||||
"mainAlign expects start, center, end or space-between",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Size {
|
||||
pub width: f32,
|
||||
@@ -230,11 +260,34 @@ pub fn paint_native(node: &UiNode, x: f32, y: f32, size: Size) -> Option<RenderC
|
||||
}
|
||||
}
|
||||
|
||||
pub fn arrange_native(node: &UiNode, x: f32, y: f32, children: &[Size]) -> Result<Vec<(f32, f32)>> {
|
||||
pub fn arrange_native(
|
||||
node: &UiNode,
|
||||
x: f32,
|
||||
y: f32,
|
||||
bounds: Size,
|
||||
children: &[Size],
|
||||
) -> Result<Vec<(f32, f32)>> {
|
||||
let Some((row, padding, gap)) = container(node) else {
|
||||
return Ok(vec![]);
|
||||
};
|
||||
let mut cursor = padding;
|
||||
let occupied = children
|
||||
.iter()
|
||||
.map(|child| if row { child.width } else { child.height })
|
||||
.sum::<f32>()
|
||||
+ gap * children.len().saturating_sub(1) as f32;
|
||||
let available = if row { bounds.width } else { bounds.height };
|
||||
let spare = (available - padding * 2.0 - occupied).max(0.0);
|
||||
let offset = match node.main_align {
|
||||
MainAlign::Center => spare / 2.0,
|
||||
MainAlign::End => spare,
|
||||
_ => 0.0,
|
||||
};
|
||||
let distributed_gap = if node.main_align == MainAlign::SpaceBetween && children.len() > 1 {
|
||||
spare / (children.len() - 1) as f32
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let mut cursor = padding + offset;
|
||||
let mut points = Vec::with_capacity(children.len());
|
||||
for child in children {
|
||||
let point = if row {
|
||||
@@ -248,7 +301,7 @@ pub fn arrange_native(node: &UiNode, x: f32, y: f32, children: &[Size]) -> Resul
|
||||
bounded(point.1 + child.height)?;
|
||||
points.push(point);
|
||||
cursor += if row { child.width } else { child.height };
|
||||
cursor += gap;
|
||||
cursor += gap + distributed_gap;
|
||||
}
|
||||
Ok(points)
|
||||
}
|
||||
@@ -410,7 +463,7 @@ impl LayoutRuntime {
|
||||
for (child, point) in
|
||||
item.children
|
||||
.iter()
|
||||
.zip(arrange_native(item.node, x, y, &child_sizes)?)
|
||||
.zip(arrange_native(item.node, x, y, size, &child_sizes)?)
|
||||
{
|
||||
points[*child] = point;
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ impl NativeCallable for Method {
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
};
|
||||
let points = layout::arrange_native(&node, x, y, &children)
|
||||
let points = layout::arrange_native(&node, x, y, Size { width, height }, &children)
|
||||
.map_err(|_| invalid("native arrangement exceeds limits"))?;
|
||||
let mut result = Vec::new();
|
||||
for ((slot, size), (x, y)) in node.slots.iter().zip(children).zip(points) {
|
||||
|
||||
@@ -117,6 +117,7 @@ mod tests {
|
||||
height: 160.0,
|
||||
});
|
||||
let root = UiNode {
|
||||
main_align: crate::layout::MainAlign::Start,
|
||||
block_id: "shared".into(),
|
||||
protocol_key: "rect".into(),
|
||||
slots: Vec::new(),
|
||||
|
||||
@@ -273,6 +273,7 @@ impl RenderCache {
|
||||
},
|
||||
};
|
||||
let next = UiNode {
|
||||
main_align: data.main_align,
|
||||
block_id: block.to_string(),
|
||||
protocol_key,
|
||||
slots: data.children.iter().map(|c| c.slot).collect(),
|
||||
|
||||
+3
-1
@@ -60,6 +60,7 @@ pub const QUERY_NAMES: &[&str] = &[
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct UiNode {
|
||||
pub main_align: crate::layout::MainAlign,
|
||||
pub block_id: String,
|
||||
pub protocol_key: String,
|
||||
pub slots: Vec<u64>,
|
||||
@@ -79,7 +80,8 @@ impl UiNode {
|
||||
}
|
||||
|
||||
pub fn shallow_eq(&self, other: &Self) -> bool {
|
||||
if self.block_id != other.block_id
|
||||
if self.main_align != other.main_align
|
||||
|| self.block_id != other.block_id
|
||||
|| self.protocol_key != other.protocol_key
|
||||
|| self.slots != other.slots
|
||||
|| self.interactive != other.interactive
|
||||
|
||||
Reference in New Issue
Block a user