Skip to content

Common widget helpers

Source: src/widgets/common.odin
Package: widgets — drawing helpers re-exported on flashbang as emit_surface and emit_separator.

These procs are used by many widgets after style.resolve_surface (and optional apply_color_override) to turn a ResolvedSurface into DrawList operations.

emit_surface

emit_surface :: proc(
    list: ^rendering.DrawList,
    resolved: ^style.ResolvedSurface,
    x, y, w, h: f32,
    theme: ^style.Theme = nil,
)
  1. If theme != nil and theme.geometry != nil, calls the theme geometry proc first (shadow/highlight/extra layers).
  2. Emits the main filled rounded rect using resolved.surface_color.
  3. If resolved.border_width > 0, emits a stroke with resolved.border_color.
  4. If resolved.focus_ring and resolved.focus_ring_width > 0, emits an outer focus ring stroke.

From app code you typically use flashbang.emit_surface after resolving a surface for a custom widget.

emit_separator

emit_separator :: proc(
    list: ^rendering.DrawList,
    resolved: ^style.ResolvedSurface,
    x, y, length: f32,
    horizontal: bool,
    theme: ^style.Theme = nil,
)

Uses theme.separator_geometry when set; otherwise draws a 1px rect along the axis using resolved.border_color.

Layout override

apply_layout_override :: proc(id: string, x, y, w, h: ^f32)

If id is non-empty and the per-frame layout rect cache has an entry for hash_id(id), replaces the pointed-to x,y,w,h with that rect. Widgets call this so an external layout backend can own geometry while you still pass local coordinates in configs.

Dimension getters

Procedure groups (no arg = last widget; string = lookup by id):

  • get_width, get_height
  • get_content_width, get_content_height — last container content area when set

Re-exported on flashbang as GetWidth, GetHeight, GetContentWidth, GetContentHeight.

draw_centered_text

Centers str in a rectangle using TextBackend.measure_text, allocates stable text bytes on the draw-list arena, and emits a TEXT_RUN op. Used internally and useful for custom immediate UI.

Legacy TextBackend struct

A small TextBackend struct remains in this file for compatibility notes; immediate mode uses backends.TextBackend on ImmediateContext.