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:
@@ -200,7 +200,7 @@ Visual, EventTarget, Children and Presentable are explicit managed Trait definit
|
||||
|
||||
A plain source object can declare Presentable by implementing `present(self, window: Window): Block` and calling `ui.implement(MyType, Presentable)`. `ui.present(value)` invokes this method with the calling window and checks the returned actual Block; `ui.open(value)` also opens the result in a Page. Block values pass through directly. The existing summary viewer remains the fallback for unregistered values, and merely viewing a function does not execute it. Presentation runs through the same bounded VM call sequence; there is no recursive host evaluator. A source adapter can keep the original object through fields/callbacks/bindings; [presentable.endor](examples/presentable.endor) shows a source-preserving view and GUI calls to the original object's method. Presentation methods are ordinary calls; visual measure/arrange/paint/hitTest still run read-only and check their nominal results at runtime. Source implementations of EventTarget.on/dispatch must provide the contract's canonical 3/2 arguments after self; native methods retain their existing optional convenience arguments.
|
||||
|
||||
`ScrollBlock(width, height, child)` is a ContainerBlock with a bounded viewport and unconstrained content measurement. It also supports inherited child operations and padding/gap. Its width/height are managed attributes and can be bound or assigned. Each attached Mount owns its scroll offset; two occurrences of the same ScrollBlock scroll independently. Moving/remounting content creates a new Mount and starts at zero. Changes to content or viewport clamp offsets to the new limits.
|
||||
`ScrollBlock(width, height, child)` is a ContainerBlock with a bounded viewport. Its `axis` attribute defaults to `"both"`, preserving unconstrained content measurement. `"vertical"` wraps/restricts content to the actual occurrence viewport width minus padding, while `"horizontal"` restricts its height. The disabled axis has a zero offset/limit, including after a live axis change. Source-arranged viewport dimensions participate in remeasurement. Child stacking remains Column-like; use a Row child for horizontal composition. See [scroll-axis.endor](examples/scroll-axis.endor). It also supports inherited child operations and padding/gap. Its width/height are managed attributes and can be bound or assigned. Each attached Mount owns its scroll offset; two occurrences of the same ScrollBlock scroll independently. Moving/remounting content creates a new Mount and starts at zero. Changes to content or viewport clamp offsets to the new limits.
|
||||
|
||||
`mount.scrollTo(x,y)` and `scrollBy(dx,dy)` update that occurrence; multiple relative requests in one input accumulate. `scrollPosition()` returns a snapshot with x/y/maxX/maxY from the last committed layout. `mount.scrollIntoView()` minimally adjusts all scrollable ancestors, and requestFocus() uses it too. Requests settle at the same successful input/event boundary as other UI changes. Detached mounts and mutations during read-only rendering are rejected. Wheel input selects an eligible scrolling ancestor of the foremost visible occurrence, with outer scrolling when the inner range is exhausted; Shift+wheel selects the horizontal axis. A diagonal gesture currently goes to one eligible container rather than splitting axes across ancestors. Scrollbars/thumb dragging, touch inertia and PageUp/PageDown are not yet implemented.
|
||||
|
||||
@@ -262,7 +262,7 @@ Native TextBlock measurement now uses the occurrence's maximum width, with word
|
||||
|
||||
Native TextBlock painting carries its allocated width/height into the immutable frame and clips glyphs to those bounds as well as any enclosing scroll clip. Measurement and drawing use the same font/shaping implementation; drawing shapes at the device font size. Zero-width or zero-height paint bounds draw nothing. Management UI text keeps its existing single-line/explicit-newline behavior.
|
||||
|
||||
Source `PaintCommand` text may supply both `wrapWidth` and `wrapHeight` as finite nonnegative logical dimensions up to 1000000. Omitting both preserves unwrapped text; supplying only one is rejected. `TextBlock.paint` returns these fields, so a source override can preserve or explicitly change the boundary. Changing paint bounds does not renegotiate layout: source arrange supplies child Bounds and changed dimensions participate in the layout solve. Row's unbounded main axis and ScrollBlock's unbounded content continue their current policies; flex allocation and automatic vertical-only scroll wrapping remain pending. Fractional-DPI wrap boundaries need broader platform validation.
|
||||
Source `PaintCommand` text may supply both `wrapWidth` and `wrapHeight` as finite nonnegative logical dimensions up to 1000000. Omitting both preserves unwrapped text; supplying only one is rejected. `TextBlock.paint` returns these fields, so a source override can preserve or explicitly change the boundary. Changing paint bounds does not renegotiate layout: source arrange supplies child Bounds and changed dimensions participate in the layout solve. Row's unbounded main-axis policy and flex allocation remain pending. ScrollBlock's axis policy now controls cross-axis wrapping and scrolling. Fractional-DPI wrap boundaries need broader platform validation.
|
||||
|
||||
A source subclass can override `paint(self, mount, geometry): DisplayList`. The renderer invokes that method for each occurrence, after Mount synchronization and hooks, using current logical Bounds. Its commands replace that occurrence's native paint in preorder. Calling `RectBlock.paint(self, mount, geometry)` or another native base method obtains a fresh result that can be modified before returning. `DisplayList(ObjectList(command, ...))` builds multiple commands; ObjectList accepts objects and has a 10000-member bound. PaintCommand fields use kind (`roundedRect`, `strokeRoundedRect` or `text`), x/y/color and the corresponding width/height/radius, strokeWidth, or text/size fields. Commands must pass the same native validation and a total 10000-command frame limit. See [source-paint.endor](examples/source-paint.endor), including a Button source method that updates the same tint field used by two occurrences.
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
| File | Purpose |
|
||||
| --- | --- |
|
||||
| [scroll-axis.endor](scroll-axis.endor) | One shared TextBlock in vertical and horizontal viewports, live axis changes and independent offsets. |
|
||||
| [windows.endor](windows.endor) | Two real native windows in one Aster VM, live shared counter state and explicit Page ownership. |
|
||||
| [tabs.endor](tabs.endor) | Three real Page tabs, shared counter state, source titles, native switching/closing and reopening through code. |
|
||||
| [window.endor](window.endor) | A managed native Window resizes the actual shell; source callbacks update it and layout follows reported dimensions. |
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
class Actions {
|
||||
vertical: ScrollBlock
|
||||
horizontal: ScrollBlock
|
||||
function down(self: Actions): Unit { self.vertical.mounts().at(0).scrollBy(0, 60) }
|
||||
function right(self: Actions): Unit { self.horizontal.mounts().at(0).scrollBy(60, 0) }
|
||||
function reset(self: Actions): Unit {
|
||||
self.vertical.mounts().at(0).scrollTo(0, 0)
|
||||
self.horizontal.mounts().at(0).scrollTo(0, 0)
|
||||
}
|
||||
function both(self: Actions): Unit { self.vertical.axis = "both" }
|
||||
}
|
||||
paragraph = TextBlock("这里展示的是同一个 TextBlock。左侧只允许纵向滚动,文字会按照这个 Mount 的实际视口宽度换行;右侧只允许横向滚动,文字保留横向展开。对象的文字和业务状态只有一份,每次展示的约束、几何和滚动位置分别保存。修改滚动轴也会重新测量受影响内容,并将已经不再允许的偏移夹回零。布局传播持续到受影响部分稳定,不会按固定跳数丢弃后续更新。这里展示的是同一个 TextBlock,两个视图可以拥有不同的换行结果。")
|
||||
vertical = ScrollBlock(260, 140, paragraph)
|
||||
vertical.padding = 8
|
||||
vertical.axis = "vertical"
|
||||
horizontal = ScrollBlock(260, 140, paragraph)
|
||||
horizontal.padding = 8
|
||||
horizontal.axis = "horizontal"
|
||||
actions = Actions(vertical, horizontal)
|
||||
down = Button("向下滚动")
|
||||
down.onClick(actions.down)
|
||||
right = Button("向右滚动")
|
||||
right.onClick(actions.right)
|
||||
reset = Button("回到起点")
|
||||
reset.onClick(actions.reset)
|
||||
both = Button("左侧恢复双轴")
|
||||
both.onClick(actions.both)
|
||||
page = Page()
|
||||
page.title = "滚动轴"
|
||||
page.render(Column(24, 16, TextBlock("同一个对象,不同的滚动轴", 2), Row(0, 24, Column(0, 8, TextBlock("vertical"), vertical), Column(0, 8, TextBlock("horizontal"), horizontal)), Row(0, 12, down, right, reset, both)))
|
||||
+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