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 | |
7 | struct _DemoChild |
8 | { |
9 | GtkWidget parent_instance; |
10 | GdkRGBA color; |
11 | }; |
12 | |
13 | struct _DemoChildClass |
14 | { |
15 | GtkWidgetClass parent_class; |
16 | }; |
17 | |
18 | G_DEFINE_TYPE (DemoChild, demo_child, GTK_TYPE_WIDGET) |
19 | |
20 | static void |
21 | demo_child_init (DemoChild *self) |
22 | { |
23 | } |
24 | |
25 | static void |
26 | demo_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 | |
39 | static void |
40 | demo_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 | |
51 | static void |
52 | demo_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 | |
60 | GtkWidget * |
61 | demo_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 | |