Raxol.UI.Layout.FlexItem (Raxol v2.6.1)

View Source

A flex child resolved into the inputs the flexible-length solver needs.

This is the interface contract between element resolution and the flexible-length solver. One FlexItem is resolved per child before distribution; Flexbox.Solver then works exclusively on these — it never reads raw elements or style maps.

Semantics

  • base_size — resolved flex-basis; :auto resolves via the measure function passed to resolve/5.
  • style: %{flex: n} expands to grow n / shrink 1 / basis 0 AND min_main: 0, so equal columns actually equalize. An explicit min_width/min_height still wins over the sugar.
  • {:pct, n} resolves against the container's dimension when definite, else behaves as :auto (spec). Margin percentages always resolve against the container's WIDTH (spec).
  • Invalid values (negative sizes/factors, malformed percentages) clamp to the nearest valid value and emit [:raxol, :layout, :invalid_style] — layout never raises on style input.
  • margin sides may be :auto, treated as 0 for sizing (outer_main/2); positioning distributes free space into them.

frozen, frozen_reason, and main_size belong to the resolve-flexible-lengths loop and live here so the struct is the single currency across resolution, distribution, and positioning.

Summary

Functions

Clamp a candidate main size into the item's [min_main, max_main].

Cross-axis {start, end} margins for the given MAIN axis.

Hypothetical main size: base size clamped (spec 9.7 step 1 input).

Expands the flex shorthand plus explicit grow/shrink/basis keys.

Main-axis {start, end} margins for the given axis.

Outer main size: margins + size; :auto margins count as 0 here.

Resolves a single dimension value against a containing dimension.

Types

dimension()

@type dimension() :: non_neg_integer() | :infinity

margin_side()

@type margin_side() :: non_neg_integer() | :auto

pct()

@type pct() :: {:pct, number()}

t()

@type t() :: %Raxol.UI.Layout.FlexItem{
  align_self: atom() | nil,
  base_size: non_neg_integer(),
  cross_size: non_neg_integer() | nil,
  element: map(),
  frozen: boolean(),
  frozen_reason: nil | :inflexible | :min_violation | :max_violation,
  grow: non_neg_integer(),
  main_size: non_neg_integer() | nil,
  margin: {margin_side(), margin_side(), margin_side(), margin_side()},
  max_cross: dimension(),
  max_main: dimension(),
  min_cross: non_neg_integer(),
  min_main: non_neg_integer(),
  shrink: non_neg_integer()
}

Functions

clamp_main(flex_item, size)

Clamp a candidate main size into the item's [min_main, max_main].

cross_margins(flex_item, atom)

Cross-axis {start, end} margins for the given MAIN axis.

hypothetical_main(item)

Hypothetical main size: base size clamped (spec 9.7 step 1 input).

lift_flex(style, attrs \\ %{})

Expands the flex shorthand plus explicit grow/shrink/basis keys.

Returns %{grow, shrink, basis, min_main_override}.

  • flex: n (int) -> grow n, shrink 1, basis 0, min_main_override 0
  • flex: {g, s, b} -> as given, no min override
  • flex: %{...} map -> grow/shrink/basis keys, no min override
  • legacy attrs.flex -> same as map form (lowest precedence)

main_margins(flex_item, atom)

Main-axis {start, end} margins for the given axis.

margin_int(n)

outer_main(item, size, main_axis)

Outer main size: margins + size; :auto margins count as 0 here.

resolve(child, main_axis, container, content_size_fun, auto_min_fun \\ fn -> 0 end)

Resolves a raw child element into a FlexItem.

  • child — element map (style read from :style, flex attrs also honored from legacy child.attrs.flex for back-compat)
  • main_axis:horizontal | :vertical

  • container%{width: definite | nil, height: definite | nil}; nil marks an indefinite dimension (percentages resolve to :auto)

  • content_size_fun — zero-arg fun returning the content main size; called ONLY when basis resolves to :auto
  • auto_min_fun — zero-arg fun returning the automatic minimum size (spec min-width: auto = min-content); called ONLY when no explicit min is set and no sugar override applies. Defaults to 0.

resolve_dimension(n, container)

Resolves a single dimension value against a containing dimension.

int -> int (clamped non-negative); {:pct, n} -> rounded share of a definite container, :auto against an indefinite one; nil/:auto -> :auto.