From 2f811f69c13c3ad9b05d15e6510192a7dde95c71 Mon Sep 17 00:00:00 2001 From: Physick <96335032+DegustatorPonos@users.noreply.github.com> Date: Thu, 3 Sep 2026 01:54:55 +0500 Subject: scene reopen API --- src/ui_elements/Panel.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/ui_elements/Panel.c (limited to 'src/ui_elements/Panel.c') diff --git a/src/ui_elements/Panel.c b/src/ui_elements/Panel.c new file mode 100644 index 0000000..e9e6212 --- /dev/null +++ b/src/ui_elements/Panel.c @@ -0,0 +1,46 @@ +#include "UI.h" +#include + +void UpdatePanel(Panel *panel) { + if (panel == NULL) return; + for (size_t i = 0; i < panel->elementsCount; ++i) { + PanelElement *el = &panel->elements[i]; + el->update(el->data); + } +} + +void DrawPanel(Panel *panel, Rectangle rec, PanelDirection direction) { + if (panel == NULL) return; + float acc_x; + + if (direction == RIGHT_TO_LEFT) + acc_x = rec.x + rec.width - PANEL_SPACING_PX; + else + acc_x = rec.x + PANEL_SPACING_PX; + + for (size_t i = 0; i < panel->elementsCount; ++i) { + PanelElement *el = &panel->elements[i]; + Rectangle targetRec = { + .x = rec.x + acc_x, + .y = rec.y, + .height = rec.height, + .width = rec.height * el->proportion, + }; + if (direction == RIGHT_TO_LEFT) targetRec.x -= rec.height * el->proportion; + Rectangle zeroRec = { + .x = 0, + .y = 0, + .height = 0, + .width = 0, + }; + + el->draw(el, zeroRec); + if (direction == RIGHT_TO_LEFT) { + acc_x -= (targetRec.width + PANEL_SPACING_PX); + if (acc_x < rec.x) break; + } else { + acc_x += (targetRec.width + PANEL_SPACING_PX); + if (acc_x > rec.x + rec.width) break; + } + } +} -- cgit v1.3