From 722a9d1e729aff2eb64f3c064c33d547ea980eb0 Mon Sep 17 00:00:00 2001 From: physick Date: Fri, 31 Jul 2026 18:36:22 +0500 Subject: Buttons GUI start --- src/ui_elements/Button.c | 17 +++++++++++++++++ src/ui_elements/UI.h | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/ui_elements/Button.c (limited to 'src/ui_elements') diff --git a/src/ui_elements/Button.c b/src/ui_elements/Button.c new file mode 100644 index 0000000..f3ab8fa --- /dev/null +++ b/src/ui_elements/Button.c @@ -0,0 +1,17 @@ +#include "UI.h" +#include + +void UpdateButton(Button *btn, Rectangle *location) { + if (IsMouseInRec(*location) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + btn->OnClick(btn->parent); + } +} + +void DrawButton(Button *btn, Rectangle *location) { + DrawTexturePro(*btn->atlas, + btn->textrueLocation, + *location, + (Vector2) { 0 , 0 }, + 0, + WHITE); +} diff --git a/src/ui_elements/UI.h b/src/ui_elements/UI.h index 06d127f..c23faf7 100644 --- a/src/ui_elements/UI.h +++ b/src/ui_elements/UI.h @@ -1,5 +1,6 @@ #include #include +#include "../scenes/scenes.h" #ifndef UI_ELEMENTS_H #define UI_ELEMENTS_H @@ -17,6 +18,18 @@ void DrawTextInRec(Rectangle rec, char *text, Font *font, int height, Color colo float MeasureChar(Font *font, int height, char symbol); bool IsMouseInRec(Rectangle rec); +// ========== BUTTON ========== + +typedef struct { + Scene *parent; + void (*OnClick)(Scene *); + Texture *atlas; + Rectangle textrueLocation; +} Button; + +void UpdateButton(Button *btn, Rectangle *location); +void DrawButton(Button *btn, Rectangle *location); + // ========== TEXT EDITOR ========== static const size_t DEFAULT_TEXT_NODE_SIZE = 256; -- cgit v1.3