ui colors

This commit is contained in:
Krzosa Karol
2025-01-22 22:18:18 +01:00
parent de35c4a705
commit 057d6b6f50
13 changed files with 169 additions and 105 deletions

View File

@@ -1,16 +1,31 @@
void mt_ui(ma_arena_t *arena) {
// 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);
/*
white color 0xE9F7F7 0xE9, 0xF7, 0xF7
blueish color 0xBCF7F3 0xBC, 0xF7, 0xF3
redish color 0xFB8D82 0xFB, 0x8D, 0x82
background 0x0A, 0x11, 0x17
*/
fn void mt_ui_stacks(ma_arena_t *arena, sb8_t *c, sb8_t *h) {
ast_t *table = mtt_parse(arena, __FILE__, S8_CODE(
{ type name skip_box_member }
{ ui_id_t id 1 }
{ ui_lop_t lop 1 }
{ f32 border_thickness 0 }
{ ui_text_align_t text_align 0 }
{ f32 required_width 0 }
{ f32 required_height 0 }
{ v2f32_t padding 0 }
{ v4f32_t background_color 0 }
{ v4f32_t border_color 0 }
{ v4f32_t text_color 0 }
// 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_width 0 x }
{ f32 required_height 0 x }
{ v2f32_t padding 0 x }
{ v4f32_t background_color 0 `v4f32_rgba255(245, 238, 230, 255)` }
{ v4f32_t border_color 0 `v4f32_rgba255(230, 164, 180, 255)` }
{ v4f32_t text_color 0 `v4f32_rgba255(0, 0, 0, 255)` }
{ v4f32_t radio_color 0 `v4f32_rgba255(243, 215, 202, 255)` }
));
///////////////////////////////
@@ -33,11 +48,6 @@ void mt_ui(ma_arena_t *arena) {
mt_ast_append(it, mt_kv(arena, s8_lit("stack"), stack));
}
sb8_t *h = sb8_serial_begin(arena);
sb8_t *c = sb8_serial_begin(arena);
sb8_printf(h, "// automatically generated using: " __FILE__ "\n");
sb8_printf(c, "// automatically generated using: " __FILE__ "\n");
///////////////////////////////
// generate types
@@ -55,7 +65,7 @@ void mt_ui(ma_arena_t *arena) {
// generate field embeds
sb8_stmtf(h, "#define UI_DECL_BOX_MEMBERS \\");
for (ast_t *it = table->first; it; it = it->next) {
if (mtt(it, "skip_box_member")->integer) continue;
if (mtt(it, "skip")->integer) continue;
mt_stmtf(h, it, "@type @name;\\");
}
sb8_printf(h, "\n");
@@ -71,15 +81,46 @@ void mt_ui(ma_arena_t *arena) {
for (ast_t *it = table->first; it; it = it->next) {
mt_sbprintf(c, it, "fn void ui_push_@name(@type v) { @node *n = ma_push_type(tcx.temp, @node); n->value = v; SLLS_PUSH(ui->@stack, n); }\n"
"fn void ui_pop_@name(void) { SLLS_POP(ui->@stack); }\n"
"fn @type ui_top_@name(void) { return ui->@stack->value; }\n"
"#define ui_set_@name(x) defer_block(ui_push_@name(x), ui_pop_@name())\n");
}
///////////////////////////////
// generate init stack functions
sb8_stmtf(c, "fn void ui_assert_stacks_are_null(void) {");
for (ast_t *it = table->first; it; it = it->next) {
mt_stmtf(c, it, "assert(ui->@stack == NULL);");
}
sb8_stmtf(c, "}");
sb8_stmtf(c, "fn void ui_push_init_values(void) {");
for (ast_t *it = table->first; it; it = it->next) {
if (s8_are_equal(mtts(it, "init"), s8_lit("x"))) {
continue;
}
mt_stmtf(c, it, "ui_push_@name(@init);");
}
sb8_stmtf(c, "}");
sb8_stmtf(c, "fn void ui_pop_init_values(void) {");
for (ast_t *it = table->first; it; it = it->next) {
if (s8_are_equal(mtts(it, "init"), s8_lit("x"))) {
continue;
}
mt_stmtf(c, it, "ui_pop_@name();");
}
sb8_stmtf(c, "}");
}
fn void mt_ui(ma_arena_t *arena) {
sb8_t *h = sb8_serial_begin(arena);
sb8_t *c = sb8_serial_begin(arena);
sb8_printf(h, "// automatically generated using: " __FILE__ "\n");
sb8_printf(c, "// automatically generated using: " __FILE__ "\n");
mt_ui_stacks(arena, c, h);
os_write_file(mt_cpath(arena), sb8_serial_end(arena, c));
os_write_file(mt_hpath(arena), sb8_serial_end(arena, h));