Browse Source

add visibility flag for widgets

master
Alexandros Theodotou 3 years ago
parent
commit
74bc87a6c0
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 8
      inc/ztoolkit/ztk_widget.h
  2. 30
      src/ztk_app.c
  3. 2
      src/ztk_control.c
  4. 12
      src/ztk_widget.c

8
inc/ztoolkit/ztk_widget.h

@ -246,6 +246,14 @@ ztk_widget_set_user_data ( @@ -246,6 +246,14 @@ ztk_widget_set_user_data (
ZtkWidget * self,
void * data);
/**
* Shows or hides the widget.
*/
void
ztk_widget_set_visible (
ZtkWidget * self,
int visible);
/**
* @}
*/

30
src/ztk_app.c

@ -44,7 +44,10 @@ on_expose ( @@ -44,7 +44,10 @@ on_expose (
for (int i = 0; i < self->num_widgets; i++)
{
w = self->widgets[i];
w->update_cb (w, w->user_data);
if (w->visible)
{
w->update_cb (w, w->user_data);
}
}
cairo_t* cr = (cairo_t*)puglGetContext(view);
@ -103,7 +106,7 @@ is_first_widget_hit ( @@ -103,7 +106,7 @@ is_first_widget_hit (
for (int i = self->num_widgets - 1; i >= 0; i--)
{
ZtkWidget * w = self->widgets[i];
if (ztk_widget_is_hit (w, x, y))
if (w->visible && ztk_widget_is_hit (w, x, y))
{
if (widget == w)
return 1;
@ -138,7 +141,8 @@ post_event_to_widgets ( @@ -138,7 +141,8 @@ post_event_to_widgets (
if (w->type ==
ZTK_WIDGET_TYPE_COMBO_BOX)
{
if (ztk_widget_is_hit (
if (w->visible &&
ztk_widget_is_hit (
w, ev->x, ev->y))
{
combo_box_hit = 1;
@ -161,7 +165,7 @@ post_event_to_widgets ( @@ -161,7 +165,7 @@ post_event_to_widgets (
{
const PuglEventKey * ev =
(const PuglEventKey *) event;
if (w->key_event_cb)
if (w->visible && w->key_event_cb)
{
w->key_event_cb (w, ev);
}
@ -171,7 +175,8 @@ post_event_to_widgets ( @@ -171,7 +175,8 @@ post_event_to_widgets (
{
const PuglEventButton * ev =
(const PuglEventButton *) event;
if (ztk_widget_is_hit (
if (w->visible &&
ztk_widget_is_hit (
w, ev->x, ev->y) &&
is_first_widget_hit (
self, w, ev->x, ev->y))
@ -204,7 +209,8 @@ post_event_to_widgets ( @@ -204,7 +209,8 @@ post_event_to_widgets (
w->state &=
(unsigned int)
~ZTK_WIDGET_STATE_PRESSED;
if (w->button_event_cb &&
if (w->visible &&
w->button_event_cb &&
(w->type ==
ZTK_WIDGET_TYPE_COMBO_BOX ||
!combo_box_hit))
@ -218,7 +224,8 @@ post_event_to_widgets ( @@ -218,7 +224,8 @@ post_event_to_widgets (
{
const PuglEventMotion * ev =
(const PuglEventMotion *) event;
if (ztk_widget_is_hit (
if (w->visible &&
ztk_widget_is_hit (
w, ev->x, ev->y) &&
is_first_widget_hit (
self, w, ev->x, ev->y))
@ -248,7 +255,8 @@ post_event_to_widgets ( @@ -248,7 +255,8 @@ post_event_to_widgets (
w->state &=
(unsigned int)
~ZTK_WIDGET_STATE_HOVERED;
if (w->motion_event_cb)
if (w->visible &&
w->motion_event_cb)
{
w->motion_event_cb (
w, ev, w->user_data);
@ -260,7 +268,8 @@ post_event_to_widgets ( @@ -260,7 +268,8 @@ post_event_to_widgets (
{
const PuglEventScroll * ev =
(const PuglEventScroll *) event;
if (ztk_widget_is_hit (
if (w->visible &&
ztk_widget_is_hit (
w, ev->x, ev->y) &&
w->scroll_event_cb)
{
@ -524,6 +533,9 @@ ztk_app_draw ( @@ -524,6 +533,9 @@ ztk_app_draw (
for (int i = 0; i < self->num_widgets; i++)
{
ZtkWidget * widget = self->widgets[i];
if (!widget->visible)
continue;
widget->draw_cb (
widget, cr, widget->user_data);
}

2
src/ztk_control.c

@ -127,7 +127,7 @@ update_cb ( @@ -127,7 +127,7 @@ update_cb (
break;
case ZTK_CTRL_DRAG_VERTICAL:
ctrl_val =
1.f -
1.0 -
(dy - w->rect.y) / w->rect.height;
break;
default:

12
src/ztk_widget.c

@ -51,6 +51,7 @@ ztk_widget_is_hit ( @@ -51,6 +51,7 @@ ztk_widget_is_hit (
double y)
{
return
self->visible &&
x >= self->rect.x &&
x <= self->rect.x + self->rect.width &&
y >= self->rect.y &&
@ -67,3 +68,14 @@ ztk_widget_set_user_data ( @@ -67,3 +68,14 @@ ztk_widget_set_user_data (
{
self->user_data = data;
}
/**
* Shows or hides the widget.
*/
void
ztk_widget_set_visible (
ZtkWidget * self,
int visible)
{
self->visible = visible;
}

Loading…
Cancel
Save