class Adw::Animation


A base class for animations.

Adw::Animation represents an animation on a widget. It has a target that provides a value to animate, and a state indicating whether the animation hasn't been started yet, is playing, paused or finished.

Currently there are two concrete animation types: #TimedAnimation and #SpringAnimation.

Adw::Animation will automatically skip the animation if Animation::widget is unmapped, or if [property@Gtk.Settings:gtk-enable-animations] is FALSE.

The Animation::#done signal can be used to perform an action after the animation ends, for example hiding a widget after animating its Gtk::Widget#opacity to 0.

Adw::Animation will be kept alive while the animation is playing. As such, it's safe to create an animation, start it and immediately unref it: A fire-and-forget animation:

WARNING ⚠️ The following code is in c ⚠️

static void
animation_cb (double    value,
              MyObject *self)
  // Do something with @value

static void
my_object_animate (MyObject *self)
  Adw::AnimationTarget *target =
    adw_callback_animation_target_new ((Adw::AnimationTargetFunc) animation_cb,
                                       self, NULL);
  g_autoptr (Adw::Animation) animation =
    adw_timed_animation_new (widget, 0, 1, 250, target);

  adw_animation_play (animation);

If there's a chance the previous animation for the same target hasn't yet finished, the previous animation should be stopped first, or the existing Adw::Animation object can be reused.

Direct Known Subclasses

Defined in:



Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def #

Initialize a new Animation.

def*, state : Adw::AnimationState? = nil, target : Adw::AnimationTarget? = nil, value : Float64? = nil, widget : Gtk::Widget? = nil) #

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.

Instance Method Detail

def done_signal #

def pause : Nil #

Pauses a playing animation for @self.

Does nothing if the current state of @self isn't ADW_ANIMATION_PLAYING.

Sets Animation::state to ADW_ANIMATION_PAUSED.

def play : Nil #

Starts the animation for @self.

If the animation is playing, paused or has been completed, restarts it from the beginning. This allows to easily play an animation regardless of whether it's already playing or not.

Sets Animation::state to ADW_ANIMATION_PLAYING.

The animation will be automatically skipped if Animation::widget is unmapped, or if [property@Gtk.Settings:gtk-enable-animations] is FALSE.

As such, it's not guaranteed that the animation will actually run. For example, when using GLib::idle_add and starting an animation immediately afterwards, it's entirely possible that the idle callback will run after the animation has already finished, and not while it's playing.

def reset : Nil #

Resets the animation for @self.

Sets Animation::state to ADW_ANIMATION_IDLE.

def resume : Nil #

Resumes a paused animation for @self.

This function must only be used if the animation has been paused with Animation::pause.

Sets Animation::state to ADW_ANIMATION_PLAYING.

def skip : Nil #

Skips the animation for @self.

If the animation hasn't been started yet, is playing, or is paused, instantly skips the animation to the end and causes Animation::#done to be emitted.

Sets Animation::state to ADW_ANIMATION_FINISHED.

def state : Adw::AnimationState #

Gets the current value of @self.

The state indicates whether @self is currently playing, paused, finished or hasn't been started yet.

def target : Adw::AnimationTarget #

Gets the target @self animates.

def target=(target : Adw::AnimationTarget) : Nil #

Sets the target @self animates to @target.

def value : Float64 #

Gets the current value of @self.

def widget : Gtk::Widget #

Gets the widget @self was created for.

It provides the frame clock for the animation. It's not strictly necessary for this widget to be same as the one being animated.

The widget must be mapped in order for the animation to work. If it's not mapped, or if it gets unmapped during an ongoing animation, the animation will be automatically skipped.

def widget=(value : Gtk::Widget?) : Gtk::Widget? #