diff options
author | Matthias Clasen <mclasen@redhat.com> | 2013-03-23 15:40:44 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2013-03-23 15:43:37 -0400 |
commit | cc86a7bb7e0dc90366a1cfb58b769e0528665b3c (patch) | |
tree | 4a922a4b6fc6767f9400292da9ff8f54d6a38260 | |
parent | 666d10ec7676a15b6861b785397563cbd4ef21e6 (diff) | |
download | gtk+-cc86a7bb7e0dc90366a1cfb58b769e0528665b3c.tar.gz |
Add gtk_grid_remove_{row,column}
It is sometimes convenient to deal with entire rows or
columns at a time.
https://bugzilla.gnome.org/show_bug.cgi?id=695994
-rw-r--r-- | docs/reference/gtk/gtk3-sections.txt | 2 | ||||
-rw-r--r-- | gtk/gtk.symbols | 2 | ||||
-rw-r--r-- | gtk/gtkgrid.c | 102 | ||||
-rw-r--r-- | gtk/gtkgrid.h | 6 |
4 files changed, 112 insertions, 0 deletions
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index e39da7f194..6f3c4fd113 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -7238,6 +7238,8 @@ gtk_grid_attach_next_to gtk_grid_get_child_at gtk_grid_insert_row gtk_grid_insert_column +gtk_grid_remove_row +gtk_grid_remove_column gtk_grid_insert_next_to gtk_grid_set_row_homogeneous gtk_grid_get_row_homogeneous diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 417bd2c248..96811a5ff4 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -1205,6 +1205,8 @@ gtk_grid_insert_column gtk_grid_insert_next_to gtk_grid_insert_row gtk_grid_new +gtk_grid_remove_column +gtk_grid_remove_row gtk_grid_set_column_homogeneous gtk_grid_set_column_spacing gtk_grid_set_row_homogeneous diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c index e1df436e80..d392fb1228 100644 --- a/gtk/gtkgrid.c +++ b/gtk/gtkgrid.c @@ -1685,6 +1685,57 @@ gtk_grid_insert_row (GtkGrid *grid, } /** + * gtk_grid_remove_row: + * @grid: a #GtkGrid + * @position: the position of the row to remove + * + * Removes a row from the grid. + * + * Children that are placed in this row are removed, + * spanning children that overlap this row have their + * height reduced by one, and children below the row + * are moved up. + * + * Since: 3.10 + */ +void +gtk_grid_remove_row (GtkGrid *grid, + gint position) +{ + GtkGridPrivate *priv; + GtkGridChild *child; + GList *list; + gint top, height; + + g_return_if_fail (GTK_IS_GRID (grid)); + + priv = grid->priv; + + list = priv->children; + while (list) + { + child = list->data; + list = list->next; + + top = CHILD_TOP (child); + height = CHILD_HEIGHT (child); + + if (top <= position && top + height > position) + height--; + if (top > position) + top--; + + if (height <= 0) + gtk_container_remove (GTK_CONTAINER (grid), child->widget); + else + gtk_container_child_set (GTK_CONTAINER (grid), child->widget, + "height", height, + "top-attach", top, + NULL); + } +} + +/** * gtk_grid_insert_column: * @grid: a #GtkGrid * @position: the position to insert the column at @@ -1731,6 +1782,57 @@ gtk_grid_insert_column (GtkGrid *grid, } /** + * gtk_grid_remove_column: + * @grid: a #GtkGrid + * @position: the position of the column to remove + * + * Removes a column from the grid. + * + * Children that are placed in this column are removed, + * spanning children that overlap this column have their + * width reduced by one, and children after the column + * are moved to the left. + * + * Since: 3.10 + */ +void +gtk_grid_remove_column (GtkGrid *grid, + gint position) +{ + GtkGridPrivate *priv; + GtkGridChild *child; + GList *list; + gint left, width; + + g_return_if_fail (GTK_IS_GRID (grid)); + + priv = grid->priv; + + list = priv->children; + while (list) + { + child = list->data; + list = list->next; + + left = CHILD_LEFT (child); + width = CHILD_WIDTH (child); + + if (left <= position && left + width > position) + width--; + if (left > position) + left--; + + if (width <= 0) + gtk_container_remove (GTK_CONTAINER (grid), child->widget); + else + gtk_container_child_set (GTK_CONTAINER (grid), child->widget, + "width", width, + "left-attach", left, + NULL); + } +} + +/** * gtk_grid_insert_next_to: * @grid: a #GtkGrid * @sibling: the child of @grid that the new row or column will be diff --git a/gtk/gtkgrid.h b/gtk/gtkgrid.h index 0e37277ad7..f2d550fe50 100644 --- a/gtk/gtkgrid.h +++ b/gtk/gtkgrid.h @@ -87,6 +87,12 @@ void gtk_grid_insert_row (GtkGrid *grid, GDK_AVAILABLE_IN_3_2 void gtk_grid_insert_column (GtkGrid *grid, gint position); +GDK_AVAILABLE_IN_3_10 +void gtk_grid_remove_row (GtkGrid *grid, + gint position); +GDK_AVAILABLE_IN_3_10 +void gtk_grid_remove_column (GtkGrid *grid, + gint position); GDK_AVAILABLE_IN_3_2 void gtk_grid_insert_next_to (GtkGrid *grid, GtkWidget *sibling, |