blob: e9e62128e397b84193cd11f5377451a99ee6de70 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}
}
}
|