diff options
Diffstat (limited to 'src/ui_elements/Panel.c')
| -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; + } + } +} |
