1#include "demochild.h"
2
3/* This is a trivial child widget just for demo purposes.
4 * It draws a 32x32 square in fixed color.
5 */
6
7struct _DemoChild
8{
9 GtkWidget parent_instance;
10 GdkRGBA color;
11};
12
13struct _DemoChildClass
14{
15 GtkWidgetClass parent_class;
16};
17
18G_DEFINE_TYPE (DemoChild, demo_child, GTK_TYPE_WIDGET)
19
20static void
21demo_child_init (DemoChild *self)
22{
23}
24
25static void
26demo_child_snapshot (GtkWidget *widget,
27 GtkSnapshot *snapshot)
28{
29 DemoChild *self = DEMO_CHILD (ptr: widget);
30 int width, height;
31
32 width = gtk_widget_get_width (widget);
33 height = gtk_widget_get_height (widget);
34
35 gtk_snapshot_append_color (snapshot, color: &self->color,
36 bounds: &GRAPHENE_RECT_INIT(0, 0, width, height));
37}
38
39static void
40demo_child_measure (GtkWidget *widget,
41 GtkOrientation orientation,
42 int for_size,
43 int *minimum,
44 int *natural,
45 int *minimum_baseline,
46 int *natural_baseline)
47{
48 *minimum = *natural = 32;
49}
50
51static void
52demo_child_class_init (DemoChildClass *class)
53{
54 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
55
56 widget_class->snapshot = demo_child_snapshot;
57 widget_class->measure = demo_child_measure;
58}
59
60GtkWidget *
61demo_child_new (const char *color)
62{
63 DemoChild *self;
64
65 self = g_object_new (DEMO_TYPE_CHILD,
66 first_property_name: "tooltip-text", color,
67 NULL);
68
69 gdk_rgba_parse (rgba: &self->color, spec: color);
70
71 return GTK_WIDGET (self);
72}
73

source code of gtk/demos/gtk-demo/demochild.c