Skip to content

feat: add responsive Flex and Grid placement with intrinsic sizing - #48

Merged
diiviocity merged 10 commits into
vlang:masterfrom
tomaszbk:feat/flex-grid-layout
Oct 21, 2026
Merged

diiviocity merged 10 commits into
vlang:masterfrom
tomaszbk:feat/flex-grid-layout

Conversation

@tomaszbk

@tomaszbk tomaszbk commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

A toolbar can wrap when the window becomes narrower, and a project grid can switch from three columns to one while keeping its featured card within the available width. This adds responsive Flex and Grid placement and intrinsic measurement to the V API, with fractional dimensions retained through measurement and placement.

FlexConfig and FlexChild provide direction, wrapping, gaps, justification, alignment, basis, grow/shrink weights and size bounds. GridConfig adds automatic column counts, a column cap and row/column spans. Orientation, alignment and padding use the shared LayoutOrientation, LayoutAlignment and LayoutPadding types. Existing Grid callers, fixtures and public guides use the Grid name.

LayoutConstraints and measure_layout_element separate measurement from placement. Callers can measure a width-dependent child again at its assigned width before constructing the final flex or grid. Native macOS text measurement uses AppKit; custom rendering uses its drawing measurer, with CPU measurement available before a window exists. Custom text areas account for wrapped rows, blank lines, long words, padding and the scrollbar gutter.

The responsive and Grid examples construct layouts in V. The public guide describes the measurement and placement steps; the benchmark exercises text measurement, wrapping, nested Flex containers and responsive Grid geometry. The branch includes current upstream ui2 15709bb.

Verification

On macOS arm64 with rebuilt V source including upstream f2b0baa611, the C backend, default program GC and V_MACOS_V3_NO_FALLBACK=1:

  • Layout, measurement and example tests: 7/7 native and 6/6 custom passed, including independent fractional geometry and assigned-width measurement fixtures.
  • The custom scrolling and adaptive VML test files also passed (8/8 custom files in total), checking the upstream scroll integration and existing interpreter layout callers.
  • make check-macos, check-linux, check-windows and check-custom passed. Cross-target checks are typechecks.
  • git diff --check passed for the full diff against upstream master. Public Grid documentation uses the current V/VML names.

Add FlexLayout and extend GridLayout with spans, automatic columns and
content measurement, shared by native backends and the custom renderer,
in the V API and runtime VML.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tomaszbk and others added 7 commits October 1, 2026 21:12
Each Flex level measured its subtree twice (before and after assigning
widths), and nested levels repeated that, so intrinsic measurement grew
exponentially with nesting depth.

A per-build VLayoutMeasureCache now memoizes Flex/Grid preferred sizes by
structural content and probe size, plus leaf sizes measured inside another
container's measurement. Keys intern tag, id, resolved props and children
rather than node paths, so Repeater items and scope-dependent expressions
stay distinct. The model path keeps the cache in VmlEvaluation; static
documents use one per FlexLayout. Nothing persists between builds. The
flex/grid solver is unchanged.

Verified identical element trees (frames, text, hidden) against the
previous code for the responsive example, nested Flex and a Repeater/Grid
document at four window sizes, native and custom. Benchmark (-prod,
AppKit text): nested 10 levels 83 ms -> 1.6-2.5 ms, responsive example
6.2 -> 3.0 ms, flat 200-label wrap unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tomaszbk tomaszbk changed the title feat: add responsive flex and grid layout with intrinsic sizing feat: add responsive Flex and Grid placement with intrinsic sizing Oct 10, 2026
tomaszbk and others added 2 commits October 13, 2026 23:31
# Conflicts:
#	examples/grid_layout/main.v
#	ui/box_layout_test.v
#	ui/grid_layout_test.v
#	ui/ui_custom_test.v
@diiviocity
diiviocity merged commit de1ff9e into vlang:master Oct 21, 2026
0 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants