moved code from header to source files
This commit is contained in:
71
src/widgets.c
Executable file
71
src/widgets.c
Executable file
@@ -0,0 +1,71 @@
|
||||
#include "tim.h"
|
||||
|
||||
void tim_frame(i32 x, i32 y, i32 w, i32 h, u64 color) {
|
||||
if (tim.event.type == TimEvent_Draw) {
|
||||
TimRect r = tim_scope_rect_to_absolute(x, y, w, h);
|
||||
tim_draw_box(r.x, r.y, r.w, r.h, color, color >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
void label(cstr s, i32 x, i32 y, i32 w, i32 h, u64 color) {
|
||||
if (tim.event.type == TimEvent_Draw) {
|
||||
TimText t = tim_scan_str(s);
|
||||
w = (w == A) ? t.width : w;
|
||||
h = (h == A) ? t.lines : h;
|
||||
TimRect r = tim_scope_rect_to_absolute(x, y, w, h);
|
||||
TimCell c = tim_cell(" ", color, color >> 8);
|
||||
tim_draw_lot(c, r.x, r.y, r.w, r.h);
|
||||
TimLine l = {.s = s, .line = ""};
|
||||
for (i32 i = 0; tim_next_line(&l); i++) {
|
||||
tim_draw_str(l.line, r.x, r.y + i, l.width, c.fg, c.bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool button(cstr txt, i32 x, i32 y, i32 w, i32 h, u64 color) {
|
||||
i32 tw = tim_utf8_len(txt);
|
||||
w = (w == A) ? (tw + 4) : w;
|
||||
h = (h == A) ? 3 : h;
|
||||
TimRect r = tim_scope_rect_to_absolute(x, y, w, h);
|
||||
|
||||
if (tim.event.type == TimEvent_Draw) {
|
||||
tim_draw_box(r.x, r.y, r.w, r.h, color >> 16, color >> 8);
|
||||
tim_draw_str(txt, r.x + (w - tw) / 2, r.y + h / 2, w, color, color >> 8);
|
||||
}
|
||||
return tim_is_mouse_click_over(r);
|
||||
}
|
||||
|
||||
bool check(cstr txt, i32* state, i32 x, i32 y, i32 w, u64 color) {
|
||||
w = (w == A) ? tim_utf8_len(txt) + 4 : w;
|
||||
TimRect r = tim_scope_rect_to_absolute(x, y, w, 1);
|
||||
|
||||
if (tim.event.type == TimEvent_Draw) {
|
||||
cstr st = *state == -1 ? "-" : *state ? "x" : " ";
|
||||
tim_draw_str("[ ] ", r.x, r.y, 4, color, color >> 8);
|
||||
tim_draw_str(st, r.x + 1, r.y, 1, color >> 16, color >> 8);
|
||||
tim_draw_str(txt, r.x + 4, r.y, r.w - 4, color, color >> 8);
|
||||
}
|
||||
|
||||
bool click = tim_is_mouse_click_over(r);
|
||||
*state = click ? !*state : *state;
|
||||
return click;
|
||||
}
|
||||
|
||||
|
||||
bool radio(cstr txt, i32* state, i32 v, i32 x, i32 y, i32 w, u64 color) {
|
||||
w = (w == A) ? tim_utf8_len(txt) + 4 : w;
|
||||
TimRect r = tim_scope_rect_to_absolute(x, y, w, 1);
|
||||
|
||||
if (tim.event.type == TimEvent_Draw) {
|
||||
cstr st = *state == v ? "o" : " ";
|
||||
tim_draw_str("( ) ", r.x, r.y, 4, color, color >> 8);
|
||||
tim_draw_str(st, r.x + 1, r.y, 1, color >> 16, color >> 8);
|
||||
tim_draw_str(txt, r.x + 4, r.y, r.w - 4, color, color >> 8);
|
||||
}
|
||||
|
||||
bool click = tim_is_mouse_click_over(r);
|
||||
*state = click ? v : *state;
|
||||
return click;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user