diff options
| author | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-09-03 01:54:55 +0500 |
|---|---|---|
| committer | Physick <96335032+DegustatorPonos@users.noreply.github.com> | 2026-09-03 01:54:55 +0500 |
| commit | 2f811f69c13c3ad9b05d15e6510192a7dde95c71 (patch) | |
| tree | f65eda3ceef69243de609560c24538e9bf38c7b1 /src/ui_elements | |
| parent | da295397942073453ed9f82cc88dafd083d4c782 (diff) | |
scene reopen API
Diffstat (limited to 'src/ui_elements')
| -rw-r--r-- | src/ui_elements/Panel.c | 46 |
1 files changed, 46 insertions, 0 deletions
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 <raylib.h> + +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; + } + } +} |
