57 lines
1.0 KiB
C
57 lines
1.0 KiB
C
#include <gui/container.h>
|
|
#include <gui.h>
|
|
|
|
static void add_child(struct gui_common *const parent,
|
|
struct gui_common *const child)
|
|
{
|
|
if (!child->get_dim)
|
|
return;
|
|
|
|
struct gui_container *const c = (struct gui_container *)parent;
|
|
short w, h;
|
|
|
|
child->get_dim(child, &w, &h);
|
|
|
|
switch (c->mode)
|
|
{
|
|
case GUI_CONTAINER_MODE_H:
|
|
child->x += c->w;
|
|
c->w += w;
|
|
|
|
if (h > c->h)
|
|
c->h = h;
|
|
|
|
break;
|
|
|
|
case GUI_CONTAINER_MODE_V:
|
|
child->y += c->h;
|
|
c->h += h;
|
|
|
|
if (w > c->w)
|
|
c->w = w;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
static void get_dim(const struct gui_common *const g,
|
|
short *const w, short *const h)
|
|
{
|
|
struct gui_container *const c = (struct gui_container *)g;
|
|
|
|
*w = c->w;
|
|
*h = c->h;
|
|
}
|
|
|
|
void gui_container_init(struct gui_container *const c)
|
|
{
|
|
*c = (const struct gui_container)
|
|
{
|
|
.common =
|
|
{
|
|
.add_child = add_child,
|
|
.get_dim = get_dim
|
|
}
|
|
};
|
|
}
|