Skip to content

layout: add weighted child sizing#77

Merged
GGRei merged 1 commit into
vlang:mainfrom
GGRei:feature/weighted-child-layout
Jul 12, 2026
Merged

layout: add weighted child sizing#77
GGRei merged 1 commit into
vlang:mainfrom
GGRei:feature/weighted-child-layout

Conversation

@GGRei

@GGRei GGRei commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Add gui.weighted() for assigning proportional main-axis space to container children.

A row distributes width, while a column or circle distributes height:

gui.weighted(weight: 2, view: gui.button(...))

The implementation:

  • supports constrained 1:1:2-style layouts;
  • redistributes space correctly around minimum and maximum sizes;
  • recalculates proportions when the parent is resized;
  • preserves the existing layout path when no weights are used;
  • adds no extra Layout node and does not change the View interface;
  • rejects invalid weights and unsupported configurations explicitly;
  • includes documentation and a resizable button example.

Validation

  • Weighted layout tests pass with Clang in normal and production modes.
  • Existing layout, wrap, border, GC leak and GC lint tests pass.
  • Documentation and formatting checks pass.
  • No allocations occur during distribution after warm-up.
  • examples/weighted_layout.v compiles cleanly with -W and runs successfully.

Fix #71
Codex review validation

@squidink7

squidink7 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Works well in my tests! My only question is to whether view as a property name is consistent with the rest of this library which seems to use content, however that usually refers to several child views while this takes only one. Is there anywhere else where this is the case?

@GGRei

GGRei commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking this. The closest existing precedent is OverflowItem.view View, which also holds one arbitrary view.

There are singular content cases such as ExpandPanelCfg.content, but there content specifically represents the panel body. weighted is a transparent decorator, it applies metadata to exactly one view and adds no container or layout node.

For that reason, I think view is the more precise name here.

@GGRei
GGRei merged commit 88a509a into vlang:main Jul 12, 2026
4 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.

Feature request: child layout sizing ratio

2 participants