color table, string_pos_offset

This commit is contained in:
Krzosa Karol
2025-01-26 08:24:09 +01:00
parent 0a6654c15d
commit 7831cc51d6
7 changed files with 183 additions and 109 deletions

View File

@@ -1,26 +1,50 @@
// gb_read_only v4f32_t primary_color_global = v4f32_rgba(245, 238, 230, 255);
// gb_read_only v4f32_t secondary_color_global = v4f32_rgba(255, 248, 227, 255);
// gb_read_only v4f32_t accent1_color_global = v4f32_rgba(243, 215, 202, 255);
// gb_read_only v4f32_t accent2_color_global = v4f32_rgba(230, 164, 180, 255);
fn void mt_ui_colors(ma_arena_t *arena, sb8_t *c, sb8_t *h) {
ast_t *table = mtt_parse(arena, __FILE__, S8_CODE(
{ name color }
{ rect_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.95f, 1.0f})` }
{ rect_hot_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.5f, 0.95f, 1.0f})` }
{ rect_active_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.95f, 1.0f})` }
{ border_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f})` }
{ text_color `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.70f, 1.0f})` }
{ text_hot_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.4f, 0.70f, 1.0f})` }
{ text_active_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.70f, 1.0f})` }
{ focused_rect_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.95f, 1.0f})` }
{ scroller_color `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.6f, 0.95f, 1.0f})` }
));
mtt_serial_enum(c, h, table, s8_lit("ui_color"));
sb8_stmtf(c, "gb v4f32_t ui_color_table[] = {");
for (ast_t *it = table->first; it; it = it->next) {
mt_stmtf(c, it, "{0},");
}
sb8_stmtf(c, "};\n");
sb8_stmtf(c, "fn void ui_init_colors(void) {");
for (ast_t *it = table->first; it; it = it->next) {
mt_stmtf(c, it, "ui_color_table[ui_color_@name] = @color;");
}
sb8_stmtf(c, "}\n");
}
fn void mt_ui_stacks(ma_arena_t *arena, sb8_t *c, sb8_t *h) {
ast_t *table = mtt_parse(arena, __FILE__, S8_CODE(
// skip = don't include in ui_box_t as field
{ type name skip init }
{ ui_id_t id 1 `ui_idf("root")` }
{ ui_lop_t lop 1 ui_lop_cut_top }
{ f32 border_thickness 0 1.0f }
{ ui_text_align_t text_align 0 ui_text_align_left }
{ f32 required_size 0 x }
{ f32 padding 0 x }
{ v4f32_t background_color 0 `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.95f, 1.0f})` }
{ v4f32_t bg_hot_color 0 `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.5f, 0.95f, 1.0f})` }
{ v4f32_t bg_active_color 0 `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.95f, 1.0f})` }
{ v4f32_t border_color 0 `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.7f, 1.0f})` }
{ v4f32_t text_color 0 `v4f32_hsla_to_rgba((v4f32_t){0.0f, 0.2f, 0.7f, 1.0f})` }
{ v4f32_t text_hot_color 0 `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.4f, 0.7f, 1.0f})` }
{ v4f32_t text_active_color 0 `v4f32_hsla_to_rgba((v4f32_t){0.1f, 0.5f, 0.7f, 1.0f})` }
// skip = don't include in ui_box_t as field
{ type name skip init }
{ ui_id_t id 1 `ui_idf("root")` }
{ ui_lop_t lop 1 ui_lop_cut_top }
{ f32 border_thickness 0 1.0f }
{ ui_text_align_t text_align 0 ui_text_align_left }
{ f32 required_size 0 x }
{ f32 padding 0 x }
{ f32 string_pos_offset 0 0 }
{ v4f32_t background_color 0 `ui_color_table[ui_color_rect_color]` }
{ v4f32_t bg_hot_color 0 `ui_color_table[ui_color_rect_hot_color]` }
{ v4f32_t bg_active_color 0 `ui_color_table[ui_color_rect_active_color]` }
{ v4f32_t border_color 0 `ui_color_table[ui_color_border_color]` }
{ v4f32_t text_color 0 `ui_color_table[ui_color_text_color]` }
{ v4f32_t text_hot_color 0 `ui_color_table[ui_color_text_hot_color]` }
{ v4f32_t text_active_color 0 `ui_color_table[ui_color_text_active_color]` }
));
///////////////////////////////
@@ -124,6 +148,7 @@ fn void mt_ui(ma_arena_t *arena) {
sb8_printf(h, "// automatically generated using: " __FILE__ "\n");
sb8_printf(c, "// automatically generated using: " __FILE__ "\n");
mt_ui_colors(arena, c, h);
mt_ui_stacks(arena, c, h);
os_write_file(mt_cpath(arena), sb8_serial_end(arena, c));