aboutsummaryrefslogtreecommitdiff
path: root/teensy
diff options
context:
space:
mode:
Diffstat (limited to 'teensy')
-rw-r--r--teensy/teensy_ui.c28
-rw-r--r--teensy/teensy_ui.h1
2 files changed, 29 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;
+}
diff --git a/teensy/teensy_ui.h b/teensy/teensy_ui.h
index 9a1e33a..aae066f 100644
--- a/teensy/teensy_ui.h
+++ b/teensy/teensy_ui.h
@@ -36,6 +36,7 @@ bool tyui_begin_window_ex(
bool *closed
);
void tyui_end_window(void);
+bool tyui_button(const char *text);
void tyui_text(const char *text);