[gtk/modern-doc-shooter: 1/8] docs: Redo the doc shooter code
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/modern-doc-shooter: 1/8] docs: Redo the doc shooter code
- Date: Tue, 4 Aug 2020 04:40:30 +0000 (UTC)
commit 1e3df88ee03756a13542f29ac70401acbc948678
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Aug 3 21:09:54 2020 -0400
docs: Redo the doc shooter code
Steal snapshotting code from the reftests to
make this work again.
Other changes here: catch up with container removal.
docs/tools/meson.build | 2 +-
docs/tools/shadow.c | 7 +-
docs/tools/shadow.h | 2 +-
docs/tools/shooter.c | 327 ++++++++++++++-----------------------------------
docs/tools/widgets.c | 249 +++++++++++++++++++++----------------
5 files changed, 241 insertions(+), 346 deletions(-)
---
diff --git a/docs/tools/meson.build b/docs/tools/meson.build
index a7ec75b447..ead3357af0 100644
--- a/docs/tools/meson.build
+++ b/docs/tools/meson.build
@@ -1,7 +1,7 @@
if x11_enabled and get_option('gtk_doc')
doc_shooter_sources = [
- 'shadow.c',
'shooter.c',
+ 'shadow.c',
'widgets.c',
'../../tests/gtkgears.c',
]
diff --git a/docs/tools/shadow.c b/docs/tools/shadow.c
index 67c31fe709..20dfdbca13 100644
--- a/docs/tools/shadow.c
+++ b/docs/tools/shadow.c
@@ -128,12 +128,12 @@ create_shadow (GdkPixbuf *src)
}
}
-
+
return dest;
}
GdkPixbuf *
-create_shadowed_pixbuf (GdkPixbuf *src)
+add_shadow (GdkPixbuf *src)
{
GdkPixbuf *dest;
@@ -145,5 +145,8 @@ create_shadowed_pixbuf (GdkPixbuf *src)
gdk_pixbuf_get_height (src),
BLUR_RADIUS, BLUR_RADIUS, 1.0, 1.0,
GDK_INTERP_NEAREST, 255);
+
+ g_object_unref (src);
+
return dest;
}
diff --git a/docs/tools/shadow.h b/docs/tools/shadow.h
index 2f569cc349..cb87c504b7 100644
--- a/docs/tools/shadow.h
+++ b/docs/tools/shadow.h
@@ -3,6 +3,6 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
-GdkPixbuf *create_shadowed_pixbuf (GdkPixbuf *src);
+GdkPixbuf *add_shadow (GdkPixbuf *src);
#endif /* __SHADOW_H__ */
diff --git a/docs/tools/shooter.c b/docs/tools/shooter.c
index 09dea4a26b..b112fbb385 100644
--- a/docs/tools/shooter.c
+++ b/docs/tools/shooter.c
@@ -21,290 +21,141 @@
#include "widgets.h"
#include "shadow.h"
-#define MAXIMUM_WM_REPARENTING_DEPTH 4
-#ifndef _
-#define _(x) (x)
-#endif
-
-static void queue_show (void);
-
-static Window
-find_toplevel_window (Window xid)
-{
- Window root, parent, *children;
- guint nchildren;
-
- do
- {
- if (XQueryTree (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xid, &root,
- &parent, &children, &nchildren) == 0)
- {
- g_warning ("Couldn't find window manager window");
- return 0;
- }
-
- if (root == parent)
- return xid;
-
- xid = parent;
- }
- while (TRUE);
-}
-
static GdkPixbuf *
-add_border_to_shot (GdkPixbuf *pixbuf)
+add_border (GdkPixbuf *pixbuf)
{
GdkPixbuf *retval;
- GdkColorspace colorspace;
- int bits;
- colorspace = gdk_pixbuf_get_colorspace (pixbuf);
- bits = gdk_pixbuf_get_bits_per_sample (pixbuf);
- retval = gdk_pixbuf_new (colorspace, TRUE, bits,
- gdk_pixbuf_get_width (pixbuf) + 2,
- gdk_pixbuf_get_height (pixbuf) + 2);
+ retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
+ gdk_pixbuf_get_width (pixbuf) + 2,
+ gdk_pixbuf_get_height (pixbuf) + 2);
/* Fill with solid black */
gdk_pixbuf_fill (retval, 0xFF);
gdk_pixbuf_copy_area (pixbuf,
- 0, 0,
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- retval, 1, 1);
+ 0, 0,
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ retval, 1, 1);
+
+ g_object_unref (pixbuf);
return retval;
}
-static GdkPixbuf *
-remove_shaped_area (GdkPixbuf *pixbuf,
- Window window)
+static GMainLoop *loop;
+
+static gboolean
+quit_when_idle (gpointer loop)
{
- GdkPixbuf *retval;
- XRectangle *rectangles;
- int rectangle_count, rectangle_order;
- int i;
- GdkColorspace colorspace;
- int bits;
-
- colorspace = gdk_pixbuf_get_colorspace (pixbuf);
- bits = gdk_pixbuf_get_bits_per_sample (pixbuf);
- retval = gdk_pixbuf_new (colorspace, TRUE, bits,
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf));
-
- gdk_pixbuf_fill (retval, 0);
- rectangles = XShapeGetRectangles (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), window,
- ShapeBounding, &rectangle_count, &rectangle_order);
-
- for (i = 0; i < rectangle_count; i++)
- {
- int y, x;
-
- for (y = rectangles[i].y; y < rectangles[i].y + rectangles[i].height; y++)
- {
- guchar *src_pixels, *dest_pixels;
-
- src_pixels = gdk_pixbuf_get_pixels (pixbuf) +
- y * gdk_pixbuf_get_rowstride (pixbuf) +
- rectangles[i].x * (gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3);
- dest_pixels = gdk_pixbuf_get_pixels (retval) +
- y * gdk_pixbuf_get_rowstride (retval) +
- rectangles[i].x * 4;
-
- for (x = rectangles[i].x; x < rectangles[i].x + rectangles[i].width; x++)
- {
- *dest_pixels++ = *src_pixels ++;
- *dest_pixels++ = *src_pixels ++;
- *dest_pixels++ = *src_pixels ++;
- *dest_pixels++ = 255;
-
- if (gdk_pixbuf_get_has_alpha (pixbuf))
- src_pixels++;
- }
- }
- }
+ g_main_loop_quit (loop);
- return retval;
+ return G_SOURCE_REMOVE;
}
-typedef enum {
- DECOR_NONE,
- DECOR_FRAME,
- DECOR_WINDOW_FRAME
-} DecorationType;
-
-static GdkPixbuf *
-take_window_shot (Window child,
- DecorationType decor)
+static void
+draw_paintable (GdkPaintable *paintable,
+ gpointer out_surface)
{
+ GtkSnapshot *snapshot;
+ GskRenderNode *node;
cairo_surface_t *surface;
- XWindowAttributes attrs;
- Window xid;
- Display *dpy;
- int x = 0, y = 0;
- int width, height;
+ cairo_t *cr;
+
+ snapshot = gtk_snapshot_new ();
+ gdk_paintable_snapshot (paintable,
+ snapshot,
+ gdk_paintable_get_intrinsic_width (paintable),
+ gdk_paintable_get_intrinsic_height (paintable));
+ node = gtk_snapshot_free_to_node (snapshot);
+
+ /* If the window literally draws nothing, we assume it hasn't been mapped yet and as such
+ * the invalidations were only side effects of resizes.
+ */
+ if (node == NULL)
+ return;
- GdkPixbuf *tmp, *tmp2;
- GdkPixbuf *retval = NULL;
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ gdk_paintable_get_intrinsic_width (paintable),
+ gdk_paintable_get_intrinsic_height (paintable));
- if (decor == DECOR_WINDOW_FRAME)
- xid = find_toplevel_window (child);
- else
- xid = child;
+ cr = cairo_create (surface);
+ gsk_render_node_draw (node, cr);
+ cairo_destroy (cr);
+ gsk_render_node_unref (node);
- dpy = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
- XGetWindowAttributes (dpy, xid, &attrs);
+ g_signal_handlers_disconnect_by_func (paintable, draw_paintable, out_surface);
- width = attrs.width;
- height = attrs.height;
+ *(cairo_surface_t **) out_surface = surface;
- if (attrs.x < 0)
- {
- x = - attrs.x;
- width = width + attrs.x;
- }
+ g_idle_add (quit_when_idle, loop);
+}
- if (attrs.y < 0)
- {
- y = - attrs.y;
- height = height + attrs.y;
- }
+static cairo_surface_t *
+snapshot_widget (GtkWidget *widget)
+{
+ GdkPaintable *paintable;
+ cairo_surface_t *surface;
- if (attrs.x + x + width > WidthOfScreen (DefaultScreenOfDisplay (dpy)))
- width = WidthOfScreen (DefaultScreenOfDisplay (dpy)) - attrs.x - x;
+ g_assert (gtk_widget_get_realized (widget));
- if (attrs.y + y + height > HeightOfScreen (DefaultScreenOfDisplay (dpy)))
- height = HeightOfScreen (DefaultScreenOfDisplay (dpy)) - attrs.y - y;
+ loop = g_main_loop_new (NULL, FALSE);
- surface = cairo_xlib_surface_create (dpy,
- xid,
- attrs.visual,
- attrs.width,
- attrs.height);
- tmp = gdk_pixbuf_get_from_surface (surface,
- x, y,
- width, height);
- cairo_surface_destroy (surface);
+ /* We wait until the widget is drawn for the first time.
+ *
+ * We also use an inhibit mechanism, to give module functions a chance
+ * to delay the snapshot.
+ */
+ paintable = gtk_widget_paintable_new (widget);
+ g_signal_connect (paintable, "invalidate-contents", G_CALLBACK (draw_paintable), &surface);
+ g_main_loop_run (loop);
- if (tmp != NULL)
- {
- if (decor == DECOR_WINDOW_FRAME)
- tmp2 = remove_shaped_area (tmp, xid);
- else if (decor == DECOR_FRAME)
- tmp2 = add_border_to_shot (tmp);
- else
- tmp2 = g_object_ref (tmp);
-
- g_object_unref (tmp);
-
- if (tmp2 != NULL)
- {
- retval = create_shadowed_pixbuf (tmp2);
- g_object_unref (tmp2);
- }
- }
+ g_main_loop_unref (loop);
+ g_object_unref (paintable);
+ gtk_window_destroy (GTK_WINDOW (widget));
- return retval;
+ return surface;
}
-static GList *toplevels;
-static guint shot_id;
-
-static gboolean
-window_is_csd (GdkSurface *window)
+int
+main (int argc, char **argv)
{
- return TRUE;
-}
+ GList *toplevels, *node;
-static gboolean
-shoot_one (WidgetInfo *info)
-{
- GdkSurface *window;
- XID id;
- GdkPixbuf *screenshot = NULL;
- DecorationType decor = DECOR_FRAME;
+ gtk_init ();
- if (g_list_find (toplevels, info) == NULL)
- {
- g_warning ("Widget not found in queue");
- exit (1);
- }
+ toplevels = get_all_widgets ();
- window = gtk_native_get_surface (GTK_NATIVE (info->window));
- id = gdk_x11_surface_get_xid (window);
- if (window_is_csd (window))
- decor = (info->include_decorations) ? DECOR_NONE : DECOR_WINDOW_FRAME;
- screenshot = take_window_shot (id, decor);
- if (screenshot != NULL)
+ for (node = toplevels; node; node = node->next)
{
+ WidgetInfo *info;
char *filename;
- filename = g_strdup_printf ("./%s.png", info->name);
- gdk_pixbuf_save (screenshot, filename, "png", NULL, NULL);
- g_free (filename);
- g_object_unref (screenshot);
- }
- else
- {
- g_warning ("unable to save shot of %s", info->name);
- }
- gtk_window_destroy (GTK_WINDOW (info->window));
-
- shot_id = 0;
-
- /* remove from the queue and try to load up another */
- toplevels = g_list_remove (toplevels, info);
- if (toplevels == NULL)
- exit (0);
- else
- queue_show ();
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-on_show (WidgetInfo *info)
-{
- if (shot_id != 0)
- return;
+ cairo_surface_t *surface;
+ GdkPixbuf *pixbuf;
- shot_id = g_timeout_add (500, (GSourceFunc) shoot_one, info);
-}
+ info = node->data;
-static gboolean
-show_one (void)
-{
- WidgetInfo *info = toplevels->data;
+ gtk_widget_show (info->window);
- g_message ("shooting %s", info->name);
+ surface = snapshot_widget (info->window);
- g_signal_connect_swapped (info->window,
- "show",
- G_CALLBACK (on_show),
- info);
+ pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ cairo_image_surface_get_width (surface),
+ cairo_image_surface_get_height (surface));
- gtk_widget_show (info->window);
+ if (!info->include_decorations)
+ pixbuf = add_border (pixbuf);
- return G_SOURCE_REMOVE;
-}
+ pixbuf = add_shadow (pixbuf);
-static void
-queue_show (void)
-{
- g_idle_add ((GSourceFunc) show_one, NULL);
-}
-
-int main (int argc, char **argv)
-{
- /* If there's no DISPLAY, we silently error out. We don't want to break
- * headless builds. */
- if (! gtk_init_check ())
- return 0;
+ filename = g_strdup_printf ("./%s.png", info->name);
- toplevels = get_all_widgets ();
+ gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL);
+ g_free (filename);
- queue_show ();
- while (TRUE)
- g_main_context_iteration (NULL, TRUE);
+ g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
+ }
return 0;
}
diff --git a/docs/tools/widgets.c b/docs/tools/widgets.c
index 93aeb2ab52..078b90954b 100644
--- a/docs/tools/widgets.c
+++ b/docs/tools/widgets.c
@@ -17,12 +17,6 @@
#define LARGE_WIDTH 240
#define LARGE_HEIGHT 240
-static gboolean
-focus_handled (void)
-{
- return TRUE;
-}
-
static WidgetInfo *
new_widget_info (const char *name,
GtkWidget *widget,
@@ -42,27 +36,22 @@ new_widget_info (const char *name,
else
{
info->window = gtk_window_new ();
+ gtk_window_set_decorated (GTK_WINDOW (info->window), FALSE);
info->include_decorations = FALSE;
- gtk_widget_show (widget);
- gtk_box_append (GTK_BOX (info->window), widget);
+ gtk_window_set_child (GTK_WINDOW (info->window), widget);
}
info->no_focus = TRUE;
- g_signal_connect (info->window, "focus", G_CALLBACK (focus_handled), NULL);
-
switch (size)
{
case SMALL:
- gtk_widget_set_size_request (info->window,
- 240, 75);
+ gtk_widget_set_size_request (info->window, 240, 75);
break;
case MEDIUM:
- gtk_widget_set_size_request (info->window,
- 240, 165);
+ gtk_widget_set_size_request (info->window, 240, 165);
break;
case LARGE:
- gtk_widget_set_size_request (info->window,
- 240, 240);
+ gtk_widget_set_size_request (info->window, 240, 240);
break;
default:
break;
@@ -71,6 +60,15 @@ new_widget_info (const char *name,
return info;
}
+static void
+add_margin (GtkWidget *widget)
+{
+ gtk_widget_set_margin_start (widget, 10);
+ gtk_widget_set_margin_end (widget, 10);
+ gtk_widget_set_margin_top (widget, 10);
+ gtk_widget_set_margin_bottom (widget, 10);
+}
+
static WidgetInfo *
create_button (void)
{
@@ -79,6 +77,7 @@ create_button (void)
widget = gtk_button_new_with_mnemonic ("_Button");
gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
+ add_margin (widget);
return new_widget_info ("button", widget, SMALL);
}
@@ -144,14 +143,11 @@ static WidgetInfo *
create_menu_button (void)
{
GtkWidget *widget;
- GtkWidget *image;
GtkWidget *menu;
GtkWidget *vbox;
widget = gtk_menu_button_new ();
- image = gtk_image_new ();
- gtk_image_set_from_icon_name (GTK_IMAGE (image), "emblem-system-symbolic");
- gtk_box_append (GTK_BOX (widget), image);
+ gtk_menu_button_set_icon_name (GTK_MENU_BUTTON (widget), "emblem-system-symbolic");
menu = gtk_popover_new ();
gtk_menu_button_set_popover (GTK_MENU_BUTTON (widget), menu);
@@ -162,6 +158,8 @@ create_menu_button (void)
gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Menu Button"));
+ add_margin (vbox);
+
return new_widget_info ("menu-button", vbox, SMALL);
}
@@ -210,8 +208,7 @@ create_lockbutton (void)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Lock Button"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Lock Button"));
gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER);
gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);
@@ -229,6 +226,8 @@ create_entry (void)
gtk_editable_set_text (GTK_EDITABLE (widget), "Entry");
gtk_editable_set_position (GTK_EDITABLE (widget), -1);
+ add_margin (widget);
+
return new_widget_info ("entry", widget, SMALL);
}
@@ -240,7 +239,9 @@ create_search_entry (void)
widget = gtk_search_entry_new ();
gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
- gtk_entry_set_placeholder_text (GTK_ENTRY (widget), "Search...");
+ g_object_set (widget, "placeholder-text", "Search…", NULL);
+
+ add_margin (widget);
return new_widget_info ("search-entry", widget, SMALL);
}
@@ -280,19 +281,18 @@ static WidgetInfo *
create_accel_label (void)
{
WidgetInfo *info;
- GtkWidget *widget, *button, *box;
+ GtkWidget *widget, *box;
widget = gtk_accel_label_new ("Accel Label");
-
- button = gtk_button_new_with_label ("Quit");
- gtk_widget_hide (button);
+ gtk_widget_set_size_request (widget, 148, -1);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_box_append (GTK_BOX (box), widget);
- gtk_box_append (GTK_BOX (box), button);
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (widget), GDK_KEY_Q, GDK_CONTROL_MASK);
+ add_margin (box);
+
info = new_widget_info ("accel-label", box, SMALL);
return info;
@@ -369,12 +369,13 @@ create_info_bar (void)
widget = gtk_info_bar_new ();
gtk_info_bar_set_show_close_button (GTK_INFO_BAR (widget), TRUE);
gtk_info_bar_set_message_type (GTK_INFO_BAR (widget), GTK_MESSAGE_INFO);
- gtk_box_append (GTK_BOX (widget),
- gtk_label_new ("Info Bar"));
+ gtk_info_bar_add_child (GTK_INFO_BAR (widget), gtk_label_new ("Info Bar"));
gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
+ add_margin (widget);
+
info = new_widget_info ("info-bar", widget, SMALL);
return info;
@@ -394,8 +395,7 @@ create_search_bar (void)
entry = gtk_search_entry_new ();
gtk_editable_set_text (GTK_EDITABLE (entry), "Search Bar");
- gtk_box_append (GTK_BOX (widget), entry);
- gtk_widget_show (entry);
+ gtk_search_bar_set_child (GTK_SEARCH_BAR (widget), entry);
gtk_search_bar_set_show_close_button (GTK_SEARCH_BAR (widget), TRUE);
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (widget), TRUE);
@@ -421,16 +421,15 @@ create_action_bar (void)
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
view = gtk_text_view_new ();
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
gtk_box_append (GTK_BOX (box), view);
widget = gtk_action_bar_new ();
button = gtk_button_new_from_icon_name ("object-select-symbolic");
- gtk_widget_show (button);
- gtk_box_append (GTK_BOX (widget), button);
+ gtk_action_bar_pack_start (GTK_ACTION_BAR (widget), button);
button = gtk_button_new_from_icon_name ("call-start-symbolic");
- gtk_widget_show (button);
- gtk_box_append (GTK_BOX (widget), button);
+ gtk_action_bar_pack_start (GTK_ACTION_BAR (widget), button);
g_object_set (gtk_widget_get_parent (button),
"margin-start", 6,
"margin-end", 6,
@@ -439,8 +438,6 @@ create_action_bar (void)
"spacing", 6,
NULL);
- gtk_widget_show (widget);
-
gtk_box_append (GTK_BOX (box), widget);
info = new_widget_info ("action-bar", box, SMALL);
@@ -456,11 +453,13 @@ create_text_view (void)
widget = gtk_frame_new (NULL);
text_view = gtk_text_view_new ();
- gtk_box_append (GTK_BOX (widget), text_view);
- /* Bad hack to add some size to the widget */
+ gtk_frame_set_child (GTK_FRAME (widget), text_view);
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)),
- "Multiline\nText\n\n", -1);
+ "Multiline\nText\n\n", -1);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE);
+ gtk_widget_set_size_request (text_view, 100, -1);
+
+ add_margin (widget);
return new_widget_info ("multiline-text", widget, MEDIUM);
}
@@ -498,7 +497,7 @@ create_tree_view (void)
g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, "xalign", 0.5,
NULL),
"text", 2, NULL);
gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
- gtk_box_append (GTK_BOX (widget), tree_view);
+ gtk_frame_set_child (GTK_FRAME (widget), tree_view);
info = new_widget_info ("list-and-tree", widget, MEDIUM);
info->no_focus = FALSE;
@@ -516,6 +515,7 @@ create_icon_view (void)
GtkTreeIter iter;
GdkPixbuf *pixbuf;
WidgetInfo *info;
+ GtkWidget *sw;
widget = gtk_frame_new (NULL);
list_store = gtk_list_store_new (2, G_TYPE_STRING, GDK_TYPE_PIXBUF);
@@ -526,18 +526,27 @@ create_icon_view (void)
pixbuf = gdk_pixbuf_new_from_file ("gnome.png", NULL);
gtk_list_store_set (list_store, &iter, 0, "Two", 1, pixbuf, -1);
- icon_view = gtk_icon_view_new();
+ icon_view = gtk_icon_view_new ();
+
+ gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (icon_view), GTK_ORIENTATION_HORIZONTAL);
+ gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (icon_view), 0);
gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), GTK_TREE_MODEL (list_store));
gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view), 0);
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), 1);
- gtk_box_append (GTK_BOX (widget), icon_view);
+ sw = gtk_scrolled_window_new ();
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), icon_view);
+
+ gtk_frame_set_child (GTK_FRAME (widget), sw);
+
+ gtk_widget_set_size_request (widget, 96, 128);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Icon View"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Icon View"));
+
+ add_margin (vbox);
info = new_widget_info ("icon-view", vbox, MEDIUM);
info->no_focus = FALSE;
@@ -553,15 +562,17 @@ create_color_button (void)
GdkRGBA color;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
- color.red = 0x1e<<8; /* Go Gagne! */
+ color.red = 0x1e<<8;
color.green = 0x90<<8;
color.blue = 0xff<<8;
+ color.alpha = 0xffff;
picker = gtk_color_button_new_with_rgba (&color);
gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), picker);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Color Button"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Color Button"));
+
+ add_margin (vbox);
return new_widget_info ("color-button", vbox, SMALL);
}
@@ -577,8 +588,9 @@ create_font_button (void)
gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), picker);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Font Button"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Font Button"));
+
+ add_margin (vbox);
return new_widget_info ("font-button", vbox, SMALL);
}
@@ -620,10 +632,10 @@ create_file_button (void)
gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox2), picker);
- gtk_box_append (GTK_BOX (vbox2),
- gtk_label_new ("File Button (Select Folder)"));
- gtk_box_append (GTK_BOX (vbox),
- vbox2);
+ gtk_box_append (GTK_BOX (vbox2), gtk_label_new ("File Button (Select Folder)"));
+ gtk_box_append (GTK_BOX (vbox), vbox2);
+
+ add_margin (vbox);
return new_widget_info ("file-button", vbox, MEDIUM);
}
@@ -633,20 +645,25 @@ create_separator (void)
{
GtkWidget *hbox;
GtkWidget *vbox;
+ GtkWidget *widget;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
- gtk_box_append (GTK_BOX (hbox),
- gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
- gtk_box_append (GTK_BOX (hbox),
- gtk_separator_new (GTK_ORIENTATION_VERTICAL));
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
+ widget = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_set_size_request (widget, 100, -1);
+ gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
+ gtk_box_append (GTK_BOX (hbox), widget);
+ widget = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
+ gtk_widget_set_size_request (widget, -1, 100);
+ gtk_box_append (GTK_BOX (hbox), widget);
gtk_box_append (GTK_BOX (vbox), hbox);
- gtk_box_append (GTK_BOX (vbox),
- g_object_new (GTK_TYPE_LABEL,
- "label", "Horizontal and Vertical\nSeparators",
- "justify", GTK_JUSTIFY_CENTER,
- NULL));
+ gtk_box_append (GTK_BOX (vbox), g_object_new (GTK_TYPE_LABEL,
+ "label", "Horizontal and Vertical\nSeparators",
+ "justify", GTK_JUSTIFY_CENTER,
+ NULL));
+ add_margin (vbox);
+
return new_widget_info ("separator", vbox, MEDIUM);
}
@@ -673,6 +690,8 @@ create_panes (void)
gtk_paned_set_resize_end_child (GTK_PANED (pane), FALSE);
gtk_paned_set_shrink_end_child (GTK_PANED (pane), FALSE);
+ gtk_widget_set_size_request (pane, 96, 96);
+
gtk_box_append (GTK_BOX (hbox), pane);
pane = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
@@ -686,14 +705,18 @@ create_panes (void)
gtk_paned_set_resize_end_child (GTK_PANED (pane), FALSE);
gtk_paned_set_shrink_end_child (GTK_PANED (pane), FALSE);
+ gtk_widget_set_size_request (pane, 96, 96);
+
gtk_box_append (GTK_BOX (hbox), pane);
gtk_box_append (GTK_BOX (vbox), hbox);
- gtk_box_append (GTK_BOX (vbox),
- g_object_new (GTK_TYPE_LABEL,
- "label", "Horizontal and Vertical\nPanes",
- "justify", GTK_JUSTIFY_CENTER,
- NULL));
+ gtk_box_append (GTK_BOX (vbox), g_object_new (GTK_TYPE_LABEL,
+ "label", "Horizontal and Vertical\nPanes",
+ "justify", GTK_JUSTIFY_CENTER,
+ NULL));
+
+ add_margin (vbox);
+
return new_widget_info ("panes", vbox, MEDIUM);
}
@@ -703,6 +726,9 @@ create_frame (void)
GtkWidget *widget;
widget = gtk_frame_new ("Frame");
+ gtk_widget_set_size_request (widget, 96, 96);
+
+ add_margin (widget);
return new_widget_info ("frame", widget, MEDIUM);
}
@@ -853,8 +879,9 @@ create_progressbar (void)
gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Progress Bar"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Progress Bar"));
+
+ add_margin (vbox);
return new_widget_info ("progressbar", vbox, SMALL);
}
@@ -870,8 +897,9 @@ create_level_bar (void)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Level Bar"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Level Bar"));
+
+ add_margin (vbox);
return new_widget_info ("levelbar", vbox, SMALL);
}
@@ -884,6 +912,7 @@ create_scrolledwindow (void)
scrolledwin = gtk_scrolled_window_new ();
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+ gtk_scrolled_window_set_overlay_scrolling (GTK_SCROLLED_WINDOW (scrolledwin), FALSE);
label = gtk_label_new ("Scrolled Window");
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolledwin), label);
@@ -904,8 +933,9 @@ create_scrollbar (void)
gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Scrollbar"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Scrollbar"));
+
+ add_margin (vbox);
return new_widget_info ("scrollbar", vbox, SMALL);
}
@@ -922,8 +952,9 @@ create_spinbutton (void)
gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Spin Button"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Spin Button"));
+
+ add_margin (vbox);
return new_widget_info ("spinbutton", vbox, SMALL);
}
@@ -944,6 +975,8 @@ create_statusbar (void)
gtk_box_append (GTK_BOX (vbox), widget);
+ add_margin (vbox);
+
info = new_widget_info ("statusbar", vbox, SMALL);
return info;
@@ -970,6 +1003,8 @@ create_scales (void)
"label", "Horizontal and Vertical\nScales",
"justify", GTK_JUSTIFY_CENTER,
NULL));
+ add_margin (vbox);
+
return new_widget_info ("scales", vbox, MEDIUM);}
static WidgetInfo *
@@ -985,8 +1020,9 @@ create_image (void)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Image"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Image"));
+
+ add_margin (vbox);
return new_widget_info ("image", vbox, SMALL);
}
@@ -1005,8 +1041,9 @@ create_spinner (void)
gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), widget);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Spinner"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Spinner"));
+
+ add_margin (vbox);
return new_widget_info ("spinner", vbox, SMALL);
}
@@ -1022,7 +1059,7 @@ create_volume_button (void)
gtk_widget_set_size_request (widget, 100, 250);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_box_append (GTK_BOX (widget), box);
+ gtk_window_set_child (GTK_WINDOW (widget), box);
button = gtk_volume_button_new ();
gtk_box_append (GTK_BOX (box), button);
@@ -1030,7 +1067,6 @@ create_volume_button (void)
gtk_scale_button_set_value (GTK_SCALE_BUTTON (button), 33);
popup = gtk_scale_button_get_popup (GTK_SCALE_BUTTON (button));
gtk_widget_realize (widget);
- gtk_widget_show (box);
gtk_widget_show (popup);
return new_widget_info ("volumebutton", widget, ASIS);
@@ -1047,14 +1083,12 @@ create_assistant (void)
gtk_window_set_title (GTK_WINDOW (widget), "Assistant");
page1 = gtk_label_new ("Assistant");
- gtk_widget_show (page1);
gtk_widget_set_size_request (page1, 300, 140);
gtk_assistant_prepend_page (GTK_ASSISTANT (widget), page1);
gtk_assistant_set_page_title (GTK_ASSISTANT (widget), page1, "Assistant page");
gtk_assistant_set_page_complete (GTK_ASSISTANT (widget), page1, TRUE);
page2 = gtk_label_new (NULL);
- gtk_widget_show (page2);
gtk_assistant_append_page (GTK_ASSISTANT (widget), page2);
gtk_assistant_set_page_type (GTK_ASSISTANT (widget), page2, GTK_ASSISTANT_PAGE_CONFIRM);
@@ -1075,8 +1109,9 @@ create_appchooserbutton (void)
gtk_widget_set_halign (picker, GTK_ALIGN_CENTER);
gtk_widget_set_valign (picker, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (vbox), picker);
- gtk_box_append (GTK_BOX (vbox),
- gtk_label_new ("Application Button"));
+ gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Application Button"));
+
+ add_margin (vbox);
return new_widget_info ("appchooserbutton", vbox, SMALL);
}
@@ -1134,7 +1169,7 @@ create_headerbar (void)
window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (window), "Header Bar");
view = gtk_text_view_new ();
- gtk_widget_show (view);
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
gtk_widget_set_size_request (window, 220, 150);
gtk_window_set_child (GTK_WINDOW (window), view);
bar = gtk_header_bar_new ();
@@ -1159,10 +1194,8 @@ create_stack (void)
gtk_widget_set_margin_bottom (stack, 10);
gtk_widget_set_size_request (stack, 120, 120);
view = gtk_text_view_new ();
- gtk_widget_show (view);
gtk_stack_add_titled (GTK_STACK (stack), view, "page1", "Page 1");
view = gtk_text_view_new ();
- gtk_widget_show (view);
gtk_stack_add_titled (GTK_STACK (stack), view, "page2", "Page 2");
switcher = gtk_stack_switcher_new ();
@@ -1192,10 +1225,8 @@ create_stack_switcher (void)
gtk_widget_set_margin_bottom (stack, 10);
gtk_widget_set_size_request (stack, 120, 120);
view = gtk_text_view_new ();
- gtk_widget_show (view);
gtk_stack_add_titled (GTK_STACK (stack), view, "page1", "Page 1");
view = gtk_text_view_new ();
- gtk_widget_show (view);
gtk_stack_add_titled (GTK_STACK (stack), view, "page2", "Page 2");
switcher = gtk_stack_switcher_new ();
@@ -1227,10 +1258,8 @@ create_sidebar (void)
gtk_widget_add_css_class (view, "view");
gtk_widget_set_halign (view, GTK_ALIGN_FILL);
gtk_widget_set_valign (view, GTK_ALIGN_FILL);
- gtk_widget_show (view);
gtk_stack_add_titled (GTK_STACK (stack), view, "page1", "Page 1");
view = gtk_text_view_new ();
- gtk_widget_show (view);
gtk_stack_add_titled (GTK_STACK (stack), view, "page2", "Page 2");
sidebar = gtk_stack_sidebar_new ();
@@ -1290,7 +1319,7 @@ create_list_box (void)
gtk_box_append (GTK_BOX (row), button);
gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
- gtk_box_append (GTK_BOX (widget), list);
+ gtk_frame_set_child (GTK_FRAME (widget), list);
info = new_widget_info ("list-box", widget, MEDIUM);
info->no_focus = FALSE;
@@ -1315,19 +1344,19 @@ create_flow_box (void)
gtk_flow_box_set_max_children_per_line (GTK_FLOW_BOX (box), 2);
gtk_flow_box_set_selection_mode (GTK_FLOW_BOX (box), GTK_SELECTION_BROWSE);
button = gtk_label_new ("Child One");
- gtk_box_append (GTK_BOX (box), button);
+ gtk_flow_box_insert (GTK_FLOW_BOX (box), button, -1);
button = gtk_button_new_with_label ("Child Two");
- gtk_box_append (GTK_BOX (box), button);
+ gtk_flow_box_insert (GTK_FLOW_BOX (box), button, -1);
child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_append (GTK_BOX (child), gtk_label_new ("Child Three"));
button = gtk_check_button_new ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_box_append (GTK_BOX (child), button);
- gtk_box_append (GTK_BOX (box), child);
+ gtk_flow_box_insert (GTK_FLOW_BOX (box), child, -1);
gtk_flow_box_select_child (GTK_FLOW_BOX (box),
GTK_FLOW_BOX_CHILD (gtk_widget_get_parent (child)));
- gtk_box_append (GTK_BOX (widget), box);
+ gtk_frame_set_child (GTK_FRAME (widget), box);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -1345,12 +1374,24 @@ create_gl_area (void)
WidgetInfo *info;
GtkWidget *widget;
GtkWidget *gears;
+ GtkCssProvider *provider;
widget = gtk_frame_new (NULL);
-
gears = gtk_gears_new ();
- gtk_box_append (GTK_BOX (widget), gears);
-
+ gtk_widget_add_css_class (gears, "velvet");
+ gtk_widget_set_size_request (gears, 96, 96);
+ gtk_frame_set_child (GTK_FRAME (widget), gears);
+
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (provider, ".velvet { background: black; }", -1);
+ gtk_style_context_add_provider (gtk_widget_get_style_context (gears), GTK_STYLE_PROVIDER (provider), 800);
+ g_object_unref (provider);
+
+ gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
+ gtk_widget_set_valign (widget, GTK_ALIGN_FILL);
+
+ add_margin (widget);
+
info = new_widget_info ("glarea", widget, MEDIUM);
return info;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]