Merge branch 'matthiasc/for-main' into 'main'
gtk-demo: Clean up path walk demo See merge request GNOME/gtk!6288
This commit is contained in:
@@ -24,6 +24,7 @@ struct _GtkPathWalk
|
||||
GtkWidget parent_instance;
|
||||
|
||||
GskPath *path;
|
||||
graphene_rect_t bounds;
|
||||
};
|
||||
|
||||
struct _GtkPathWalkClass
|
||||
@@ -58,6 +59,23 @@ gtk_path_walk_snapshot (GtkWidget *widget,
|
||||
gtk_snapshot_restore (snapshot);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_walk_measure (GtkWidget *widget,
|
||||
GtkOrientation orientation,
|
||||
int for_size,
|
||||
int *minimum,
|
||||
int *natural,
|
||||
int *minimum_baseline,
|
||||
int *natural_baseline)
|
||||
{
|
||||
GtkPathWalk *self = GTK_PATH_WALK (widget);
|
||||
|
||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
*minimum = *natural = (int) ceilf (self->bounds.size.width);
|
||||
else
|
||||
*minimum = *natural = (int) ceilf (self->bounds.size.height);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_walk_set_path (GtkPathWalk *self,
|
||||
GskPath *path)
|
||||
@@ -66,10 +84,18 @@ gtk_path_walk_set_path (GtkPathWalk *self,
|
||||
return;
|
||||
|
||||
g_clear_pointer (&self->path, gsk_path_unref);
|
||||
graphene_rect_init (&self->bounds, 0, 0, 0, 0);
|
||||
if (path)
|
||||
self->path = gsk_path_ref (path);
|
||||
{
|
||||
GskStroke *stroke;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
self->path = gsk_path_ref (path);
|
||||
stroke = gsk_stroke_new (2.0);
|
||||
gsk_path_get_stroke_bounds (path, stroke, &self->bounds);
|
||||
gsk_stroke_free (stroke);
|
||||
}
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PATH]);
|
||||
}
|
||||
@@ -136,6 +162,7 @@ gtk_path_walk_class_init (GtkPathWalkClass *klass)
|
||||
object_class->get_property = gtk_path_walk_get_property;
|
||||
|
||||
widget_class->snapshot = gtk_path_walk_snapshot;
|
||||
widget_class->measure = gtk_path_walk_measure;
|
||||
|
||||
properties[PROP_PATH] =
|
||||
g_param_spec_boxed ("path",
|
||||
@@ -149,7 +176,9 @@ gtk_path_walk_class_init (GtkPathWalkClass *klass)
|
||||
static void
|
||||
gtk_path_walk_init (GtkPathWalk *self)
|
||||
{
|
||||
self->path = gsk_path_parse (path_world);
|
||||
GskPath *path = gsk_path_parse (path_world);
|
||||
gtk_path_walk_set_path (self, path);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
|
||||
@@ -1,29 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow" id="window">
|
||||
<property name="title" translatable="yes">Animation along a Path</property>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<child type="end">
|
||||
<object class="GtkToggleButton" id="edit-toggle">
|
||||
<property name="icon-name">document-edit-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="title" translatable="yes">World Map</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkRevealer">
|
||||
<property name="reveal-child" bind-source="edit-toggle" bind-property="active" bind-flags="sync-create"></property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="text">
|
||||
<property name="text">Through the looking glass</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkPathWalk" id="view">
|
||||
<property name="hexpand">true</property>
|
||||
|
||||
Reference in New Issue
Block a user