From 75d894b1bd98bbf0d9790276f26db8131b6111fe Mon Sep 17 00:00:00 2001 From: Timerix Date: Mon, 12 Jan 2026 18:34:13 +0500 Subject: [PATCH] tim_button_noborder --- include/tim.h | 6 +++++- src/widgets.c | 22 ++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/tim.h b/include/tim.h index afd7587..a271903 100644 --- a/include/tim.h +++ b/include/tim.h @@ -256,10 +256,14 @@ void tim_frame(i32 x, i32 y, i32 w, i32 h, TimStyle style); // color: background, text 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 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 // txt : text label // state: persistent state, 0 unchecked, -1 semi checked, !0: checked diff --git a/src/widgets.c b/src/widgets.c index c695ab5..b4646ef 100755 --- a/src/widgets.c +++ b/src/widgets.c @@ -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) { - i32 tw = tim_utf8_len(txt); - w = (w == A) ? (tw + 4) : w; - h = (h == A) ? 3 : h; + i32 txt_w = tim_utf8_len(txt); + w = (w == A) ? (txt_w + 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, 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); } @@ -67,5 +79,3 @@ bool tim_radiobutton(cstr txt, i32* state, i32 v, i32 x, i32 y, i32 w, TimStyle *state = click ? v : *state; return click; } - -