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.
- Resolves text color: optional
config.color, elseactive_theme(ctx).text_color, else opaque white if no theme pointer. - Measures text via
ctx.text_backend.measure_text(if non-nil). apply_layout_override(config.id, …)onx,y,w,h(height becomes measured height; width stays from config unless override changes it).- Applies
origin_x/origin_y. - If
config.w > 0, horizontally centers the glyph run in that width; otherwise uses measured width for placement. - Emits
TEXT_RUNwith arena-allocated payload (string bytes as in source). - Sets
last_widget_w/last_widget_handstore_widget_dimswhenidis 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
})