Skip to content

Label

Source: src/widgets/label.odin
FlashBang API: flashbang.Label, type LabelConfig.

What it does

label(ctx, config) draws a single line of text as a TEXT_RUN draw op. It does not allocate a separate “label object”; it runs immediately when called.

  1. Resolves text color: optional config.color, else active_theme(ctx).text_color, else opaque white if no theme pointer.
  2. Measures text via ctx.text_backend.measure_text (if non-nil).
  3. apply_layout_override(config.id, …) on x,y,w,h (height becomes measured height; width stays from config unless override changes it).
  4. Applies origin_x / origin_y.
  5. If config.w > 0, horizontally centers the glyph run in that width; otherwise uses measured width for placement.
  6. Emits TEXT_RUN with arena-allocated payload (string bytes as in source).
  7. Sets last_widget_w / last_widget_h and store_widget_dims when id is set.

LabelConfig

Field Role
id Optional — dimension map + layout override.
text UTF-8 string content.
font_id, font_size Text backend parameters.
color Optional Maybe(style.Color) override.
x, y Position (before origin offset).
w If > 0, text is centered in this width; if 0, width follows measurement.

Interaction and focus

Non-interactive in the usual sense: no hover/click state. Hit testing for tools built on top must use the stored rect (GetWidth/GetHeight with id or last-widget getters).

Theming

Uses active_theme only for default text_color. It does not call resolve_surface or emit_surface—only text is drawn.

Example

flashbang.Label(ctx, flashbang.LabelConfig{
    id = "title",
    text = "Settings",
    font_id = font,
    font_size = 18,
    x = margin_x,
    y = margin_y,
    w = 200, // center within 200px
})