tim_button_noborder

This commit is contained in:
2026-01-12 18:34:13 +05:00
parent 1aa33128e9
commit 75d894b1bd
2 changed files with 21 additions and 7 deletions

View File

@@ -256,10 +256,14 @@ void tim_frame(i32 x, i32 y, i32 w, i32 h, TimStyle style);
// color: background, text // color: background, text
void tim_label(cstr s, i32 x, i32 y, i32 w, i32 h, TimStyle style); void tim_label(cstr s, i32 x, i32 y, i32 w, i32 h, TimStyle style);
// button - returns true on click // button with border - returns true on click
// color: frame, background, text // color: frame, background, text
bool tim_button(cstr txt, i32 x, i32 y, i32 w, i32 h, TimStyle style); bool tim_button(cstr txt, i32 x, i32 y, i32 w, i32 h, TimStyle style);
// button without border - returns true on click
// color: frame, background, text
bool tim_button_noborder(cstr txt, i32 x, i32 y, i32 w, i32 h, TimStyle style);
// check box - returns true when clicked // check box - returns true when clicked
// txt : text label // txt : text label
// state: persistent state, 0 unchecked, -1 semi checked, !0: checked // state: persistent state, 0 unchecked, -1 semi checked, !0: checked

View File

@@ -23,14 +23,26 @@ void tim_label(cstr s, i32 x, i32 y, i32 w, i32 h, TimStyle style) {
} }
bool tim_button(cstr txt, i32 x, i32 y, i32 w, i32 h, TimStyle style) { bool tim_button(cstr txt, i32 x, i32 y, i32 w, i32 h, TimStyle style) {
i32 tw = tim_utf8_len(txt); i32 txt_w = tim_utf8_len(txt);
w = (w == A) ? (tw + 4) : w; w = (w == A) ? (txt_w + 4) : w;
h = (h == A) ? 3 : h; h = (h == A) ? 3 : h;
TimRect r = tim_scope_rect_to_absolute(x, y, w, h); TimRect r = tim_scope_rect_to_absolute(x, y, w, h);
if (tim->event.type == TimEvent_Draw) { if (tim->event.type == TimEvent_Draw) {
tim_draw_box(r.x, r.y, r.w, r.h, style.brd, style.bg); tim_draw_box(r.x, r.y, r.w, r.h, style.brd, style.bg);
tim_draw_str(txt, r.x + (w - tw) / 2, r.y + h / 2, w, style.fg, style.bg); tim_draw_str(txt, r.x + (w - txt_w) / 2, r.y + h / 2, w, style.fg, style.bg);
}
return tim_is_mouse_click_over(r);
}
bool tim_button_noborder(cstr txt, i32 x, i32 y, i32 w, i32 h, TimStyle style) {
i32 txt_w = tim_utf8_len(txt);
w = (w == A) ? txt_w : w;
h = (h == A) ? 1 : h;
TimRect r = tim_scope_rect_to_absolute(x, y, w, h);
if (tim->event.type == TimEvent_Draw) {
tim_draw_str(txt, r.x + (w - txt_w) / 2, r.y + h / 2, w, style.fg, style.bg);
} }
return tim_is_mouse_click_over(r); return tim_is_mouse_click_over(r);
} }
@@ -67,5 +79,3 @@ bool tim_radiobutton(cstr txt, i32* state, i32 v, i32 x, i32 y, i32 w, TimStyle
*state = click ? v : *state; *state = click ? v : *state;
return click; return click;
} }