gui: Allow elements to be hidden
When a GUI element is hidden, no rendering or updating is done to it or its children. This can be useful to define a complex GUI tree structure that changes under specific conditions, without redefining it.
This commit is contained in:
parent
d0089e7ddf
commit
d989dc6f49
|
@ -24,7 +24,7 @@ struct gui_common
|
||||||
} *cb;
|
} *cb;
|
||||||
|
|
||||||
short x, y, xoff, yoff;
|
short x, y, xoff, yoff;
|
||||||
bool hcentered, vcentered;
|
bool hidden, hcentered, vcentered;
|
||||||
struct gui_common *parent, *child, *sibling;
|
struct gui_common *parent, *child, *sibling;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
static void add_child(struct gui_common *const parent,
|
static void add_child(struct gui_common *const parent,
|
||||||
struct gui_common *const child)
|
struct gui_common *const child)
|
||||||
{
|
{
|
||||||
if (!child->cb || !child->cb->get_dim)
|
if (child->hidden || !child->cb || !child->cb->get_dim)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct gui_container *const c = (struct gui_container *)parent;
|
struct gui_container *const c = (struct gui_container *)parent;
|
||||||
|
@ -62,11 +62,14 @@ static int update(struct gui_common *const g,
|
||||||
|
|
||||||
struct gui_common *const child = c->common.child;
|
struct gui_common *const child = c->common.child;
|
||||||
|
|
||||||
if (child->cb->get_dim)
|
if (child && child->cb)
|
||||||
add_child(&c->common, child);
|
{
|
||||||
|
if (child->cb->get_dim)
|
||||||
|
add_child(&c->common, child);
|
||||||
|
|
||||||
for (struct gui_common *s = child->sibling; s; s = s->sibling)
|
for (struct gui_common *s = child->sibling; s; s = s->sibling)
|
||||||
add_child(&c->common, s);
|
add_child(&c->common, s);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,15 @@
|
||||||
static void get_centered(const struct gui_common *const g,
|
static void get_centered(const struct gui_common *const g,
|
||||||
short *const x, short *const y)
|
short *const x, short *const y)
|
||||||
{
|
{
|
||||||
if (g->cb && g->cb->get_dim)
|
if (!g->hidden && g->cb && g->cb->get_dim)
|
||||||
{
|
{
|
||||||
short w, h, pw = 0, ph = 0;
|
short w, h, pw = 0, ph = 0;
|
||||||
|
const struct gui_common *p = g->parent;
|
||||||
|
|
||||||
if (g->parent)
|
if (p)
|
||||||
{
|
{
|
||||||
if (g->parent->cb && g->parent->cb->get_dim)
|
if (!p->hidden && p->cb && p->cb->get_dim)
|
||||||
g->parent->cb->get_dim(g->parent, &pw, &ph);
|
p->cb->get_dim(p, &pw, &ph);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -34,6 +35,9 @@ static void get_centered(const struct gui_common *const g,
|
||||||
void gui_coords(const struct gui_common *const g, short *const x,
|
void gui_coords(const struct gui_common *const g, short *const x,
|
||||||
short *const y)
|
short *const y)
|
||||||
{
|
{
|
||||||
|
if (g->hidden)
|
||||||
|
return;
|
||||||
|
|
||||||
*x = g->x + g->xoff;
|
*x = g->x + g->xoff;
|
||||||
*y = g->y + g->yoff;
|
*y = g->y + g->yoff;
|
||||||
|
|
||||||
|
@ -79,6 +83,9 @@ bool gui_pressed(const struct gui_common *const g,
|
||||||
const union peripheral *const p,
|
const union peripheral *const p,
|
||||||
const struct camera *cam, const short w, const short h)
|
const struct camera *cam, const short w, const short h)
|
||||||
{
|
{
|
||||||
|
if (g->hidden)
|
||||||
|
return false;
|
||||||
|
|
||||||
bool check = false;
|
bool check = false;
|
||||||
|
|
||||||
switch (p->common.type)
|
switch (p->common.type)
|
||||||
|
@ -105,6 +112,9 @@ bool gui_released(const struct gui_common *const g,
|
||||||
const union peripheral *const p,
|
const union peripheral *const p,
|
||||||
const struct camera *cam, const short w, const short h)
|
const struct camera *cam, const short w, const short h)
|
||||||
{
|
{
|
||||||
|
if (g->hidden)
|
||||||
|
return false;
|
||||||
|
|
||||||
bool check = false;
|
bool check = false;
|
||||||
|
|
||||||
switch (p->common.type)
|
switch (p->common.type)
|
||||||
|
@ -155,13 +165,14 @@ void gui_add_child(struct gui_common *const p,
|
||||||
int gui_update(struct gui_common *const g, const union peripheral *const p,
|
int gui_update(struct gui_common *const g, const union peripheral *const p,
|
||||||
const struct camera *const c, struct input *const in)
|
const struct camera *const c, struct input *const in)
|
||||||
{
|
{
|
||||||
if ((g->child && gui_update(g->child, p, c, in))
|
if (!g->hidden
|
||||||
|| (g->cb && g->cb->update && g->cb->update(g, p, c, in)))
|
&& ((g->child && gui_update(g->child, p, c, in))
|
||||||
|
|| (g->cb && g->cb->update && g->cb->update(g, p, c, in))))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (struct gui_common *s = g->sibling; s; s = s->sibling)
|
for (struct gui_common *s = g->sibling; s; s = s->sibling)
|
||||||
if ((s->child && gui_update(s->child, p, c, in))
|
if (!s->hidden && ((s->child && gui_update(s->child, p, c, in))
|
||||||
|| (s->cb && s->cb->update && s->cb->update(s, p, c, in)))
|
|| (s->cb && s->cb->update && s->cb->update(s, p, c, in))))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -169,13 +180,13 @@ int gui_update(struct gui_common *const g, const union peripheral *const p,
|
||||||
|
|
||||||
int gui_render(const struct gui_common *const g)
|
int gui_render(const struct gui_common *const g)
|
||||||
{
|
{
|
||||||
if ((g->cb && g->cb->render && g->cb->render(g))
|
if (!g->hidden && ((g->cb && g->cb->render && g->cb->render(g))
|
||||||
|| (g->child && gui_render(g->child)))
|
|| (g->child && gui_render(g->child))))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (struct gui_common *s = g->sibling; s; s = s->sibling)
|
for (struct gui_common *s = g->sibling; s; s = s->sibling)
|
||||||
if ((s->cb && s->cb->render && s->cb->render(s))
|
if (!s->hidden && ((s->cb && s->cb->render && s->cb->render(s))
|
||||||
|| (s->child && gui_render(s->child)))
|
|| (s->child && gui_render(s->child))))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue