Commit 6736dd02 authored by Manuel Genovés's avatar Manuel Genovés
Browse files

Refactor animation-target

parent d2c417ab
Pipeline #308993 failed with stage
in 4 minutes and 30 seconds
......@@ -18,21 +18,6 @@
#include "adw-animation.h"
G_BEGIN_DECLS
typedef void (*AdwAnimationTargetFunc) (double value,
gpointer user_data);
#define ADW_TYPE_ANIMATION_TARGET (adw_animation_target_get_type())
G_DECLARE_FINAL_TYPE (AdwAnimationTarget, adw_animation_target, ADW, ANIMATION_TARGET, GObject)
AdwAnimationTarget *adw_animation_target_new (AdwAnimationTargetFunc callback,
gpointer data);
void adw_animation_target_set_value (AdwAnimationTarget *target,
double value);
typedef void (*AdwAnimationDoneCallback) (gpointer user_data);
typedef double (*AdwAnimationEasingFunc) (double t);
typedef enum {
ADW_ANIMATION_STATUS_NONE,
......
/*
* Copyright (C) 2021 Manuel Genovés <manuel.genoves@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "config.h"
#include "adw-animation-target.h"
struct _AdwAnimationTarget
{
GObject parent_instance;
};
struct _AdwAnimationTargetClass
{
GObjectClass parent_class;
void (*set_value) (AdwAnimationTarget *self,
double value);
};
G_DEFINE_ABSTRACT_TYPE (AdwAnimationTarget, adw_animation_target, G_TYPE_OBJECT)
static void
adw_animation_target_constructed (GObject *object)
{
G_OBJECT_CLASS (adw_animation_target_parent_class)->constructed (object);
}
static void
adw_animation_target_class_init (AdwAnimationTargetClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = adw_animation_target_constructed;
}
static void
adw_animation_target_init (AdwAnimationTarget *self)
{
}
void
adw_animation_target_set_value (AdwAnimationTarget *self,
double value)
{
g_return_if_fail (ADW_IS_ANIMATION_TARGET (self));
ADW_ANIMATION_TARGET_GET_CLASS (self)->set_value (self, value);
}
struct _AdwCallbackAnimationTarget
{
AdwAnimationTarget parent_instance;
AdwAnimationTargetFunc callback;
gpointer user_data;
};
struct _AdwCallbackAnimationTargetClass
{
AdwAnimationTargetClass parent_class;
};
G_DEFINE_TYPE (AdwCallbackAnimationTarget, adw_callback_animation_target, ADW_TYPE_ANIMATION_TARGET)
static void
adw_callback_animation_target_class_init (AdwCallbackAnimationTargetClass *klass)
{
AdwAnimationTargetClass *target_class = ADW_ANIMATION_TARGET_CLASS (klass);
target_class->set_value = adw_callback_animation_target_set_value;
}
static void
adw_callback_animation_target_init (AdwCallbackAnimationTarget *self)
{
}
AdwAnimationTarget *
adw_callback_animation_target_new (AdwAnimationTargetFunc callback,
gpointer user_data)
{
AdwCallbackAnimationTarget *self;
g_return_val_if_fail (callback != NULL, NULL);
self = g_object_new (ADW_TYPE_CALLBACK_ANIMATION_TARGET, NULL);
self->callback = callback;
self->user_data = user_data;
return ADW_ANIMATION_TARGET (self);
}
void
adw_callback_animation_target_set_value (AdwAnimationTarget *self,
double value)
{
AdwCallbackAnimationTarget *callback_target;
g_return_if_fail (ADW_IS_ANIMATION_TARGET (self));
callback_target = ADW_CALLBACK_ANIMATION_TARGET (self);
callback_target->callback (value, callback_target->user_data);
}
\ No newline at end of file
/*
* Copyright (C) 2021 Manuel Genovés <manuel.genoves@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#if !defined(_ADWAITA_INSIDE) && !defined(ADWAITA_COMPILATION)
#error "Only <adwaita.h> can be included directly."
#endif
#include <gtk/gtk.h>
#include "adw-version.h"
G_BEGIN_DECLS
typedef void (*AdwAnimationTargetFunc) (double value,
gpointer user_data);
#define ADW_TYPE_ANIMATION_TARGET (adw_animation_target_get_type())
ADW_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (AdwAnimationTarget, adw_animation_target, ADW, ANIMATION_TARGET, GObject)
void adw_animation_target_set_value (AdwAnimationTarget *self,
double value);
#define ADW_TYPE_CALLBACK_ANIMATION_TARGET (adw_callback_animation_target_get_type())
ADW_AVAILABLE_IN_ALL
GDK_DECLARE_INTERNAL_TYPE (AdwCallbackAnimationTarget, adw_callback_animation_target, ADW, CALLBACK_ANIMATION_TARGET, AdwAnimationTarget)
ADW_AVAILABLE_IN_ALL
AdwAnimationTarget *adw_callback_animation_target_new (AdwAnimationTargetFunc callback,
gpointer user_data);
ADW_AVAILABLE_IN_ALL
void adw_callback_animation_target_set_value (AdwAnimationTarget *self,
double value);
G_END_DECLS
......@@ -9,6 +9,8 @@
#include "adw-animation-util-private.h"
#include "adw-animation-private.h"
#include "adw-animation-target.h"
typedef struct
......@@ -255,7 +257,7 @@ adw_animation_new (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (target_func != NULL, NULL);
target = adw_animation_target_new(target_func, user_data);
target = adw_callback_animation_target_new(target_func, user_data);
return g_object_new (ADW_TYPE_ANIMATION,
"widget", widget,
"target", target,
......@@ -385,47 +387,4 @@ adw_animation_set_status (AdwAnimation *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATUS]);
}
struct _AdwAnimationTarget
{
GObject parent_instance;
AdwAnimationTargetFunc callback;
gpointer user_data;
};
G_DEFINE_TYPE (AdwAnimationTarget, adw_animation_target, G_TYPE_OBJECT);
static void
adw_animation_target_class_init (AdwAnimationTargetClass *klass)
{
}
static void
adw_animation_target_init (AdwAnimationTarget *self)
{
}
AdwAnimationTarget *
adw_animation_target_new (AdwAnimationTargetFunc callback,
gpointer user_data)
{
AdwAnimationTarget *self;
g_return_val_if_fail (callback != NULL, NULL);
self = g_object_new (ADW_TYPE_ANIMATION_TARGET, NULL);
self->callback = callback;
self->user_data = user_data;
return self;
}
void
adw_animation_target_set_value (AdwAnimationTarget *self,
double value)
{
g_return_if_fail (ADW_IS_ANIMATION_TARGET (self));
self->callback (value, self->user_data);
}
......@@ -14,6 +14,8 @@
#include <gtk/gtk.h>
#include "adw-version.h"
#include "adw-animation-target.h"
G_BEGIN_DECLS
......
......@@ -288,7 +288,7 @@ adw_timed_animation_new (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (target_func != NULL, NULL);
target = adw_animation_target_new(target_func, user_data);
target = adw_callback_animation_target_new(target_func, user_data);
return g_object_new (ADW_TYPE_TIMED_ANIMATION,
"widget", widget,
"value-from", from,
......
......@@ -24,6 +24,7 @@ G_BEGIN_DECLS
#include "adw-action-row.h"
#include "adw-animation.h"
#include "adw-animation-util.h"
#include "adw-animation-target.h"
#include "adw-application-window.h"
#include "adw-avatar.h"
#include "adw-bin.h"
......
......@@ -71,6 +71,7 @@ src_headers = [
'adw-action-row.h',
'adw-animation.h',
'adw-animation-util.h',
'adw-animation-target.h',
'adw-application-window.h',
'adw-avatar.h',
'adw-bin.h',
......@@ -127,6 +128,7 @@ src_sources = [
'adw-animation.c',
'adw-animation-util.c',
'adw-timed-animation.c',
'adw-animation-target.c',
'adw-application-window.c',
'adw-avatar.c',
'adw-bidi.c',
......
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