#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; } } }