boxgadget: Add ability to draw children in reverse

This is necessary for GtkNotebook so that the stack is always drawn
before the header.
And that is necessary so that the active tab can use negative
margins to overdraw the border of the stack to create a gap and
simulate old GTK2-style visuals for notebooks.
This commit is contained in:
Benjamin Otte 2016-02-27 03:56:07 +01:00
parent a2fa647199
commit 245d217e06
3 changed files with 22 additions and 3 deletions

View File

@ -36,8 +36,10 @@
typedef struct _GtkBoxGadgetPrivate GtkBoxGadgetPrivate;
struct _GtkBoxGadgetPrivate {
GtkOrientation orientation;
gboolean draw_focus;
GArray *children;
guint draw_focus : 1;
guint draw_reverse : 1;
};
typedef gboolean (* ComputeExpandFunc) (GObject *object, GtkOrientation orientation);
@ -452,9 +454,10 @@ gtk_box_gadget_draw (GtkCssGadget *gadget,
GtkWidget *owner = gtk_css_gadget_get_owner (gadget);
guint i;
for (i = 0 ; i < priv->children->len; i++)
for (i = 0; i < priv->children->len; i++)
{
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, i);
guint draw_index = priv->draw_reverse ? priv->children->len - 1 - i : i;
GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, draw_index);
if (GTK_IS_WIDGET (child->object))
gtk_container_propagate_draw (GTK_CONTAINER (owner), GTK_WIDGET (child->object), cr);
@ -559,6 +562,15 @@ gtk_box_gadget_set_draw_focus (GtkBoxGadget *gadget,
priv->draw_focus = draw_focus;
}
void
gtk_box_gadget_set_draw_reverse (GtkBoxGadget *gadget,
gboolean draw_reverse)
{
GtkBoxGadgetPrivate *priv = gtk_box_gadget_get_instance_private (gadget);
priv->draw_reverse = draw_reverse;
}
static GtkCssNode *
get_css_node (GObject *child)
{

View File

@ -58,6 +58,8 @@ void gtk_box_gadget_set_orientation (GtkBoxGadget
GtkOrientation orientation);
void gtk_box_gadget_set_draw_focus (GtkBoxGadget *gadget,
gboolean draw_focus);
void gtk_box_gadget_set_draw_reverse (GtkBoxGadget *gadget,
gboolean draw_reverse);
void gtk_box_gadget_insert_widget (GtkBoxGadget *gadget,
int pos,

View File

@ -1304,6 +1304,7 @@ gtk_notebook_init (GtkNotebook *notebook)
GTK_WIDGET (notebook));
gtk_css_gadget_add_class (priv->gadget, GTK_STYLE_CLASS_FRAME);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->gadget), GTK_ORIENTATION_VERTICAL);
gtk_box_gadget_set_draw_reverse (GTK_BOX_GADGET (priv->gadget), TRUE);
priv->stack_gadget = gtk_css_custom_gadget_new ("stack",
GTK_WIDGET (notebook),
@ -6995,6 +6996,7 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
case GTK_POS_TOP:
if (priv->show_tabs)
gtk_box_gadget_insert_gadget (GTK_BOX_GADGET (priv->gadget), 0, priv->header_gadget, FALSE, FALSE, GTK_ALIGN_FILL);
gtk_box_gadget_set_draw_reverse (GTK_BOX_GADGET (priv->gadget), TRUE);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->gadget), GTK_ORIENTATION_VERTICAL);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->header_gadget), GTK_ORIENTATION_HORIZONTAL);
break;
@ -7002,6 +7004,7 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
case GTK_POS_BOTTOM:
if (priv->show_tabs)
gtk_box_gadget_insert_gadget (GTK_BOX_GADGET (priv->gadget), 1, priv->header_gadget, FALSE, FALSE, GTK_ALIGN_FILL);
gtk_box_gadget_set_draw_reverse (GTK_BOX_GADGET (priv->gadget), FALSE);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->gadget), GTK_ORIENTATION_VERTICAL);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->header_gadget), GTK_ORIENTATION_HORIZONTAL);
break;
@ -7009,6 +7012,7 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
case GTK_POS_LEFT:
if (priv->show_tabs)
gtk_box_gadget_insert_gadget (GTK_BOX_GADGET (priv->gadget), 0, priv->header_gadget, FALSE, FALSE, GTK_ALIGN_FILL);
gtk_box_gadget_set_draw_reverse (GTK_BOX_GADGET (priv->gadget), TRUE);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->gadget), GTK_ORIENTATION_HORIZONTAL);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->header_gadget), GTK_ORIENTATION_VERTICAL);
break;
@ -7016,6 +7020,7 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
case GTK_POS_RIGHT:
if (priv->show_tabs)
gtk_box_gadget_insert_gadget (GTK_BOX_GADGET (priv->gadget), 1, priv->header_gadget, FALSE, FALSE, GTK_ALIGN_FILL);
gtk_box_gadget_set_draw_reverse (GTK_BOX_GADGET (priv->gadget), FALSE);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->gadget), GTK_ORIENTATION_HORIZONTAL);
gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->header_gadget), GTK_ORIENTATION_VERTICAL);
break;