Commit 8f0ae8e8 authored by Matthias Clasen's avatar Matthias Clasen

Add GtkGrid

GtkGrid is a container similar to GtkTable, without legacy
properties and unnecessary restrictions.
It does height-for-width geometry management.
parent c1012715
......@@ -203,6 +203,7 @@
<chapter id="LayoutContainers">
<title>Layout Containers</title>
<xi:include href="xml/gtkgrid.xml" />
<xi:include href="xml/gtkalignment.xml" />
<xi:include href="xml/gtkaspectframe.xml" />
<xi:include href="xml/gtkbox.xml" />
......
......@@ -6350,3 +6350,34 @@ GTK_APPLICATION_GET_CLASS
gtk_application_get_type
GtkApplicationPrivate
</SECTION>
<SECTION>
<FILE>gtkgrid</FILE>
<TITLE>GtkGrid</TITLE>
GtkGrid
gtk_grid_new
gtk_grid_attach
gtk_grid_attach_next_to
gtk_grid_set_row_homogeneous
gtk_grid_get_row_homogeneous
gtk_grid_set_row_spacing
gtk_grid_get_row_spacing
gtk_grid_set_column_homogeneous
gtk_grid_get_column_homogeneous
gtk_grid_set_column_spacing
gtk_grid_get_column_spacing
<SUBSECTION Standard>
GtkGrid
GtkGridClass
GTK_TYPE_GRID
GTK_GRID
GTK_GRID_CLASS
GTK_IS_GRID
GTK_IS_GRID_CLASS
GTK_GRID_GET_CLASS
<SUBSECTION Private>
GtkGridPrivate
gtk_grid_get_type
</SECTION>
......@@ -61,6 +61,7 @@ gtk_font_button_get_type
gtk_font_selection_dialog_get_type
gtk_font_selection_get_type
gtk_frame_get_type
gtk_grid_get_type
gtk_handle_box_get_type
gtk_hbox_get_type
gtk_hbutton_box_get_type
......
......@@ -209,6 +209,7 @@ gtk_public_h_sources = \
gtkfontbutton.h \
gtkfontsel.h \
gtkframe.h \
gtkgrid.h \
gtkhandlebox.h \
gtkhbbox.h \
gtkhbox.h \
......@@ -472,6 +473,7 @@ gtk_base_c_sources = \
gtkfontbutton.c \
gtkfontsel.c \
gtkframe.c \
gtkgrid.c \
gtkhandlebox.c \
gtkhbbox.c \
gtkhbox.c \
......
......@@ -93,6 +93,7 @@
#include <gtk/gtkfontbutton.h>
#include <gtk/gtkfontsel.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkgrid.h>
#include <gtk/gtkhandlebox.h>
#include <gtk/gtkhbbox.h>
#include <gtk/gtkhbox.h>
......
......@@ -4528,3 +4528,20 @@ gtk_info_bar_set_message_type
gtk_info_bar_get_message_type
#endif
#endif
#if IN_HEADER(__GTK_GRID_H__)
#if IN_FILE(__GTK_GRID_c__)
gtk_grid_get_type G_GNUC_CONST
gtk_grid_new
gtk_grid_attach
gtk_grid_attach_next_to
gtk_grid_set_row_homogeneous
gtk_grid_get_row_homogeneous
gtk_grid_set_row_spacing
gtk_grid_get_row_spacing
gtk_grid_set_column_homogeneous
gtk_grid_get_column_homogeneous
gtk_grid_set_column_spacing
gtk_grid_get_column_spacing
#endif
#endif
This diff is collapsed.
/* GTK - The GIMP Toolkit
* Copyright (C) 2010 Red Hat, Inc.
* Author: Matthias Clasen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_GRID_H__
#define __GTK_GRID_H__
#include <gtk/gtkcontainer.h>
G_BEGIN_DECLS
#define GTK_TYPE_GRID (gtk_grid_get_type ())
#define GTK_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_GRID, GtkGrid))
#define GTK_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_GRID, GtkGridClass))
#define GTK_IS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_GRID))
#define GTK_IS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_GRID))
#define GTK_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_GRID, GtkGridClass))
typedef struct _GtkGrid GtkGrid;
typedef struct _GtkGridPrivate GtkGridPrivate;
typedef struct _GtkGridClass GtkGridClass;
struct _GtkGrid
{
/* <private> */
GtkContainer container;
GtkGridPrivate *priv;
};
struct _GtkGridClass
{
GtkContainerClass parent_class;
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
void (*_gtk_reserved5) (void);
void (*_gtk_reserved6) (void);
void (*_gtk_reserved7) (void);
void (*_gtk_reserved8) (void);
};
GType gtk_grid_get_type (void) G_GNUC_CONST;
GtkWidget* gtk_grid_new (void);
void gtk_grid_attach (GtkGrid *grid,
GtkWidget *child,
gint left,
gint top,
gint width,
gint height);
void gtk_grid_attach_next_to (GtkGrid *grid,
GtkWidget *widget,
GtkWidget *sibling,
GtkPositionType side,
gint width,
gint height);
void gtk_grid_set_row_homogeneous (GtkGrid *grid,
gboolean homogeneous);
gboolean gtk_grid_get_row_homogeneous (GtkGrid *grid);
void gtk_grid_set_row_spacing (GtkGrid *grid,
guint spacing);
guint gtk_grid_get_row_spacing (GtkGrid *grid);
void gtk_grid_set_column_homogeneous (GtkGrid *grid,
gboolean homogeneous);
gboolean gtk_grid_get_column_homogeneous (GtkGrid *grid);
void gtk_grid_set_column_spacing (GtkGrid *grid,
guint spacing);
guint gtk_grid_get_column_spacing (GtkGrid *grid);
G_END_DECLS
#endif /* __GTK_GRID_H__ */
......@@ -48,6 +48,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testfilechooserbutton \
testframe \
testgeometry \
testgrid \
testgtk \
testheightforwidth \
testiconview \
......@@ -137,6 +138,7 @@ testfilechooser_DEPENDENCIES = $(TEST_DEPS)
testfilechooserbutton_DEPENDENCIES = $(TEST_DEPS)
testframe_DEPENDENCIES = $(TEST_DEPS)
testgeometry_DEPENDENCIES = $(TEST_DEPS)
testgrid_DEPENDENCIES = $(TEST_DEPS)
testgtk_DEPENDENCIES = $(TEST_DEPS)
testinput_DEPENDENCIES = $(TEST_DEPS)
testimage_DEPENDENCIES = $(TEST_DEPS)
......@@ -202,6 +204,7 @@ testfilechooser_LDADD = $(LDADDS)
testfilechooserbutton_LDADD = $(LDADDS)
testframe_LDADD = $(LDADDS)
testgeometry_LDADD = $(LDADDS)
testgrid_LDADD = $(LDADDS)
testgtk_LDADD = $(LDADDS)
testheightforwidth_LDADD = $(LDADDS)
testicontheme_LDADD = $(LDADDS)
......@@ -266,6 +269,9 @@ testfilechooserbutton_SOURCES = \
prop-editor.c \
testfilechooserbutton.c
testgrid_SOURCES = \
testgrid.c
testgtk_SOURCES = \
prop-editor.c \
testgtk.c
......
#include <gtk/gtk.h>
static GtkWidget *
oriented_test_widget (const gchar *label, const gchar *color, gdouble angle)
{
GtkWidget *box;
GtkWidget *widget;
GdkColor c;
widget = gtk_label_new (label);
gtk_label_set_angle (GTK_LABEL (widget), angle);
box = gtk_event_box_new ();
gdk_color_parse (color, &c);
gtk_widget_modify_bg (box, GTK_STATE_NORMAL, &c);
gtk_container_add (GTK_CONTAINER (box), widget);
return box;
}
static GtkWidget *
test_widget (const gchar *label, const gchar *color)
{
return oriented_test_widget (label, color, 0.0);
}
static GtkOrientation o;
static gboolean
toggle_orientation (GtkWidget *window, GdkEventButton *event, GtkGrid *grid)
{
o = 1 - o;
gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), o);
return FALSE;
}
static void
simple_grid (void)
{
GtkWidget *window;
GtkWidget *grid;
GtkWidget *child;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Orientation");
grid = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), grid);
g_signal_connect (window, "button-press-event", G_CALLBACK (toggle_orientation), grid);
gtk_grid_set_column_spacing (GTK_GRID (grid), 5);
gtk_grid_set_row_spacing (GTK_GRID (grid), 5);
gtk_container_add (GTK_CONTAINER (grid), test_widget ("1", "red"));
gtk_container_add (GTK_CONTAINER (grid), test_widget ("2", "green"));
gtk_container_add (GTK_CONTAINER (grid), test_widget ("3", "blue"));
child = test_widget ("4", "green");
gtk_grid_attach (GTK_GRID (grid), child, 0, 1, 1, 1);
gtk_widget_set_vexpand (child, TRUE);
gtk_grid_attach_next_to (GTK_GRID (grid), test_widget ("5", "blue"), child, GTK_POS_RIGHT, 2, 1);
child = test_widget ("6", "yellow");
gtk_grid_attach (GTK_GRID (grid), child, -1, 0, 1, 2);
gtk_widget_set_hexpand (child, TRUE);
gtk_widget_show_all (window);
}
static void
text_grid (void)
{
GtkWidget *window;
GtkWidget *grid;
GtkWidget *paned1;
GtkWidget *box;
GtkWidget *label;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Height-for-Width");
paned1 = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (window), paned1);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
gtk_paned_pack1 (GTK_PANED (paned1), box, TRUE, FALSE);
gtk_paned_pack2 (GTK_PANED (paned1), gtk_label_new ("Space"), TRUE, FALSE);
grid = gtk_grid_new ();
gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Above"));
gtk_container_add (GTK_CONTAINER (box), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
gtk_container_add (GTK_CONTAINER (box), grid);
gtk_container_add (GTK_CONTAINER (box), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Below"));
label = gtk_label_new ("Some text that may wrap if it has to");
gtk_label_set_width_chars (GTK_LABEL (label), 10);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), test_widget ("1", "red"), 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), test_widget ("2", "blue"), 0, 1, 1, 1);
label = gtk_label_new ("Some text that may wrap if it has to");
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_label_set_width_chars (GTK_LABEL (label), 10);
gtk_grid_attach (GTK_GRID (grid), label, 1, 1, 1, 1);
gtk_widget_show_all (window);
}
static void
box_comparison (void)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *box;
GtkWidget *label;
GtkWidget *grid;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Grid vs. Box");
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 5);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_container_add (GTK_CONTAINER (vbox), gtk_label_new ("Above"));
gtk_container_add (GTK_CONTAINER (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
gtk_container_add (GTK_CONTAINER (vbox), box);
gtk_box_pack_start (GTK_BOX (box), test_widget ("1", "white"), FALSE, FALSE, 0);
label = gtk_label_new ("Some ellipsizing text");
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_label_set_width_chars (GTK_LABEL (label), 10);
gtk_box_pack_start (GTK_BOX (box), label, TRUE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), test_widget ("2", "green"), FALSE, FALSE, 0);
label = gtk_label_new ("Some text that may wrap if needed");
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_width_chars (GTK_LABEL (label), 10);
gtk_box_pack_start (GTK_BOX (box), label, TRUE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), test_widget ("3", "red"), FALSE, FALSE, 0);
grid = gtk_grid_new ();
gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
gtk_container_add (GTK_CONTAINER (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
gtk_container_add (GTK_CONTAINER (vbox), grid);
gtk_grid_attach (GTK_GRID (grid), test_widget ("1", "white"), 0, 0, 1, 1);
label = gtk_label_new ("Some ellipsizing text");
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_label_set_width_chars (GTK_LABEL (label), 10);
gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
gtk_widget_set_hexpand (label, TRUE);
gtk_grid_attach (GTK_GRID (grid), test_widget ("2", "green"), 2, 0, 1, 1);
label = gtk_label_new ("Some text that may wrap if needed");
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_width_chars (GTK_LABEL (label), 10);
gtk_grid_attach (GTK_GRID (grid), label, 3, 0, 1, 1);
gtk_widget_set_hexpand (label, TRUE);
gtk_grid_attach (GTK_GRID (grid), test_widget ("3", "red"), 4, 0, 1, 1);
gtk_container_add (GTK_CONTAINER (vbox), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
gtk_container_add (GTK_CONTAINER (vbox), gtk_label_new ("Below"));
gtk_widget_show_all (window);
}
static void
empty_line (void)
{
GtkWidget *window;
GtkWidget *grid;
GtkWidget *child;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Empty row");
grid = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), grid);
gtk_grid_set_row_spacing (GTK_GRID (grid), 10);
gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
child = test_widget ("(0, 0)", "red");
gtk_grid_attach (GTK_GRID (grid), child, 0, 0, 1, 1);
gtk_widget_set_hexpand (child, TRUE);
gtk_widget_set_vexpand (child, TRUE);
gtk_grid_attach (GTK_GRID (grid), test_widget ("(0, 1)", "blue"), 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), test_widget ("(10, 0)", "green"), 10, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), test_widget ("(10, 1)", "magenta"), 10, 1, 1, 1);
gtk_widget_show_all (window);
}
static void
scrolling (void)
{
GtkWidget *window;
GtkWidget *sw;
GtkWidget *viewport;
GtkWidget *grid;
GtkWidget *child;
gint i;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Scrolling");
sw = gtk_scrolled_window_new (NULL, NULL);
viewport = gtk_viewport_new (NULL, NULL);
grid = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), sw);
gtk_container_add (GTK_CONTAINER (sw), viewport);
gtk_container_add (GTK_CONTAINER (viewport), grid);
child = oriented_test_widget ("#800080", "#800080", -45.0);
gtk_grid_attach (GTK_GRID (grid), child, 0, 0, 1, 1);
gtk_widget_set_hexpand (child, TRUE);
gtk_widget_set_vexpand (child, TRUE);
for (i = 1; i < 16; i++)
{
gchar *color;
color = g_strdup_printf ("#%02x00%02x", 128 + 8*i, 128 - 8*i);
child = test_widget (color, color);
gtk_grid_attach (GTK_GRID (grid), child, 0, i, i + 1, 1);
gtk_widget_set_hexpand (child, TRUE);
g_free (color);
}
for (i = 1; i < 16; i++)
{
gchar *color;
color = g_strdup_printf ("#%02x00%02x", 128 - 8*i, 128 + 8*i);
child = oriented_test_widget (color, color, -90.0);
gtk_grid_attach (GTK_GRID (grid), child, i, 0, 1, i);
gtk_widget_set_vexpand (child, TRUE);
g_free (color);
}
gtk_widget_show_all (window);
}
int
main (int argc, char *argv[])
{
gtk_init (NULL, NULL);
simple_grid ();
text_grid ();
box_comparison ();
empty_line ();
scrolling ();
gtk_main ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment