Commit d2c417ab authored by Manuel Genovés's avatar Manuel Genovés
Browse files

Add a wip demo for timed-animation

parent 6958ab9d
Pipeline #305884 failed with stage
in 3 minutes and 53 seconds
......@@ -28,11 +28,56 @@ struct _AdwDemoWindow
GtkFileChooserNative *avatar_file_chooser;
GtkListBox *avatar_contacts;
AdwAnimation *timed_animation;
AdwBin *timed_animation_widget;
GtkFixed *timed_animation_widget_container;
};
G_DEFINE_TYPE (AdwDemoWindow, adw_demo_window, ADW_TYPE_APPLICATION_WINDOW)
enum {
PROP_0,
PROP_TIMED_ANIMATION,
LAST_PROP,
};
static GParamSpec *props[LAST_PROP];
static void
adw_demo_window_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
AdwDemoWindow *self = ADW_DEMO_WINDOW (object);
switch (prop_id) {
case PROP_TIMED_ANIMATION:
g_value_set_object (value, adw_demo_window_get_timed_animation (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
adw_demo_window_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
AdwDemoWindow *self = ADW_DEMO_WINDOW (object);
switch (prop_id) {
case PROP_TIMED_ANIMATION:
g_set_object (&self->timed_animation, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
theme_variant_button_clicked_cb (AdwDemoWindow *self)
{
......@@ -429,22 +474,37 @@ timed_animation_value_cb (double value,
static void
timed_animation_play (AdwDemoWindow *self)
{
if (self->timed_animation) {
adw_animation_start (self->timed_animation);
if (!self->timed_animation) {
self->timed_animation = adw_timed_animation_new (GTK_WIDGET (self->timed_animation_widget_container),
20,
80,
300,
(AdwAnimationTargetFunc) timed_animation_value_cb,
self->timed_animation_widget_container);
}
adw_animation_start (self->timed_animation);
self->timed_animation = adw_timed_animation_new (GTK_WIDGET (self->timed_animation_widget_container),
0,
100,
300,
(AdwAnimationTargetFunc) timed_animation_value_cb,
self->timed_animation_widget_container);
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TIMED_ANIMATION]);
}
static void
timed_animation_stop (AdwDemoWindow *self)
{
if (self->timed_animation) {
adw_animation_stop (self->timed_animation);
}
}
static void
adw_demo_window_class_init (AdwDemoWindowClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = adw_demo_window_set_property;
object_class->get_property = adw_demo_window_get_property;
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_q, GDK_CONTROL_MASK, "window.close", NULL);
......@@ -466,6 +526,7 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, avatar_file_chooser_label);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, avatar_remove_button);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, avatar_contacts);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, timed_animation_widget);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, timed_animation_widget_container);
gtk_widget_class_bind_template_callback (widget_class, notify_visible_child_cb);
gtk_widget_class_bind_template_callback (widget_class, back_clicked_cb);
......@@ -487,6 +548,16 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, tab_view_demo_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, animations_interpolator_name);
gtk_widget_class_bind_template_callback (widget_class, timed_animation_play);
gtk_widget_class_bind_template_callback (widget_class, timed_animation_stop);
props[PROP_TIMED_ANIMATION] =
g_param_spec_object ("timed_animation",
"Timed animation",
"Timed animation",
ADW_TYPE_ANIMATION,
G_PARAM_READWRITE);
g_object_class_install_properties (object_class, LAST_PROP, props);
}
static void
......@@ -532,3 +603,11 @@ adw_demo_window_init (AdwDemoWindow *self)
adw_leaflet_set_visible_child (self->content_box, GTK_WIDGET (self->right_box));
}
AdwAnimation *
adw_demo_window_get_timed_animation (AdwDemoWindow *self)
{
g_return_val_if_fail (ADW_IS_DEMO_WINDOW (self), NULL);
return self->timed_animation;
}
......@@ -10,4 +10,6 @@ G_DECLARE_FINAL_TYPE (AdwDemoWindow, adw_demo_window, ADW, DEMO_WINDOW, AdwAppli
AdwDemoWindow *adw_demo_window_new (GtkApplication *application);
AdwAnimation *adw_demo_window_get_timed_animation (AdwDemoWindow *self);
G_END_DECLS
......@@ -868,9 +868,9 @@
<class name="timed-animation-page"/>
</style>
<child>
<object class="GtkFixed" id="timed-animation-widget-container">
<object class="GtkFixed" id="timed_animation_widget_container">
<child>
<object class="AdwBin" id="timed-animation-widget">
<object class="AdwBin" id="timed_animation_widget">
<property name="halign">center</property>
<property name="valign">center</property>
<style>
......@@ -908,14 +908,27 @@
</child>
<child>
<object class="GtkBox">
<property name="valign">center</property>
<property name="halign">center</property>
<property name="margin-bottom">12</property>
<property name="spacing">18</property>
<child>
<object class="GtkButton">
<property name="icon-name">media-playback-stop-symbolic</property>
<property name="valign">center</property>
<signal name="clicked" handler="timed_animation_stop" swapped="true"/>
<style>
<class name="circular"/>
</style>
</object>
</child>
<child>
<object class="GtkButton">
<property name="icon-name">spring-run-symbolic</property>
<property name="icon-name">media-playback-start-symbolic</property>
<property name="valign">center</property>
<property name="margin-end">18</property>
<signal name="clicked" handler="timed_animation_play" swapped="true"/>
<style>
<class name="circular-large"/>
<class name="circular"/>
<class name="suggested-action"/>
</style>
</object>
......
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