boxgadget: add API to set expand/align flags for gadget child

This commit is contained in:
Cosimo Cecchi 2016-02-24 10:34:15 -08:00
parent 6827bd5e04
commit 06776d3d2f
2 changed files with 85 additions and 8 deletions

View File

@ -622,9 +622,10 @@ gtk_box_gadget_insert_widget (GtkBoxGadget *gadget,
GTK_ALIGN_FILL); GTK_ALIGN_FILL);
} }
void static GtkBoxGadgetChild *
gtk_box_gadget_remove_object (GtkBoxGadget *gadget, gtk_box_gadget_find_object (GtkBoxGadget *gadget,
GObject *object) GObject *object,
int *position)
{ {
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget); GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
guint i; guint i;
@ -635,11 +636,29 @@ gtk_box_gadget_remove_object (GtkBoxGadget *gadget,
if (child->object == object) if (child->object == object)
{ {
gtk_css_node_set_parent (get_css_node (object), NULL); if (position)
g_array_remove_index (priv->children, i); *position = i;
break; return child;
} }
} }
return NULL;
}
static void
gtk_box_gadget_remove_object (GtkBoxGadget *gadget,
GObject *object)
{
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
GtkBoxGadgetChild *child;
int position;
child = gtk_box_gadget_find_object (gadget, object, &position);
if (child)
{
gtk_css_node_set_parent (get_css_node (child->object), NULL);
g_array_remove_index (priv->children, position);
}
} }
void void
@ -663,6 +682,14 @@ only_vertical (GObject *object,
return orientation == GTK_ORIENTATION_VERTICAL; return orientation == GTK_ORIENTATION_VERTICAL;
} }
static ComputeExpandFunc
expand_func_from_flags (gboolean hexpand,
gboolean vexpand)
{
return hexpand ? (vexpand ? (ComputeExpandFunc) gtk_true : only_horizontal)
: (vexpand ? only_vertical : (ComputeExpandFunc) gtk_false);
}
void void
gtk_box_gadget_insert_gadget (GtkBoxGadget *gadget, gtk_box_gadget_insert_gadget (GtkBoxGadget *gadget,
int pos, int pos,
@ -671,11 +698,13 @@ gtk_box_gadget_insert_gadget (GtkBoxGadget *gadget,
gboolean vexpand, gboolean vexpand,
GtkAlign align) GtkAlign align)
{ {
ComputeExpandFunc func;
func = expand_func_from_flags (hexpand, vexpand);
gtk_box_gadget_insert_object (gadget, gtk_box_gadget_insert_object (gadget,
pos, pos,
G_OBJECT (cssgadget), G_OBJECT (cssgadget),
hexpand ? (vexpand ? (ComputeExpandFunc) gtk_true : only_horizontal) func,
: (vexpand ? only_vertical : (ComputeExpandFunc) gtk_false),
align); align);
} }
@ -705,3 +734,44 @@ gtk_box_gadget_reverse_children (GtkBoxGadget *gadget)
*child2 = tmp; *child2 = tmp;
} }
} }
void
gtk_box_gadget_set_gadget_expand (GtkBoxGadget *gadget,
GtkCssGadget *cssgadget,
gboolean hexpand,
gboolean vexpand)
{
GtkBoxGadgetChild *child;
ComputeExpandFunc func;
child = gtk_box_gadget_find_object (gadget, G_OBJECT (cssgadget), NULL);
if (!child)
return;
func = expand_func_from_flags (hexpand, vexpand);
if (child->compute_expand == func)
return;
child->compute_expand = func;
gtk_css_gadget_queue_resize (GTK_CSS_GADGET (gadget));
}
void
gtk_box_gadget_set_gadget_align (GtkBoxGadget *gadget,
GtkCssGadget *cssgadget,
GtkAlign align)
{
GtkBoxGadgetChild *child;
child = gtk_box_gadget_find_object (gadget, G_OBJECT (cssgadget), NULL);
if (!child)
return;
if (child->align == align)
return;
child->align = align;
gtk_css_gadget_queue_resize (GTK_CSS_GADGET (gadget));
}

View File

@ -76,6 +76,13 @@ void gtk_box_gadget_remove_gadget (GtkBoxGadget
GtkCssGadget *cssgadget); GtkCssGadget *cssgadget);
void gtk_box_gadget_reverse_children (GtkBoxGadget *gadget); void gtk_box_gadget_reverse_children (GtkBoxGadget *gadget);
void gtk_box_gadget_set_gadget_expand (GtkBoxGadget *gadget,
GtkCssGadget *cssgadget,
gboolean hexpand,
gboolean vexpand);
void gtk_box_gadget_set_gadget_align (GtkBoxGadget *gadget,
GtkCssGadget *cssgadget,
GtkAlign align);
G_END_DECLS G_END_DECLS