using cache in build_file, ui metaprogram and generating stacks
This commit is contained in:
20
build_file.c
20
build_file.c
@@ -11,23 +11,29 @@
|
|||||||
#include "src/meta/cgen.c"
|
#include "src/meta/cgen.c"
|
||||||
|
|
||||||
#include "src/app/app.meta.c"
|
#include "src/app/app.meta.c"
|
||||||
|
#include "src/ui/ui.meta.c"
|
||||||
#include "src/wasm_app/wasm_app.meta.c"
|
#include "src/wasm_app/wasm_app.meta.c"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
SRC_SearchPaths.include_path = (char*[]){OS_GetAbsolutePath(&Perm, s8_lit("../src")).str};
|
||||||
|
SRC_SearchPaths.include_path_count = 1;
|
||||||
cache_init(&Perm, s8_lit("cache_build_file"));
|
cache_init(&Perm, s8_lit("cache_build_file"));
|
||||||
|
ma_arena_t *arena = ma_create(ma_default_reserve_size);
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
ma_arena_t *arena = ma_create(ma_default_reserve_size);
|
b32 generate_math = true;
|
||||||
if (cache_code_modified(s8_lit("../src/core/core_math_gen.py"), s8_null)) {
|
|
||||||
|
if (generate_math && cache_code_modified(s8_lit("../src/core/core_math_gen.py"), s8_null)) {
|
||||||
os_set_working_dir("../src/core");
|
os_set_working_dir("../src/core");
|
||||||
os_systemf("py core_math_gen.py");
|
os_systemf("py core_math_gen.py");
|
||||||
os_set_working_dir("../../build");
|
os_set_working_dir("../../build");
|
||||||
}
|
}
|
||||||
|
mt_ui(arena);
|
||||||
mt_app(arena);
|
mt_app(arena);
|
||||||
mt_wasm_app(arena);
|
mt_wasm_app(arena);
|
||||||
|
|
||||||
b32 run_server = false;
|
b32 run_server = false;
|
||||||
b32 core_test_target = false;
|
b32 core_test_target = true;
|
||||||
b32 win32_target = true;
|
b32 win32_target = true;
|
||||||
b32 wasm_target = false;
|
b32 wasm_target = false;
|
||||||
|
|
||||||
@@ -35,7 +41,7 @@ int main(int argc, char **argv) {
|
|||||||
os_systemf("start /D ..\\package ..\\package\\run_server.bat");
|
os_systemf("start /D ..\\package ..\\package\\run_server.bat");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (win32_target) {
|
if (win32_target && cache_code_modified(s8_lit("../src/wasm_app/main.c"), s8_lit("app_win32.exe"))) {
|
||||||
os_delete_file(s8_lit("app_win32.pdb"));
|
os_delete_file(s8_lit("app_win32.pdb"));
|
||||||
ok = os_systemf(
|
ok = os_systemf(
|
||||||
"cl ../src/wasm_app/main.c -Fe:app_win32.exe -Fd:app_win32.pdb"
|
"cl ../src/wasm_app/main.c -Fe:app_win32.exe -Fd:app_win32.pdb"
|
||||||
@@ -47,7 +53,7 @@ int main(int argc, char **argv) {
|
|||||||
if (ok != 0) return ok;
|
if (ok != 0) return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core_test_target) {
|
if (core_test_target && cache_code_modified(s8_lit("../src/core/core_test_entry.c"), s8_lit("core_test.exe"))) {
|
||||||
os_delete_file(s8_lit("core_test.pdb"));
|
os_delete_file(s8_lit("core_test.pdb"));
|
||||||
ok = os_systemf(
|
ok = os_systemf(
|
||||||
"cl ../src/core/core_test_entry.c -Fe:core_test.exe -Fd:core_test.pdb"
|
"cl ../src/core/core_test_entry.c -Fe:core_test.exe -Fd:core_test.pdb"
|
||||||
@@ -59,11 +65,11 @@ int main(int argc, char **argv) {
|
|||||||
if (ok != 0) return ok;
|
if (ok != 0) return ok;
|
||||||
|
|
||||||
ok = os_systemf("core_test.exe");
|
ok = os_systemf("core_test.exe");
|
||||||
return ok;
|
if (ok != 0) return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (wasm_target) {
|
if (wasm_target && cache_code_modified(s8_lit("../src/wasm_app/main.c"), s8_lit("main.wasm"))) {
|
||||||
os_copy("../src/app/app_wasm.html", "../package/index.html", os_copy_overwrite);
|
os_copy("../src/app/app_wasm.html", "../package/index.html", os_copy_overwrite);
|
||||||
ok = os_systemf(
|
ok = os_systemf(
|
||||||
"clang.exe ../src/wasm_app/main.c -o main.wasm"
|
"clang.exe ../src/wasm_app/main.c -o main.wasm"
|
||||||
|
|||||||
@@ -199,6 +199,6 @@ void mt_app(ma_arena_t *arena) {
|
|||||||
sb8_serial_ast_to_type_info(c, decls);
|
sb8_serial_ast_to_type_info(c, decls);
|
||||||
}
|
}
|
||||||
|
|
||||||
os_write_file(cg_cpath(arena), sb8_merge(arena, c));
|
os_write_file(cg_cpath(arena), sb8_serial_end(arena, c));
|
||||||
os_write_file(cg_hpath(arena), sb8_merge(arena, h));
|
os_write_file(cg_hpath(arena), sb8_serial_end(arena, h));
|
||||||
}
|
}
|
||||||
@@ -170,6 +170,7 @@ typedef double f64;
|
|||||||
#define SLLS_PUSH(stack_base, new_stack_base) \
|
#define SLLS_PUSH(stack_base, new_stack_base) \
|
||||||
SLLS_PUSH_EX(stack_base, new_stack_base, next)
|
SLLS_PUSH_EX(stack_base, new_stack_base, next)
|
||||||
|
|
||||||
|
#define SLLS_POP(stack_base) ((stack_base) = (stack_base)->next)
|
||||||
#define SLLS_POP_AND_STORE(stack_base, out_node) \
|
#define SLLS_POP_AND_STORE(stack_base, out_node) \
|
||||||
do { \
|
do { \
|
||||||
if (stack_base) { \
|
if (stack_base) { \
|
||||||
|
|||||||
@@ -359,6 +359,7 @@ r2f32_t r2f32_get_bottom(const r2f32_t *r, f32 value) { /* Y is down */
|
|||||||
}
|
}
|
||||||
|
|
||||||
r2f32_t r2f32_shrink(r2f32_t rect, v2f32_t value) { return (r2f32_t){ v2f32_add(rect.min, value), v2f32_sub(rect.max, value) }; }
|
r2f32_t r2f32_shrink(r2f32_t rect, v2f32_t value) { return (r2f32_t){ v2f32_add(rect.min, value), v2f32_sub(rect.max, value) }; }
|
||||||
|
r2f32_t r2f32_shrinks(r2f32_t rect, f32 value) { return (r2f32_t){ v2f32_adds(rect.min, value), v2f32_subs(rect.max, value) }; }
|
||||||
v2f32_t r2f32_get_size(r2f32_t r) { return (v2f32_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
v2f32_t r2f32_get_size(r2f32_t r) { return (v2f32_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
||||||
v2f32_t r2f32_get_mid(r2f32_t r) { return v2f32_add(r.min, v2f32_divs(r2f32_get_size(r), 2)); }
|
v2f32_t r2f32_get_mid(r2f32_t r) { return v2f32_add(r.min, v2f32_divs(r2f32_get_size(r), 2)); }
|
||||||
b32 r2f32_contains(r2f32_t rec, v2f32_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
b32 r2f32_contains(r2f32_t rec, v2f32_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
||||||
@@ -469,6 +470,7 @@ r2f64_t r2f64_get_bottom(const r2f64_t *r, f64 value) { /* Y is down */
|
|||||||
}
|
}
|
||||||
|
|
||||||
r2f64_t r2f64_shrink(r2f64_t rect, v2f64_t value) { return (r2f64_t){ v2f64_add(rect.min, value), v2f64_sub(rect.max, value) }; }
|
r2f64_t r2f64_shrink(r2f64_t rect, v2f64_t value) { return (r2f64_t){ v2f64_add(rect.min, value), v2f64_sub(rect.max, value) }; }
|
||||||
|
r2f64_t r2f64_shrinks(r2f64_t rect, f64 value) { return (r2f64_t){ v2f64_adds(rect.min, value), v2f64_subs(rect.max, value) }; }
|
||||||
v2f64_t r2f64_get_size(r2f64_t r) { return (v2f64_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
v2f64_t r2f64_get_size(r2f64_t r) { return (v2f64_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
||||||
v2f64_t r2f64_get_mid(r2f64_t r) { return v2f64_add(r.min, v2f64_divs(r2f64_get_size(r), 2)); }
|
v2f64_t r2f64_get_mid(r2f64_t r) { return v2f64_add(r.min, v2f64_divs(r2f64_get_size(r), 2)); }
|
||||||
b32 r2f64_contains(r2f64_t rec, v2f64_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
b32 r2f64_contains(r2f64_t rec, v2f64_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
||||||
@@ -579,6 +581,7 @@ r2i32_t r2i32_get_bottom(const r2i32_t *r, i32 value) { /* Y is down */
|
|||||||
}
|
}
|
||||||
|
|
||||||
r2i32_t r2i32_shrink(r2i32_t rect, v2i32_t value) { return (r2i32_t){ v2i32_add(rect.min, value), v2i32_sub(rect.max, value) }; }
|
r2i32_t r2i32_shrink(r2i32_t rect, v2i32_t value) { return (r2i32_t){ v2i32_add(rect.min, value), v2i32_sub(rect.max, value) }; }
|
||||||
|
r2i32_t r2i32_shrinks(r2i32_t rect, i32 value) { return (r2i32_t){ v2i32_adds(rect.min, value), v2i32_subs(rect.max, value) }; }
|
||||||
v2i32_t r2i32_get_size(r2i32_t r) { return (v2i32_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
v2i32_t r2i32_get_size(r2i32_t r) { return (v2i32_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
||||||
v2i32_t r2i32_get_mid(r2i32_t r) { return v2i32_add(r.min, v2i32_divs(r2i32_get_size(r), 2)); }
|
v2i32_t r2i32_get_mid(r2i32_t r) { return v2i32_add(r.min, v2i32_divs(r2i32_get_size(r), 2)); }
|
||||||
b32 r2i32_contains(r2i32_t rec, v2i32_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
b32 r2i32_contains(r2i32_t rec, v2i32_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
||||||
@@ -689,6 +692,7 @@ r2i64_t r2i64_get_bottom(const r2i64_t *r, i64 value) { /* Y is down */
|
|||||||
}
|
}
|
||||||
|
|
||||||
r2i64_t r2i64_shrink(r2i64_t rect, v2i64_t value) { return (r2i64_t){ v2i64_add(rect.min, value), v2i64_sub(rect.max, value) }; }
|
r2i64_t r2i64_shrink(r2i64_t rect, v2i64_t value) { return (r2i64_t){ v2i64_add(rect.min, value), v2i64_sub(rect.max, value) }; }
|
||||||
|
r2i64_t r2i64_shrinks(r2i64_t rect, i64 value) { return (r2i64_t){ v2i64_adds(rect.min, value), v2i64_subs(rect.max, value) }; }
|
||||||
v2i64_t r2i64_get_size(r2i64_t r) { return (v2i64_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
v2i64_t r2i64_get_size(r2i64_t r) { return (v2i64_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
||||||
v2i64_t r2i64_get_mid(r2i64_t r) { return v2i64_add(r.min, v2i64_divs(r2i64_get_size(r), 2)); }
|
v2i64_t r2i64_get_mid(r2i64_t r) { return v2i64_add(r.min, v2i64_divs(r2i64_get_size(r), 2)); }
|
||||||
b32 r2i64_contains(r2i64_t rec, v2i64_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
b32 r2i64_contains(r2i64_t rec, v2i64_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
||||||
@@ -755,3 +759,19 @@ v3i32_t v3i64_to_v3i32(v3i64_t v) { return (v3i32_t){ (i32)v.x, (i32)v.y, (i32)v
|
|||||||
v4i32_t v4i64_to_v4i32(v4i64_t v) { return (v4i32_t){ (i32)v.x, (i32)v.y, (i32)v.z, (i32)v.w }; }
|
v4i32_t v4i64_to_v4i32(v4i64_t v) { return (v4i32_t){ (i32)v.x, (i32)v.y, (i32)v.z, (i32)v.w }; }
|
||||||
r2i32_t r2i64_to_r2i32(r2i64_t v) { return (r2i32_t){ (i32)v.x0, (i32)v.y0, (i32)v.x1, (i32)v.y1 }; }
|
r2i32_t r2i64_to_r2i32(r2i64_t v) { return (r2i32_t){ (i32)v.x0, (i32)v.y0, (i32)v.x1, (i32)v.y1 }; }
|
||||||
r3i32_t r3i64_to_r3i32(r3i64_t v) { return (r3i32_t){ (i32)v.x0, (i32)v.y0, (i32)v.z0, (i32)v.x1, (i32)v.y1, (i32)v.z1 }; }
|
r3i32_t r3i64_to_r3i32(r3i64_t v) { return (r3i32_t){ (i32)v.x0, (i32)v.y0, (i32)v.z0, (i32)v.x1, (i32)v.y1, (i32)v.z1 }; }
|
||||||
|
r2f32_t r2f32_add_v2f32(r2f32_t a, v2f32_t b) { return (r2f32_t){ v2f32_add(a.min, b), v2f32_add(a.max, b) }; }
|
||||||
|
r2f32_t r2f32_sub_v2f32(r2f32_t a, v2f32_t b) { return (r2f32_t){ v2f32_sub(a.min, b), v2f32_sub(a.max, b) }; }
|
||||||
|
r2f32_t r2f32_mul_v2f32(r2f32_t a, v2f32_t b) { return (r2f32_t){ v2f32_mul(a.min, b), v2f32_mul(a.max, b) }; }
|
||||||
|
r2f32_t r2f32_div_v2f32(r2f32_t a, v2f32_t b) { return (r2f32_t){ v2f32_div(a.min, b), v2f32_div(a.max, b) }; }
|
||||||
|
r2f64_t r2f64_add_v2f64(r2f64_t a, v2f64_t b) { return (r2f64_t){ v2f64_add(a.min, b), v2f64_add(a.max, b) }; }
|
||||||
|
r2f64_t r2f64_sub_v2f64(r2f64_t a, v2f64_t b) { return (r2f64_t){ v2f64_sub(a.min, b), v2f64_sub(a.max, b) }; }
|
||||||
|
r2f64_t r2f64_mul_v2f64(r2f64_t a, v2f64_t b) { return (r2f64_t){ v2f64_mul(a.min, b), v2f64_mul(a.max, b) }; }
|
||||||
|
r2f64_t r2f64_div_v2f64(r2f64_t a, v2f64_t b) { return (r2f64_t){ v2f64_div(a.min, b), v2f64_div(a.max, b) }; }
|
||||||
|
r2i32_t r2i32_add_v2i32(r2i32_t a, v2i32_t b) { return (r2i32_t){ v2i32_add(a.min, b), v2i32_add(a.max, b) }; }
|
||||||
|
r2i32_t r2i32_sub_v2i32(r2i32_t a, v2i32_t b) { return (r2i32_t){ v2i32_sub(a.min, b), v2i32_sub(a.max, b) }; }
|
||||||
|
r2i32_t r2i32_mul_v2i32(r2i32_t a, v2i32_t b) { return (r2i32_t){ v2i32_mul(a.min, b), v2i32_mul(a.max, b) }; }
|
||||||
|
r2i32_t r2i32_div_v2i32(r2i32_t a, v2i32_t b) { return (r2i32_t){ v2i32_div(a.min, b), v2i32_div(a.max, b) }; }
|
||||||
|
r2i64_t r2i64_add_v2i64(r2i64_t a, v2i64_t b) { return (r2i64_t){ v2i64_add(a.min, b), v2i64_add(a.max, b) }; }
|
||||||
|
r2i64_t r2i64_sub_v2i64(r2i64_t a, v2i64_t b) { return (r2i64_t){ v2i64_sub(a.min, b), v2i64_sub(a.max, b) }; }
|
||||||
|
r2i64_t r2i64_mul_v2i64(r2i64_t a, v2i64_t b) { return (r2i64_t){ v2i64_mul(a.min, b), v2i64_mul(a.max, b) }; }
|
||||||
|
r2i64_t r2i64_div_v2i64(r2i64_t a, v2i64_t b) { return (r2i64_t){ v2i64_div(a.min, b), v2i64_div(a.max, b) }; }
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ r2f64_t r2f64_get_bottom(const r2f64_t *r, f64 value) { /* Y is down */
|
|||||||
}
|
}
|
||||||
|
|
||||||
r2f64_t r2f64_shrink(r2f64_t rect, v2f64_t value) { return (r2f64_t){ v2f64_add(rect.min, value), v2f64_sub(rect.max, value) }; }
|
r2f64_t r2f64_shrink(r2f64_t rect, v2f64_t value) { return (r2f64_t){ v2f64_add(rect.min, value), v2f64_sub(rect.max, value) }; }
|
||||||
|
r2f64_t r2f64_shrinks(r2f64_t rect, f64 value) { return (r2f64_t){ v2f64_adds(rect.min, value), v2f64_subs(rect.max, value) }; }
|
||||||
v2f64_t r2f64_get_size(r2f64_t r) { return (v2f64_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
v2f64_t r2f64_get_size(r2f64_t r) { return (v2f64_t){r.max.x - r.min.x, r.max.y - r.min.y}; }
|
||||||
v2f64_t r2f64_get_mid(r2f64_t r) { return v2f64_add(r.min, v2f64_divs(r2f64_get_size(r), 2)); }
|
v2f64_t r2f64_get_mid(r2f64_t r) { return v2f64_add(r.min, v2f64_divs(r2f64_get_size(r), 2)); }
|
||||||
b32 r2f64_contains(r2f64_t rec, v2f64_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
b32 r2f64_contains(r2f64_t rec, v2f64_t point) { return (point.x >= rec.min.x) && (point.x < rec.max.x) && (point.y >= rec.min.y) && (point.y < rec.max.y); }
|
||||||
@@ -335,3 +336,16 @@ for at in basic_types:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
print(f"{btype}_t {atype}_to_{btype}({atype}_t v) {{ return ({btype}_t){{ {cast_members(members, bt)} }}; }}")
|
print(f"{btype}_t {atype}_to_{btype}({atype}_t v) {{ return ({btype}_t){{ {cast_members(members, bt)} }}; }}")
|
||||||
|
|
||||||
|
|
||||||
|
#######
|
||||||
|
# generate r2f64_sub_v2f64 for +-*/ and types
|
||||||
|
for bt in basic_types:
|
||||||
|
for sym in symbols:
|
||||||
|
word_op = sym[1]
|
||||||
|
s = """
|
||||||
|
r2f64_t r2f64_sub_v2f64(r2f64_t a, v2f64_t b) { return (r2f64_t){ v2f64_sub(a.min, b), v2f64_sub(a.max, b) }; }
|
||||||
|
""".strip()
|
||||||
|
s = s.replace("f64", bt)
|
||||||
|
s = s.replace("sub", word_op)
|
||||||
|
print(s)
|
||||||
@@ -5031,6 +5031,8 @@ SRC_CacheEntry *cache_hash_file(S8_String file, char *parent_file) {
|
|||||||
if (token.is_system_include) continue;
|
if (token.is_system_include) continue;
|
||||||
|
|
||||||
S8_String file_it = S8_MakeFromChar(token.string_literal);
|
S8_String file_it = S8_MakeFromChar(token.string_literal);
|
||||||
|
if (s8_are_equal(file_it, file)) continue; // prevent recursing, file includes itself (stb_truetype)
|
||||||
|
|
||||||
SRC_CacheEntry *cache = cache_hash_file(file_it, resolved_file);
|
SRC_CacheEntry *cache = cache_hash_file(file_it, resolved_file);
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
// error was reported already IO_Printf("Missing cache for: %.*s\n", S8_Expand(file_it));
|
// error was reported already IO_Printf("Missing cache for: %.*s\n", S8_Expand(file_it));
|
||||||
|
|||||||
@@ -147,11 +147,11 @@ fn void rn_draw_rect(r2f32_t rect, v4f32_t color) {
|
|||||||
rn_push_quad(rect, rn_state.main_font->white_texture_bounding_box, color);
|
rn_push_quad(rect, rn_state.main_font->white_texture_bounding_box, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void rn_draw_rect_border(r2f32_t rect, v4f32_t color) {
|
fn void rn_draw_rect_border(r2f32_t rect, v4f32_t color, f32 border_thickness) {
|
||||||
r2f32_t left = r2f32_cut_left(&rect, 1);
|
r2f32_t left = r2f32_cut_left(&rect, border_thickness);
|
||||||
r2f32_t right = r2f32_cut_right(&rect, 1);
|
r2f32_t right = r2f32_cut_right(&rect, border_thickness);
|
||||||
r2f32_t top = r2f32_cut_top(&rect, 1);
|
r2f32_t top = r2f32_cut_top(&rect, border_thickness);
|
||||||
r2f32_t bottom = r2f32_cut_bottom(&rect, 1);
|
r2f32_t bottom = r2f32_cut_bottom(&rect, border_thickness);
|
||||||
rn_push_quad(left, rn_state.main_font->white_texture_bounding_box, color);
|
rn_push_quad(left, rn_state.main_font->white_texture_bounding_box, color);
|
||||||
rn_push_quad(right, rn_state.main_font->white_texture_bounding_box, color);
|
rn_push_quad(right, rn_state.main_font->white_texture_bounding_box, color);
|
||||||
rn_push_quad(top, rn_state.main_font->white_texture_bounding_box, color);
|
rn_push_quad(top, rn_state.main_font->white_texture_bounding_box, color);
|
||||||
|
|||||||
168
src/ui/ui.c
168
src/ui/ui.c
@@ -41,8 +41,8 @@ fn ui_id_t ui_id_from_code_loc(ui_code_loc_t loc) {
|
|||||||
|
|
||||||
fn u64 ui_hash_from_stack(void) {
|
fn u64 ui_hash_from_stack(void) {
|
||||||
u64 result = 34294923;
|
u64 result = 34294923;
|
||||||
for (i32 i = 0; i < ui->id_stack.len; i += 1) {
|
for (ui_id_node_t *it = ui->id_stack; it; it = it->next) {
|
||||||
result = hash_mix(result, ui->id_stack.data[i].value);
|
result = hash_mix(result, it->value.value);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -60,11 +60,10 @@ fn ui_id_t ui_idf(char *str, ...) {
|
|||||||
return ui_id(string);
|
return ui_id(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void ui_push_id(ui_id_t id) { STACK_PUSH(ui->id_stack, id); }
|
|
||||||
fn void ui_pop_id(void) { STACK_POP(ui->id_stack); }
|
|
||||||
fn void ui_push_id_string(s8_t string) { ui_push_id(ui_id(string)); }
|
fn void ui_push_id_string(s8_t string) { ui_push_id(ui_id(string)); }
|
||||||
fn void ui_push_top(ui_box_t *new_top) { assert(new_top->parent == ui->top); ui->top = new_top; ui_push_id(new_top->id); }
|
fn void ui_push_top(ui_box_t *new_top) { assert(new_top->parent == ui->top); ui->top = new_top; ui_push_id(new_top->id); }
|
||||||
fn void ui_pop_top(void) { ui->top = ui->top->parent; ui_pop_id(); }
|
fn void ui_pop_top(void) { ui->top = ui->top->parent; ui_pop_id(); }
|
||||||
|
#define ui_set_top(x) defer_block(ui_push_top(x), ui_pop_top())
|
||||||
|
|
||||||
fn ui_box_t *ui_alloc_box(void) {
|
fn ui_box_t *ui_alloc_box(void) {
|
||||||
ui_box_t *box = NULL;
|
ui_box_t *box = NULL;
|
||||||
@@ -93,18 +92,23 @@ fn void ui_push_box(ui_box_t *parent, ui_box_t *box) {
|
|||||||
parent->node_count += 1;
|
parent->node_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn r2f32_t ui_next_rect(ui_op_t op, r2f32_t *rect, v2f32_t required_size) {
|
fn r2f32_t ui_next_rect(ui_lop_t op, r2f32_t *rect, v2f32_t required_size) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case ui_op_cut_top: return r2f32_cut_top_no_squash(rect, required_size.y); break;
|
case ui_lop_cut_top: return r2f32_cut_top_no_squash(rect, required_size.y); break;
|
||||||
case ui_op_cut_bottom: return r2f32_cut_bottom_no_squash(rect, required_size.y); break;
|
case ui_lop_cut_bottom: return r2f32_cut_bottom_no_squash(rect, required_size.y); break;
|
||||||
case ui_op_cut_left: return r2f32_cut_left_no_squash(rect, required_size.x); break;
|
case ui_lop_cut_left: return r2f32_cut_left_no_squash(rect, required_size.x); break;
|
||||||
case ui_op_cut_right: return r2f32_cut_right_no_squash(rect, required_size.x); break;
|
case ui_lop_cut_right: return r2f32_cut_right_no_squash(rect, required_size.x); break;
|
||||||
case ui_op_idle: break;
|
case ui_lop_idle: break;
|
||||||
default_is_invalid;
|
default_is_invalid;
|
||||||
}
|
}
|
||||||
return (r2f32_t){0};
|
return (r2f32_t){0};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn void ui_offset_box(ui_box_t *box, v2f32_t offset) {
|
||||||
|
box->full_rect = r2f32_sub_v2f32(box->full_rect, offset);
|
||||||
|
box->rect = r2f32_sub_v2f32(box->rect, offset);
|
||||||
|
}
|
||||||
|
|
||||||
fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flags_t flags, ui_id_t id) {
|
fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flags_t flags, ui_id_t id) {
|
||||||
ui_box_t *box = ui_find_box(id);
|
ui_box_t *box = ui_find_box(id);
|
||||||
if (box) {
|
if (box) {
|
||||||
@@ -121,7 +125,8 @@ fn ui_box_t *ui_build_box_from_id(ui_code_loc_t loc, ui_box_flags_t flags, ui_id
|
|||||||
box->last_touched_event_id = ui->event->id;
|
box->last_touched_event_id = ui->event->id;
|
||||||
box->id = id;
|
box->id = id;
|
||||||
box->flags = flags;
|
box->flags = flags;
|
||||||
box->text_align = ui->pref_text_align;
|
box->text_align = ui->text_align_stack->value;
|
||||||
|
box->border_thickness = ui->border_thickness_stack->value;
|
||||||
ui_push_box(ui->top, box);
|
ui_push_box(ui->top, box);
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
@@ -131,19 +136,30 @@ fn ui_box_t *ui_build_box_from_string(ui_code_loc_t loc, ui_box_flags_t flags, s
|
|||||||
ui_box_t *box = ui_build_box_from_id(loc, flags, id);
|
ui_box_t *box = ui_build_box_from_id(loc, flags, id);
|
||||||
box->string = ui_get_display_string(string);
|
box->string = ui_get_display_string(string);
|
||||||
v2f32_t string_size = rn_measure_string(rn_state.main_font, box->string);
|
v2f32_t string_size = rn_measure_string(rn_state.main_font, box->string);
|
||||||
string_size.x += ui_em(1);
|
if (ui->required_width_stack) string_size.x = ui->required_width_stack->value;
|
||||||
r2f32_t rect = ui_next_rect(ui->top->op, &ui->top->rect, string_size);
|
if (ui->required_height_stack) string_size.y = ui->required_height_stack->value;
|
||||||
|
if (ui->padding_stack) string_size = v2f32_add(string_size, ui->padding_stack->value);
|
||||||
|
r2f32_t rect = ui_next_rect(ui->lop_stack->value, &ui->top->rect, string_size);
|
||||||
ui_set_rect(box, rect);
|
ui_set_rect(box, rect);
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ui_boxf(flags, ...) ui__boxf(UILOC, flags, __VA_ARGS__)
|
#define ui_boxf(...) ui__boxf(UILOC, __VA_ARGS__)
|
||||||
fn ui_box_t *ui__boxf(ui_code_loc_t loc, ui_box_flags_t flags, char *str, ...) {
|
fn ui_box_t *ui__boxf(ui_code_loc_t loc, ui_box_flags_t flags, char *str, ...) {
|
||||||
S8_FMT(tcx.temp, str, string);
|
S8_FMT(tcx.temp, str, string);
|
||||||
ui_box_t *box = ui_build_box_from_string(loc, flags, string);
|
ui_box_t *box = ui_build_box_from_string(loc, flags, string);
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ui_box0(...) ui_build_box_from_id(UILOC, __VA_ARGS__, ui_null_id)
|
||||||
|
#define ui_box0f(...) ui__box0f(UILOC, __VA_ARGS__)
|
||||||
|
fn ui_box_t *ui__box0f(ui_code_loc_t loc, ui_box_flags_t flags, char *str, ...) {
|
||||||
|
S8_FMT(tcx.temp, str, string);
|
||||||
|
ui_box_t *box = ui_build_box_from_id(loc, flags, ui_null_id);
|
||||||
|
box->string = string;
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
|
||||||
fn ui_signal_t ui_signal_from_box(ui_box_t *box) {
|
fn ui_signal_t ui_signal_from_box(ui_box_t *box) {
|
||||||
ui_signal_t result = {box};
|
ui_signal_t result = {box};
|
||||||
app_event_t *ev = ui->event;
|
app_event_t *ev = ui->event;
|
||||||
@@ -181,6 +197,14 @@ fn ui_signal_t ui__button(ui_code_loc_t loc, char *str, ...) {
|
|||||||
return signal;
|
return signal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ui_label_button(...) ui__label_button(UILOC, __VA_ARGS__)
|
||||||
|
fn ui_signal_t ui__label_button(ui_code_loc_t loc, char *str, ...) {
|
||||||
|
S8_FMT(tcx.temp, str, string);
|
||||||
|
ui_box_t *box = ui_build_box_from_string(loc, (ui_box_flags_t){ .draw_text = true }, string);
|
||||||
|
ui_signal_t signal = ui_signal_from_box(box);
|
||||||
|
return signal;
|
||||||
|
}
|
||||||
|
|
||||||
#define ui_label(...) ui__label(UILOC, __VA_ARGS__)
|
#define ui_label(...) ui__label(UILOC, __VA_ARGS__)
|
||||||
fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) {
|
fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) {
|
||||||
S8_FMT(tcx.temp, str, string);
|
S8_FMT(tcx.temp, str, string);
|
||||||
@@ -188,6 +212,7 @@ fn ui_box_t *ui__label(ui_code_loc_t loc, char *str, ...) {
|
|||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ui_expander(...) defer_if (ui_begin_expander(__VA_ARGS__).clicked, ui_end_expander())
|
||||||
#define ui_begin_expander(...) ui__begin_expander(UILOC, __VA_ARGS__)
|
#define ui_begin_expander(...) ui__begin_expander(UILOC, __VA_ARGS__)
|
||||||
fn ui_signal_t ui__begin_expander(ui_code_loc_t loc, char *str, ...) {
|
fn ui_signal_t ui__begin_expander(ui_code_loc_t loc, char *str, ...) {
|
||||||
S8_FMT(tcx.temp, str, string);
|
S8_FMT(tcx.temp, str, string);
|
||||||
@@ -222,15 +247,26 @@ fn void ui_begin_build(ui_code_loc_t loc, app_event_t *ev, r2f32_t window_rect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui_push_lop(ui_lop_cut_top);
|
||||||
|
ui_push_id(ui_idf("root"));
|
||||||
|
ui_push_border_thickness(1.0f);
|
||||||
|
ui_push_text_align(ui_text_align_left);
|
||||||
|
|
||||||
zero_struct(&ui->root);
|
zero_struct(&ui->root);
|
||||||
ui->root.full_rect = ui->root.rect = window_rect;
|
ui->root.full_rect = ui->root.rect = window_rect;
|
||||||
ui->top = &ui->root;
|
ui->top = &ui->root;
|
||||||
ui->root.loc = loc;
|
ui->root.loc = loc;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void ui_end_build(void) {
|
fn void ui_end_build(void) {
|
||||||
assert(ui->top == &ui->root);
|
assert(ui->top == &ui->root);
|
||||||
|
|
||||||
|
SLLS_POP(ui->id_stack);
|
||||||
|
SLLS_POP(ui->border_thickness_stack);
|
||||||
|
SLLS_POP(ui->text_align_stack);
|
||||||
|
|
||||||
for (ui_box_t *box = ui->hash_first, *next = NULL; box; box = next) {
|
for (ui_box_t *box = ui->hash_first, *next = NULL; box; box = next) {
|
||||||
next = box->hash_next;
|
next = box->hash_next;
|
||||||
b32 touched_box_during_update = ui->event->id <= box->last_touched_event_id;
|
b32 touched_box_during_update = ui->event->id <= box->last_touched_event_id;
|
||||||
@@ -266,7 +302,7 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
|
|||||||
rn_draw_rect(rect, rect_color);
|
rn_draw_rect(rect, rect_color);
|
||||||
}
|
}
|
||||||
if (box->flags.draw_border) {
|
if (box->flags.draw_border) {
|
||||||
rn_draw_rect_border(rect, accent2_color_global);
|
rn_draw_rect_border(rect, accent2_color_global, box->border_thickness);
|
||||||
}
|
}
|
||||||
if (box->flags.draw_text) {
|
if (box->flags.draw_text) {
|
||||||
v2f32_t string_size = rn_measure_string(rn_state.main_font, box->string);
|
v2f32_t string_size = rn_measure_string(rn_state.main_font, box->string);
|
||||||
@@ -295,15 +331,22 @@ fn void ui__draw_box(app_frame_t *frame, ui_box_t *box) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void ui_draw(app_frame_t *frame) {
|
fn void ui_draw(void) {
|
||||||
ui->clip_rect = window_rect_from_frame(frame);
|
ui->clip_rect = window_rect_from_frame(ui->frame);
|
||||||
rn_set_clip(ui->clip_rect);
|
rn_set_clip(ui->clip_rect);
|
||||||
ui__draw_box(frame, &ui->root);
|
ui__draw_box(ui->frame, &ui->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void ui_demo_init(ma_arena_t *arena) {
|
fn void ui_begin_frame(app_frame_t *frame) {
|
||||||
ui = ma_push_type(arena, ui_t);
|
ui->frame = frame;
|
||||||
ui->box_arena = ma_push_arena(arena, mib(1));
|
}
|
||||||
|
|
||||||
|
fn void ui_end_frame(void) {
|
||||||
|
for (app_event_t *ev = ui->frame->first_event; ev; ev = ev->next) {
|
||||||
|
if (ev_left_up(ev)) {
|
||||||
|
ui->active = ui_null_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
||||||
@@ -312,7 +355,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
switch(type->kind) {
|
switch(type->kind) {
|
||||||
case type_kind_i8: {
|
case type_kind_i8: {
|
||||||
i8 *n = (i8 *)p;
|
i8 *n = (i8 *)p;
|
||||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (i8)delta;
|
n[0] += (i8)delta;
|
||||||
}
|
}
|
||||||
@@ -320,7 +363,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_i16: {
|
case type_kind_i16: {
|
||||||
i16 *n = (i16 *)p;
|
i16 *n = (i16 *)p;
|
||||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (i16)delta;
|
n[0] += (i16)delta;
|
||||||
}
|
}
|
||||||
@@ -328,7 +371,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_i32: {
|
case type_kind_i32: {
|
||||||
i32 *n = (i32 *)p;
|
i32 *n = (i32 *)p;
|
||||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (i32)delta;
|
n[0] += (i32)delta;
|
||||||
}
|
}
|
||||||
@@ -336,7 +379,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_i64: {
|
case type_kind_i64: {
|
||||||
i64 *n = (i64 *)p;
|
i64 *n = (i64 *)p;
|
||||||
if (ui_button("%S: %lld##slider%S", name, (long long)*n, name).dragging) {
|
if (ui_label_button("%S: %lld##slider%S", name, (long long)*n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (i64)delta;
|
n[0] += (i64)delta;
|
||||||
}
|
}
|
||||||
@@ -344,7 +387,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_u8: {
|
case type_kind_u8: {
|
||||||
u8 *n = (u8 *)p;
|
u8 *n = (u8 *)p;
|
||||||
if (ui_button("%S: %u##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (u8)delta;
|
n[0] += (u8)delta;
|
||||||
}
|
}
|
||||||
@@ -352,7 +395,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_u16: {
|
case type_kind_u16: {
|
||||||
u16 *n = (u16 *)p;
|
u16 *n = (u16 *)p;
|
||||||
if (ui_button("%S: %u##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (u16)delta;
|
n[0] += (u16)delta;
|
||||||
}
|
}
|
||||||
@@ -360,7 +403,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_u32: {
|
case type_kind_u32: {
|
||||||
u32 *n = (u32 *)p;
|
u32 *n = (u32 *)p;
|
||||||
if (ui_button("%S: %u##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %u##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (u32)delta;
|
n[0] += (u32)delta;
|
||||||
}
|
}
|
||||||
@@ -368,7 +411,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_u64: {
|
case type_kind_u64: {
|
||||||
u64 *n = (u64 *)p;
|
u64 *n = (u64 *)p;
|
||||||
if (ui_button("%S: %llu##slider%S", name, (unsigned long long)*n, name).dragging) {
|
if (ui_label_button("%S: %llu##slider%S", name, (unsigned long long)*n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (u64)delta;
|
n[0] += (u64)delta;
|
||||||
}
|
}
|
||||||
@@ -376,35 +419,35 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_b8: {
|
case type_kind_b8: {
|
||||||
b8 *n = (b8 *)p;
|
b8 *n = (b8 *)p;
|
||||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||||
*n = !*n;
|
*n = !*n;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} break;
|
} break;
|
||||||
case type_kind_b16: {
|
case type_kind_b16: {
|
||||||
b16 *n = (b16 *)p;
|
b16 *n = (b16 *)p;
|
||||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||||
*n = !*n;
|
*n = !*n;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} break;
|
} break;
|
||||||
case type_kind_b32: {
|
case type_kind_b32: {
|
||||||
b32 *n = (b32 *)p;
|
b32 *n = (b32 *)p;
|
||||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||||
*n = !*n;
|
*n = !*n;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} break;
|
} break;
|
||||||
case type_kind_b64: {
|
case type_kind_b64: {
|
||||||
b64 *n = (b64 *)p;
|
b64 *n = (b64 *)p;
|
||||||
if (ui_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
if (ui_label_button("%S: %s", name, *n ? "true" : "false").clicked) {
|
||||||
*n = !*n;
|
*n = !*n;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} break;
|
} break;
|
||||||
case type_kind_f32: {
|
case type_kind_f32: {
|
||||||
f32 *n = (f32 *)p;
|
f32 *n = (f32 *)p;
|
||||||
if (ui_button("%S: %f##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %f##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += delta;
|
n[0] += delta;
|
||||||
}
|
}
|
||||||
@@ -412,7 +455,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_f64: {
|
case type_kind_f64: {
|
||||||
f64 *n = (f64 *)p;
|
f64 *n = (f64 *)p;
|
||||||
if (ui_button("%S: %f##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %f##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += delta;
|
n[0] += delta;
|
||||||
}
|
}
|
||||||
@@ -420,7 +463,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_isize: {
|
case type_kind_isize: {
|
||||||
isize *n = (isize *)p;
|
isize *n = (isize *)p;
|
||||||
if (ui_button("%S: %lld##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %lld##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (isize)delta;
|
n[0] += (isize)delta;
|
||||||
}
|
}
|
||||||
@@ -428,7 +471,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_usize: {
|
case type_kind_usize: {
|
||||||
usize *n = (usize *)p;
|
usize *n = (usize *)p;
|
||||||
if (ui_button("%S: %llu##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %llu##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (usize)delta;
|
n[0] += (usize)delta;
|
||||||
}
|
}
|
||||||
@@ -436,7 +479,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_int: {
|
case type_kind_int: {
|
||||||
int *n = (int *)p;
|
int *n = (int *)p;
|
||||||
if (ui_button("%S: %d##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %d##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (int)delta;
|
n[0] += (int)delta;
|
||||||
}
|
}
|
||||||
@@ -444,7 +487,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
} break;
|
} break;
|
||||||
case type_kind_char: {
|
case type_kind_char: {
|
||||||
char *n = (char *)p;
|
char *n = (char *)p;
|
||||||
if (ui_button("%S: %c##slider%S", name, *n, name).dragging) {
|
if (ui_label_button("%S: %c##slider%S", name, *n, name).dragging) {
|
||||||
f32 delta = ui->event->mouse_delta.x;
|
f32 delta = ui->event->mouse_delta.x;
|
||||||
n[0] += (char)delta;
|
n[0] += (char)delta;
|
||||||
}
|
}
|
||||||
@@ -460,7 +503,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
if (type->kind == type_kind_enum) {
|
if (type->kind == type_kind_enum) {
|
||||||
i64 value = ti_enum_read_value(p, type);
|
i64 value = ti_enum_read_value(p, type);
|
||||||
s8_t string_value = ti_enum_value_to_name(value, type);
|
s8_t string_value = ti_enum_value_to_name(value, type);
|
||||||
if (ui_button("%S: %S = %S", name, type->name, string_value).clicked) {
|
if (ui_label_button("%S: %S = %S", name, type->name, string_value).clicked) {
|
||||||
i64 new_value = ti_enum_next_value(p, value, type);
|
i64 new_value = ti_enum_next_value(p, value, type);
|
||||||
ti_enum_write_value(p, new_value, type);
|
ti_enum_write_value(p, new_value, type);
|
||||||
}
|
}
|
||||||
@@ -468,7 +511,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type->kind == type_kind_array) {
|
if (type->kind == type_kind_array) {
|
||||||
defer_if (ui_begin_expander("%S:", name).clicked, ui_end_expander()) {
|
ui_expander("%S:", name) {
|
||||||
for (i32 i = 0; i < type->count; i += 1) {
|
for (i32 i = 0; i < type->count; i += 1) {
|
||||||
ma_temp_t scratch = ma_begin_scratch();
|
ma_temp_t scratch = ma_begin_scratch();
|
||||||
s8_t index_name = s8_printf(scratch.arena, "[%d]", i);
|
s8_t index_name = s8_printf(scratch.arena, "[%d]", i);
|
||||||
@@ -481,7 +524,7 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type->kind == type_kind_struct) {
|
if (type->kind == type_kind_struct) {
|
||||||
defer_if (ui_begin_expander("%S:", name).clicked, ui_end_expander()) {
|
ui_expander("%S:", name) {
|
||||||
for (i32 i = 0; i < type->count; i += 1) {
|
for (i32 i = 0; i < type->count; i += 1) {
|
||||||
type_member_t *tm = type->members + i;
|
type_member_t *tm = type->members + i;
|
||||||
void *tmp = ti_extract_member(p, tm);
|
void *tmp = ti_extract_member(p, tm);
|
||||||
@@ -498,33 +541,41 @@ fn void ui_serial_type(void *p, type_t *type) {
|
|||||||
ui_serial_subtype(p, type, type->name);
|
ui_serial_subtype(p, type, type->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn void ui_demo_init(ma_arena_t *arena) {
|
||||||
|
ui = ma_push_type(arena, ui_t);
|
||||||
|
ui->box_arena = ma_push_arena(arena, mib(1));
|
||||||
|
}
|
||||||
|
|
||||||
gb app_event_t ui_test_event;
|
gb app_event_t ui_test_event;
|
||||||
fn void ui_demo_update(app_frame_t *frame) {
|
fn void ui_demo_update(app_frame_t *frame) {
|
||||||
|
ui_begin_frame(frame);
|
||||||
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
||||||
ui_begin_build(UILOC, ev, window_rect_from_frame(frame));
|
ui_begin_build(UILOC, ev, window_rect_from_frame(frame));
|
||||||
|
|
||||||
ui->top->op = ui_op_idle;
|
ui->top->rect = r2f32_shrinks(ui->top->rect, 200);
|
||||||
|
|
||||||
ui_box_t *scroller_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "scroller");
|
ui_box_t *scroller_box = ui_box0((ui_box_flags_t){.draw_rect = true, .clip_rect = true});
|
||||||
ui_set_rect(scroller_box, r2f32_cut_right(&ui->top->rect, ui_em(0.5f)));
|
ui_set_rect(scroller_box, r2f32_cut_right(&ui->top->rect, ui_em(0.5f)));
|
||||||
|
|
||||||
ui_box_t *item_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "item_box");
|
ui_box_t *item_box = ui_box0((ui_box_flags_t){.draw_rect = true, .clip_rect = true});
|
||||||
ui_set_rect(item_box, r2f32_cut_left(&ui->top->rect, ui_max));
|
ui_set_rect(item_box, r2f32_cut_left(&ui->top->rect, ui_max));
|
||||||
|
|
||||||
static f32 scroller_value;
|
static f32 scroller_value;
|
||||||
defer_block(ui_push_top(item_box), ui_pop_top()) {
|
ui_set_text_align(ui_text_align_center)
|
||||||
|
ui_set_top(item_box) {
|
||||||
for (i32 i = 0; i < lengthof(tweak_table); i += 1) {
|
for (i32 i = 0; i < lengthof(tweak_table); i += 1) {
|
||||||
mt_tweak_t *tweak = tweak_table + i;
|
mt_tweak_t *tweak = tweak_table + i;
|
||||||
if (s8_starts_with(tweak->name, s8_lit("_"), false)) continue;
|
if (s8_starts_with(tweak->name, s8_lit("_"), false)) continue;
|
||||||
|
|
||||||
if (tweak->type->kind == type_kind_b32) {
|
if (tweak->type->kind == type_kind_b32) {
|
||||||
b32 *n = (b32 *)tweak->ptr;
|
b32 *n = (b32 *)tweak->ptr;
|
||||||
if (ui_button("%S: %s##slider%S", tweak->name, *n ? "true" : "false", tweak->name).clicked) {
|
if (ui_label_button("%S: %s##slider%S", tweak->name, *n ? "true" : "false", tweak->name).clicked) {
|
||||||
*n = !*n;
|
*n = !*n;
|
||||||
}
|
}
|
||||||
} else if (tweak->type->kind == type_kind_f32) {
|
} else if (tweak->type->kind == type_kind_f32) {
|
||||||
f32 *n = (f32 *)tweak->ptr;
|
f32 *n = (f32 *)tweak->ptr;
|
||||||
ui_signal_t signal = ui_button("%S: %f##slider%S", tweak->name, *n, tweak->name);
|
ui_signal_t signal = ui_label_button("%S: %f##slider%S", tweak->name, *n, tweak->name);
|
||||||
if (signal.dragging) {
|
if (signal.dragging) {
|
||||||
f32 size = tweak->max - tweak->min;
|
f32 size = tweak->max - tweak->min;
|
||||||
v2f32_t string_size = rn_measure_string(rn_state.main_font, signal.box->string);
|
v2f32_t string_size = rn_measure_string(rn_state.main_font, signal.box->string);
|
||||||
@@ -534,17 +585,17 @@ fn void ui_demo_update(app_frame_t *frame) {
|
|||||||
} else_is_invalid;
|
} else_is_invalid;
|
||||||
}
|
}
|
||||||
ui_serial_type(&ui_test_event, type(app_event_t));
|
ui_serial_type(&ui_test_event, type(app_event_t));
|
||||||
defer_if (ui_begin_expander("app_event_t").clicked, ui_end_expander()) {
|
ui_expander("app_event_t") {
|
||||||
for (int i = 0; i < 2; i += 1) {
|
for (int i = 0; i < 2; i += 1) {
|
||||||
ui_label("kind: app_event_kind_t##a%d", i);
|
ui_label("kind: app_event_kind_t##a%d", i);
|
||||||
ui_label("ctrl: b8##ds%d", i);
|
ui_label("ctrl: b8##ds%d", i);
|
||||||
ui_label("shift: b8##f%d", i);
|
ui_label("shift: b8##f%d", i);
|
||||||
defer_if (ui_begin_expander("pos: v3f32_t##gg%d", i).clicked, ui_end_expander()) {
|
ui_expander("pos: v3f32_t##gg%d", i) {
|
||||||
ui_label("x: f64 = value##hgt%d", i);
|
ui_label("x: f64 = value##hgt%d", i);
|
||||||
ui_label("y: f64 = value##r%d", i);
|
ui_label("y: f64 = value##r%d", i);
|
||||||
ui_label("z: f64 = value##yr%d", i);
|
ui_label("z: f64 = value##yr%d", i);
|
||||||
}
|
}
|
||||||
defer_if (ui_begin_expander("mouse_pos: v2f32_t##i2%d", i).clicked, ui_end_expander()) {
|
ui_expander("mouse_pos: v2f32_t##i2%d", i) {
|
||||||
ui_label("x: f64 = value##i3%d", i);
|
ui_label("x: f64 = value##i3%d", i);
|
||||||
ui_label("y: f64 = value##i4%d", i);
|
ui_label("y: f64 = value##i4%d", i);
|
||||||
}
|
}
|
||||||
@@ -578,10 +629,7 @@ fn void ui_demo_update(app_frame_t *frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (ui_box_t *it = item_box->first; it; it = it->next) {
|
for (ui_box_t *it = item_box->first; it; it = it->next) {
|
||||||
it->full_rect.min.y -= scroller_value;
|
ui_offset_box(it, v2f32(0, scroller_value));
|
||||||
it->full_rect.max.y -= scroller_value;
|
|
||||||
it->rect.min.y -= scroller_value;
|
|
||||||
it->rect.max.y -= scroller_value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -589,15 +637,9 @@ fn void ui_demo_update(app_frame_t *frame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rn_begin();
|
rn_begin();
|
||||||
ui_draw(frame);
|
ui_draw();
|
||||||
rn_draw_stringf(rn_state.main_font, v2f32(0, frame->window_size.y - rn_state.main_font->size), black_color_global, "boxes: %d", ui->allocated_boxes);
|
rn_draw_stringf(rn_state.main_font, v2f32(0, frame->window_size.y - rn_state.main_font->size), black_color_global, "boxes: %d", ui->allocated_boxes);
|
||||||
rn_end(frame->window_size, white_color_global);
|
rn_end(frame->window_size, white_color_global);
|
||||||
|
|
||||||
|
ui_end_frame();
|
||||||
// End frame
|
|
||||||
for (app_event_t *ev = frame->first_event; ev; ev = ev->next) {
|
|
||||||
if (ev_left_up(ev)) {
|
|
||||||
ui->active = ui_null_id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
31
src/ui/ui.gen.c
Normal file
31
src/ui/ui.gen.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
fn void ui_push_id(ui_id_t v) { ui_id_node_t *n = ma_push_type(tcx.temp, ui_id_node_t); n->value = v; SLLS_PUSH(ui->id_stack, n); }
|
||||||
|
fn void ui_pop_id(void) { SLLS_POP(ui->id_stack); }
|
||||||
|
#define ui_set_id(x) defer_block(ui_push_id(x), ui_pop_id())
|
||||||
|
fn void ui_push_lop(ui_lop_t v) { ui_lop_node_t *n = ma_push_type(tcx.temp, ui_lop_node_t); n->value = v; SLLS_PUSH(ui->lop_stack, n); }
|
||||||
|
fn void ui_pop_lop(void) { SLLS_POP(ui->lop_stack); }
|
||||||
|
#define ui_set_lop(x) defer_block(ui_push_lop(x), ui_pop_lop())
|
||||||
|
fn void ui_push_border_thickness(f32 v) { ui_f32_node_t *n = ma_push_type(tcx.temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->border_thickness_stack, n); }
|
||||||
|
fn void ui_pop_border_thickness(void) { SLLS_POP(ui->border_thickness_stack); }
|
||||||
|
#define ui_set_border_thickness(x) defer_block(ui_push_border_thickness(x), ui_pop_border_thickness())
|
||||||
|
fn void ui_push_text_align(ui_text_align_t v) { ui_text_align_node_t *n = ma_push_type(tcx.temp, ui_text_align_node_t); n->value = v; SLLS_PUSH(ui->text_align_stack, n); }
|
||||||
|
fn void ui_pop_text_align(void) { SLLS_POP(ui->text_align_stack); }
|
||||||
|
#define ui_set_text_align(x) defer_block(ui_push_text_align(x), ui_pop_text_align())
|
||||||
|
fn void ui_push_required_width(f32 v) { ui_f32_node_t *n = ma_push_type(tcx.temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->required_width_stack, n); }
|
||||||
|
fn void ui_pop_required_width(void) { SLLS_POP(ui->required_width_stack); }
|
||||||
|
#define ui_set_required_width(x) defer_block(ui_push_required_width(x), ui_pop_required_width())
|
||||||
|
fn void ui_push_required_height(f32 v) { ui_f32_node_t *n = ma_push_type(tcx.temp, ui_f32_node_t); n->value = v; SLLS_PUSH(ui->required_height_stack, n); }
|
||||||
|
fn void ui_pop_required_height(void) { SLLS_POP(ui->required_height_stack); }
|
||||||
|
#define ui_set_required_height(x) defer_block(ui_push_required_height(x), ui_pop_required_height())
|
||||||
|
fn void ui_push_padding(v2f32_t v) { ui_v2f32_node_t *n = ma_push_type(tcx.temp, ui_v2f32_node_t); n->value = v; SLLS_PUSH(ui->padding_stack, n); }
|
||||||
|
fn void ui_pop_padding(void) { SLLS_POP(ui->padding_stack); }
|
||||||
|
#define ui_set_padding(x) defer_block(ui_push_padding(x), ui_pop_padding())
|
||||||
|
fn void ui_assert_stacks_are_null(void) {
|
||||||
|
assert(ui->id_stack == NULL);
|
||||||
|
assert(ui->lop_stack == NULL);
|
||||||
|
assert(ui->border_thickness_stack == NULL);
|
||||||
|
assert(ui->text_align_stack == NULL);
|
||||||
|
assert(ui->required_width_stack == NULL);
|
||||||
|
assert(ui->required_height_stack == NULL);
|
||||||
|
assert(ui->padding_stack == NULL);
|
||||||
|
}
|
||||||
22
src/ui/ui.gen.h
Normal file
22
src/ui/ui.gen.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
typedef struct ui_id_node_t ui_id_node_t; struct ui_id_node_t { ui_id_t value; ui_id_node_t *next; };
|
||||||
|
typedef struct ui_lop_node_t ui_lop_node_t; struct ui_lop_node_t { ui_lop_t value; ui_lop_node_t *next; };
|
||||||
|
typedef struct ui_f32_node_t ui_f32_node_t; struct ui_f32_node_t { f32 value; ui_f32_node_t *next; };
|
||||||
|
typedef struct ui_text_align_node_t ui_text_align_node_t; struct ui_text_align_node_t { ui_text_align_t value; ui_text_align_node_t *next; };
|
||||||
|
typedef struct ui_v2f32_node_t ui_v2f32_node_t; struct ui_v2f32_node_t { v2f32_t value; ui_v2f32_node_t *next; };
|
||||||
|
|
||||||
|
#define UI_DECL_BOX_MEMBERS \
|
||||||
|
f32 border_thickness;\
|
||||||
|
ui_text_align_t text_align;\
|
||||||
|
f32 required_width;\
|
||||||
|
f32 required_height;\
|
||||||
|
v2f32_t padding;\
|
||||||
|
|
||||||
|
#define UI_DECL_STACKS \
|
||||||
|
ui_id_node_t *id_stack;\
|
||||||
|
ui_lop_node_t *lop_stack;\
|
||||||
|
ui_f32_node_t *border_thickness_stack;\
|
||||||
|
ui_text_align_node_t *text_align_stack;\
|
||||||
|
ui_f32_node_t *required_width_stack;\
|
||||||
|
ui_f32_node_t *required_height_stack;\
|
||||||
|
ui_v2f32_node_t *padding_stack;\
|
||||||
22
src/ui/ui.h
22
src/ui/ui.h
@@ -25,13 +25,14 @@ typedef enum {
|
|||||||
} ui_text_align_t;
|
} ui_text_align_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ui_op_cut_top,
|
ui_lop_cut_top,
|
||||||
ui_op_cut_bottom,
|
ui_lop_cut_bottom,
|
||||||
ui_op_cut_left,
|
ui_lop_cut_left,
|
||||||
ui_op_cut_right,
|
ui_lop_cut_right,
|
||||||
ui_op_idle,
|
ui_lop_idle,
|
||||||
} ui_op_t;
|
} ui_lop_t;
|
||||||
|
|
||||||
|
#include "ui.gen.h"
|
||||||
typedef struct ui_box_t ui_box_t;
|
typedef struct ui_box_t ui_box_t;
|
||||||
struct ui_box_t {
|
struct ui_box_t {
|
||||||
ui_box_t *next;
|
ui_box_t *next;
|
||||||
@@ -46,9 +47,8 @@ struct ui_box_t {
|
|||||||
|
|
||||||
ui_box_flags_t flags;
|
ui_box_flags_t flags;
|
||||||
b8 created_new;
|
b8 created_new;
|
||||||
ui_text_align_t text_align;
|
UI_DECL_BOX_MEMBERS
|
||||||
|
|
||||||
ui_op_t op;
|
|
||||||
r2f32_t full_rect;
|
r2f32_t full_rect;
|
||||||
r2f32_t rect;
|
r2f32_t rect;
|
||||||
|
|
||||||
@@ -71,12 +71,14 @@ struct ui_signal_t {
|
|||||||
|
|
||||||
typedef struct ui_t ui_t;
|
typedef struct ui_t ui_t;
|
||||||
struct ui_t {
|
struct ui_t {
|
||||||
|
app_frame_t *frame;
|
||||||
|
|
||||||
// building
|
// building
|
||||||
ui_box_t root;
|
ui_box_t root;
|
||||||
ui_box_t *top;
|
ui_box_t *top;
|
||||||
app_event_t *event;
|
app_event_t *event;
|
||||||
stack_t(ui_id_t, 32) id_stack;
|
|
||||||
ui_text_align_t pref_text_align;
|
UI_DECL_STACKS
|
||||||
|
|
||||||
// allocation
|
// allocation
|
||||||
ma_arena_t *box_arena;
|
ma_arena_t *box_arena;
|
||||||
|
|||||||
76
src/ui/ui.meta.c
Normal file
76
src/ui/ui.meta.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
void mt_ui(ma_arena_t *arena) {
|
||||||
|
typedef struct cg_ui_stacks_t cg_ui_stacks_t;
|
||||||
|
struct cg_ui_stacks_t {
|
||||||
|
s8_t type;
|
||||||
|
s8_t name;
|
||||||
|
b32 skip_box_member;
|
||||||
|
|
||||||
|
s8_t stack;
|
||||||
|
s8_t node;
|
||||||
|
};
|
||||||
|
|
||||||
|
cg_ui_stacks_t stacks[] = {
|
||||||
|
{s8_lit("ui_id_t") , s8_lit("id") , .skip_box_member = true} ,
|
||||||
|
{s8_lit("ui_lop_t") , s8_lit("lop") , .skip_box_member = true} ,
|
||||||
|
{s8_lit("f32") , s8_lit("border_thickness")} ,
|
||||||
|
{s8_lit("ui_text_align_t") , s8_lit("text_align")} ,
|
||||||
|
{s8_lit("f32") , s8_lit("required_width")} ,
|
||||||
|
{s8_lit("f32") , s8_lit("required_height")} ,
|
||||||
|
{s8_lit("v2f32_t") , s8_lit("padding")} ,
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
// fill stack and node
|
||||||
|
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||||
|
s8_t core_type = it->type;
|
||||||
|
if (s8_ends_with(core_type, s8_lit("_t"), false)) core_type = s8_chop(core_type, 2);
|
||||||
|
it->stack = s8_printf(arena, "%S_stack", it->name);
|
||||||
|
it->node = s8_printf(arena, "%S_node_t", core_type);
|
||||||
|
if (!s8_starts_with(it->node, s8_lit("ui_"), false)) it->node = s8_printf(arena, "ui_%S", it->node);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb8_t *h_sb = sb8_serial_begin(arena);
|
||||||
|
sb8_t *c_sb = sb8_serial_begin(arena);
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
// generate types
|
||||||
|
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||||
|
for (cg_ui_stacks_t *jt = it - 1; jt >= stacks; jt -= 1) if (s8_are_equal(it->type, jt->type)) goto type_already_gened;
|
||||||
|
sb8_stmtf(h_sb, "typedef struct %S %S; struct %S { %S value; %S *next; };", it->node, it->node, it->node, it->type, it->node);
|
||||||
|
type_already_gened:;
|
||||||
|
}
|
||||||
|
sb8_printf(h_sb, "\n");
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
// generate field embeds
|
||||||
|
sb8_stmtf(h_sb, "#define UI_DECL_BOX_MEMBERS \\");
|
||||||
|
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||||
|
if (it->skip_box_member) continue;
|
||||||
|
sb8_stmtf(h_sb, "%S %S;\\", it->type, it->name);
|
||||||
|
}
|
||||||
|
sb8_printf(h_sb, "\n");
|
||||||
|
|
||||||
|
sb8_stmtf(h_sb, "#define UI_DECL_STACKS \\");
|
||||||
|
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||||
|
sb8_stmtf(h_sb, "%S *%S;\\", it->node, it->stack);
|
||||||
|
}
|
||||||
|
sb8_printf(h_sb, "\n");
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
// generate stack functions
|
||||||
|
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||||
|
sb8_stmtf(c_sb, "fn void ui_push_%S(%S v) { %S *n = ma_push_type(tcx.temp, %S); n->value = v; SLLS_PUSH(ui->%S, n); }", it->name, it->type, it->node, it->node, it->stack);
|
||||||
|
sb8_stmtf(c_sb, "fn void ui_pop_%S(void) { SLLS_POP(ui->%S); }", it->name, it->stack);
|
||||||
|
sb8_stmtf(c_sb, "#define ui_set_%S(x) defer_block(ui_push_%S(x), ui_pop_%S())", it->name, it->name, it->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb8_stmtf(c_sb, "fn void ui_assert_stacks_are_null(void) {");
|
||||||
|
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||||
|
sb8_stmtf(c_sb, "assert(ui->%S == NULL);", it->stack);
|
||||||
|
}
|
||||||
|
sb8_stmtf(c_sb, "}");
|
||||||
|
|
||||||
|
|
||||||
|
os_write_file(cg_cpath(arena), sb8_serial_end(arena, c_sb));
|
||||||
|
os_write_file(cg_hpath(arena), sb8_serial_end(arena, h_sb));
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "render/render_opengl.c"
|
#include "render/render_opengl.c"
|
||||||
#include "wasm_app.gen.c"
|
#include "wasm_app.gen.c"
|
||||||
#include "ui/ui_iter.c"
|
#include "ui/ui_iter.c"
|
||||||
|
#include "ui/ui.gen.c"
|
||||||
#include "ui/ui.c"
|
#include "ui/ui.c"
|
||||||
|
|
||||||
fn void app_init(f32 dpr) {
|
fn void app_init(f32 dpr) {
|
||||||
@@ -41,7 +42,6 @@ fn b32 app_update(app_frame_t *frame) {
|
|||||||
if (!f32_are_equal(font_size, _font_size)) {
|
if (!f32_are_equal(font_size, _font_size)) {
|
||||||
_font_size = font_size;
|
_font_size = font_size;
|
||||||
rn_reload_font(font_data, font_size);
|
rn_reload_font(font_data, font_size);
|
||||||
debugf("reloading font");
|
|
||||||
}
|
}
|
||||||
ui_demo_update(frame);
|
ui_demo_update(frame);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
5
todo.txt
5
todo.txt
@@ -23,10 +23,11 @@
|
|||||||
[x] remove dates and time from core
|
[x] remove dates and time from core
|
||||||
[ ] meta
|
[ ] meta
|
||||||
[x] search for python snippets and execute meta.py script on that file
|
[x] search for python snippets and execute meta.py script on that file
|
||||||
|
[ ] simplify logging!!!!
|
||||||
[ ] somehow index properly the meta files and ignore generated files
|
[ ] somehow index properly the meta files and ignore generated files
|
||||||
[ ] extract declarations from c files meta(introspect)
|
[x] extract declarations from c files meta(introspect)
|
||||||
[ ] extract all globals from c files
|
[ ] extract all globals from c files
|
||||||
[ ] tweak variables and embeds declared in c code
|
[x] tweak variables and embeds declared in c code
|
||||||
[ ] new simple format with tags
|
[ ] new simple format with tags
|
||||||
[x] revisit api
|
[x] revisit api
|
||||||
[ ] s8_bin
|
[ ] s8_bin
|
||||||
|
|||||||
Reference in New Issue
Block a user