ugui.c3l/src/ugui_text.c3

27 lines
629 B
Plaintext
Raw Normal View History

2024-12-11 01:14:14 +01:00
module ugui;
import std::io;
2024-12-11 22:25:53 +01:00
2024-12-11 01:14:14 +01:00
fn void! Ctx.text_unbounded(&ctx, String label, String text)
{
Id id = ctx.gen_id(label)!;
2024-12-11 01:14:14 +01:00
Elem *parent = ctx.get_parent()!;
2024-12-19 15:24:39 +01:00
Elem *elem = ctx.get_elem(id)!;
2024-12-11 01:14:14 +01:00
// add it to the tree
ctx.tree.add(id, ctx.active_div)!;
// 1. Fill the element fields
// this resets the flags
2024-12-19 15:24:39 +01:00
elem.type = ETYPE_TEXT;
2024-12-11 01:14:14 +01:00
// if the element is new or the parent was updated then redo layout
2024-12-18 14:58:40 +01:00
Rect text_size = ctx.get_text_bounds(text)!;
// 2. Layout
2024-12-19 15:24:39 +01:00
elem.bounds = ctx.position_element(parent, text_size, true);
2024-12-18 14:58:40 +01:00
// 3. Fill the button specific fields
2024-12-19 15:24:39 +01:00
elem.text.str = text;
2024-12-11 01:14:14 +01:00
2024-12-19 15:24:39 +01:00
ctx.push_string(elem.bounds, text)!;
2024-12-11 01:14:14 +01:00
}