JFLib

Layout#

Source: lib/ui/layout.rs

layout -- box layout (flex-like, measured over passes)              [src/ui/ui_layout.s]

  box_begin(id, flags, gap)          open a container (id 0 = automatic)
  box_end()                          close it
  next_size(w, h)                    size of the next widget / box in DIP: > 0 fixed,
                                     0 natural, < 0 fill weight
  next_rect(x, y, w, h)              absolute placement of the next widget in DIP,
                                     relative to the current box's content origin
  next_rect_px(x, y, w, h)           absolute placement in window px (w / h 0 = natural)
  next_flags(ST_*)   next_icon(cp)   style flags / icon for the next widget
  spacer(dip)                        empty space along the main axis (< 0 = fill)
  last_rect() -> [x, y, w, h]        the last placed widget (px)
  box_rect() -> [x, y, w, h]         content rectangle of the current box (px)
  box_id() -> id                     id of the current box
  box_offset(dx, dy)                 scroll the current box's content
  avail_width(iw) -> (px, fixed)     width the next widget will get (TX_WRAP)
Internal: place(iw, ih), take_flags(), take_icon(), layout_root(), layout_end_root()

A box lays its children out along its main axis (BOX_H: x, BOX_V: y).  Fill children
share the space left by the others; because that is only known after all children were
placed, the previous pass's totals are used and a pass is repeated when they change (the
runtime caps this at 4 passes).  A box whose fill children the previous pass did not see (a
new one) gives its first fill child the room left after the children before it (first_fill):
new boxes inside new fill boxes get about their size in their first pass and settle in the
next one, however deep.

BOX_WRAP (horizontal boxes): a child that does not fit after the others of its row starts
a new row (a row's first child stays, however wide).  Each row is as tall as its tallest
child; the cross-axis alignment (BOX_XCENTER ..., stretched: the row's height) and
BOX_CENTER / BOX_END work per row with the previous pass's rows.  Natural size: the rows
and the gaps between them high, as wide as one row with every child (the box is placed at
most as wide as avail_width allows, so it wraps where the parent has less room).  Fill
children share what is left only while everything fits on one row, else they keep their
natural size.

impl Ui

  • fn next_size(&mut self, w: i32, h: i32) ui_next_size(w, h): DIP; > 0 fixed, 0 natural, < 0 fill weight

  • fn next_rect(&mut self, x: i32, y: i32, w: i32, h: i32) ui_next_rect(x, y, w, h): DIP relative to the current box's content origin

  • fn next_rect_px(&mut self, x: i32, y: i32, w: i32, h: i32) ui_next_rect_px(x, y, w, h): absolute placement of the next widget / box in window px (w or h 0 = natural size); nothing is accounted in the parent box

  • fn box_offset(&mut self, dx: i32, dy: i32) ui_box_offset(dx, dy): shift the content of the current box by (-dx, -dy) px

  • fn next_flags(&mut self, f: u32) ui_next_flags(ST_*): style flags for the next widget (OR-ed)

  • fn take_flags(&mut self) -> u32 ui_take_flags: the pending next_flags value (cleared; for widgets)

  • fn next_icon(&mut self, cp: u32) ui_next_icon(cp): icon code point (IC_*) for the next widget

  • fn take_icon(&mut self) -> u32 ui_take_icon: the pending icon (cleared; for widgets)

  • fn last_rect(&self) -> [i32; 4] ui_last_rect: [x, y, w, h] of the last placed widget (px)

  • fn box_id(&self) -> u32 ui_box_id: id of the current box (the root box's id at the top level; 0 outside a pass)

  • fn box_rect(&self) -> [i32; 4] ui_box_rect: [x, y, w, h] content rectangle of the current box (px)

  • fn box_flags(&self) -> u32 flags of the current box (ui_box_rect - 8 + 4 in the asm)

  • fn place(&mut self, iw: i32, ih: i32) -> [i32; 4] ui_place(iw, ih) -> last_rect: place the next widget (natural size in px)

  • fn avail_width(&self, iw: i32) -> (i32, i32) ui_avail_width(iw) -> (width px a wrapping widget of natural (unwrapped) width iw gets from the next place, 1 when that width does not depend on iw) -- no side effects. 0 = unknown (no wrapping).

  • fn box_begin(&mut self, id: u32, flags: u32, gap: i32) ui_box_begin(id, flags, gap): open a container (id 0 = automatic)

  • fn box_end(&mut self) ui_box_end: store the measured natural size, correct the parent's totals

  • fn spacer(&mut self, dip: i32) ui_spacer(dip): empty space along the main axis (< 0 = fill weight)

  • fn dp(&self, dip: i32) -> i32 ui_dp(dip): DIP -> physical pixels, round(dip * dpi / 96) (signed)

  • fn px2dip(&self, px: i32) -> i32 ui_px2dip(px): physical pixels -> DIP, (px * 96 + dpi / 2) / dpi

  • fn dpi(&self) -> i32 ui_dpi: current dpi of the live window (96 = 100 %)

  • fn set_dpi(&mut self, dpi: i32) ui_set_dpi(dpi): override the dpi (tests)

  • fn dp_fx(&self, dip_fx: i32) -> i32 dp_fx(dip_fx) -> px in 24.8 (dip_fx * dpi / 96, truncated)

  • fn dp_at(dip: i32, dpi: i32) -> i32 dip2px_at / dp_at: round(dip * dpi / 96) (signed)

  • fn px2dip_at(px: i32, dpi: i32) -> i32 px2dip_at: round(px * 96 / dpi), dpi 0 = 96 (ui_win.s)

Source: docs/API.md in the JFLib repository.