gadget: Handle visibility
As GtkCssNode has the visibility concept, it makes sense to mirror it in gadgets. Do what visibility does in widgets: Hidden gadgets can't be drawn or allocated and request a 0x0 size. Note that just like widgets, gadget visibility must not be changed in size request, allocate or draw handlers. GtkWidget::child-visible has no equivalent yet, code will have to emulate that manually.
This commit is contained in:

committed by
Cosimo Cecchi

parent
9950764f12
commit
acbff85402
@ -337,6 +337,23 @@ gtk_css_gadget_get_owner (GtkCssGadget *gadget)
|
|||||||
return priv->owner;
|
return priv->owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_css_gadget_set_visible (GtkCssGadget *gadget,
|
||||||
|
gboolean visible)
|
||||||
|
{
|
||||||
|
GtkCssGadgetPrivate *priv = gtk_css_gadget_get_instance_private (gadget);
|
||||||
|
|
||||||
|
gtk_css_node_set_visible (priv->node, visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
gtk_css_gadget_get_visible (GtkCssGadget *gadget)
|
||||||
|
{
|
||||||
|
GtkCssGadgetPrivate *priv = gtk_css_gadget_get_instance_private (gadget);
|
||||||
|
|
||||||
|
return gtk_css_node_get_visible (priv->node);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_css_gadget_add_class:
|
* gtk_css_gadget_add_class:
|
||||||
* @gadget: a #GtkCssGadget
|
* @gadget: a #GtkCssGadget
|
||||||
@ -456,6 +473,17 @@ gtk_css_gadget_get_preferred_size (GtkCssGadget *gadget,
|
|||||||
if (natural == NULL)
|
if (natural == NULL)
|
||||||
natural = &unused_natural;
|
natural = &unused_natural;
|
||||||
|
|
||||||
|
if (!gtk_css_gadget_get_visible (gadget))
|
||||||
|
{
|
||||||
|
*minimum = 0;
|
||||||
|
*natural = 0;
|
||||||
|
if (minimum_baseline)
|
||||||
|
*minimum_baseline = -1;
|
||||||
|
if (natural_baseline)
|
||||||
|
*natural_baseline = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
style = gtk_css_gadget_get_style (gadget);
|
style = gtk_css_gadget_get_style (gadget);
|
||||||
get_box_margin (style, &margin);
|
get_box_margin (style, &margin);
|
||||||
get_box_border (style, &border);
|
get_box_border (style, &border);
|
||||||
@ -531,6 +559,9 @@ gtk_css_gadget_allocate (GtkCssGadget *gadget,
|
|||||||
|
|
||||||
g_return_if_fail (out_clip != NULL);
|
g_return_if_fail (out_clip != NULL);
|
||||||
|
|
||||||
|
if (!gtk_css_gadget_get_visible (gadget))
|
||||||
|
return;
|
||||||
|
|
||||||
priv->allocated_size = *allocation;
|
priv->allocated_size = *allocation;
|
||||||
priv->allocated_baseline = baseline;
|
priv->allocated_baseline = baseline;
|
||||||
|
|
||||||
@ -609,6 +640,9 @@ gtk_css_gadget_draw (GtkCssGadget *gadget,
|
|||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
int contents_x, contents_y, contents_width, contents_height;
|
int contents_x, contents_y, contents_width, contents_height;
|
||||||
|
|
||||||
|
if (!gtk_css_gadget_get_visible (gadget))
|
||||||
|
return;
|
||||||
|
|
||||||
x = priv->allocated_size.x;
|
x = priv->allocated_size.x;
|
||||||
y = priv->allocated_size.y;
|
y = priv->allocated_size.y;
|
||||||
if (priv->owner && !gtk_widget_get_has_window (priv->owner))
|
if (priv->owner && !gtk_widget_get_has_window (priv->owner))
|
||||||
@ -694,6 +728,15 @@ gtk_css_gadget_get_border_allocation (GtkCssGadget *gadget,
|
|||||||
|
|
||||||
g_return_if_fail (GTK_IS_CSS_GADGET (gadget));
|
g_return_if_fail (GTK_IS_CSS_GADGET (gadget));
|
||||||
|
|
||||||
|
if (!gtk_css_gadget_get_visible (gadget))
|
||||||
|
{
|
||||||
|
if (allocation)
|
||||||
|
allocation->x = allocation->y = allocation->width = allocation->height = 0;
|
||||||
|
if (baseline)
|
||||||
|
*baseline = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
get_box_margin (gtk_css_gadget_get_style (gadget), &margin);
|
get_box_margin (gtk_css_gadget_get_style (gadget), &margin);
|
||||||
|
|
||||||
if (allocation)
|
if (allocation)
|
||||||
@ -723,6 +766,15 @@ gtk_css_gadget_get_content_allocation (GtkCssGadget *gadget,
|
|||||||
|
|
||||||
g_return_if_fail (GTK_IS_CSS_GADGET (gadget));
|
g_return_if_fail (GTK_IS_CSS_GADGET (gadget));
|
||||||
|
|
||||||
|
if (!gtk_css_gadget_get_visible (gadget))
|
||||||
|
{
|
||||||
|
if (allocation)
|
||||||
|
allocation->x = allocation->y = allocation->width = allocation->height = 0;
|
||||||
|
if (baseline)
|
||||||
|
*baseline = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
style = gtk_css_gadget_get_style (gadget);
|
style = gtk_css_gadget_get_style (gadget);
|
||||||
get_box_margin (style, &margin);
|
get_box_margin (style, &margin);
|
||||||
get_box_border (style, &border);
|
get_box_border (style, &border);
|
||||||
|
@ -78,6 +78,10 @@ GtkCssNode * gtk_css_gadget_get_node (GtkCssGadget
|
|||||||
GtkCssStyle * gtk_css_gadget_get_style (GtkCssGadget *gadget);
|
GtkCssStyle * gtk_css_gadget_get_style (GtkCssGadget *gadget);
|
||||||
GtkWidget * gtk_css_gadget_get_owner (GtkCssGadget *gadget);
|
GtkWidget * gtk_css_gadget_get_owner (GtkCssGadget *gadget);
|
||||||
|
|
||||||
|
void gtk_css_gadget_set_visible (GtkCssGadget *gadget,
|
||||||
|
gboolean visible);
|
||||||
|
gboolean gtk_css_gadget_get_visible (GtkCssGadget *gadget);
|
||||||
|
|
||||||
void gtk_css_gadget_add_class (GtkCssGadget *gadget,
|
void gtk_css_gadget_add_class (GtkCssGadget *gadget,
|
||||||
const char *name);
|
const char *name);
|
||||||
void gtk_css_gadget_remove_class (GtkCssGadget *gadget,
|
void gtk_css_gadget_remove_class (GtkCssGadget *gadget,
|
||||||
|
Reference in New Issue
Block a user