diff options
Diffstat (limited to 'teensy/teensy_ui.c')
| -rw-r--r-- | teensy/teensy_ui.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c index c8369a5..c5bd6af 100644 --- a/teensy/teensy_ui.c +++ b/teensy/teensy_ui.c @@ -291,3 +291,31 @@ void tyui_text(const char *text) { text_cmd(text, next_pos(TEXT_HEIGHT)); } + +bool tyui_button(const char *text) +{ + const int padding = 2; + int width = ty_font_width(uictx.font, text); + ty_Vec2i pos = next_pos(TEXT_HEIGHT + padding + 1); + ty_Recti rect = ty_recti( + pos.x, pos.y, + width + padding, TEXT_HEIGHT + padding + ); + ty_Color bg_col = uictx.style.bg_normal; + ty_Vec2i mouse_pos = ty_mouse_pos(); + + mouse_pos.x -= uictx.active->rect.x; + mouse_pos.y -= uictx.active->rect.y + TEXT_HEIGHT; + + bool clicked = false; + + if (ty_pointi_in_recti(mouse_pos, rect)) { + bg_col = uictx.style.bg_hover; + clicked = ty_button_pressed(TY_BTN_DB_LMB); + } + + rect_cmd(rect, bg_col); + text_cmd(text, ty_vec2i(pos.x+1, pos.y+1)); + + return clicked; +} |
