1.4 <AdwAnimation>

Class: <AdwAnimation>

It derives from <GObject>.

A base class for animations.

<AdwAnimation> 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.

<AdwAnimation> will automatically skip the animation if Animation:widget is unmapped, or if settings:gtk-enable-animations is FALSE.

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

<AdwAnimation> 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:

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

static void
my_object_animate (MyObject *self)
{
  AdwAnimationTarget *target =
    adw_callback_animation_target_new ((AdwAnimationTargetFunc) animation_cb,
                                       self, NULL);
  g_autoptr (AdwAnimation) 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 <AdwAnimation> object can be reused.

Fields

parent-instance

Properties

Property: animation:follow-enable-animations-setting self

Whether to skip the animation when animations are globally disabled.

The default behavior is to skip the animation. Set to FALSE to disable this behavior.

This can be useful for cases where animation is essential, like spinners, or in demo applications. Most other animations should keep it enabled.

See settings:gtk-enable-animations.

Its value is a boolean.

Set it with (set! (animation:follow-enable-animations-setting self) value).

Property: animation:state self

The animation state.

The state indicates whether the animation is currently playing, paused, finished or hasn’t been started yet.

Its value is a <AdwAnimationState>.

It is read only.

Property: animation:target self

The target to animate.

Its value is a <AdwAnimationTarget>, or #f.

Set it with (set! (animation:target self) value).

Property: animation:value self

The current value of the animation.

Its value is a real number.

It is read only.

Property: animation:widget self

The animation widget.

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.

Its value is a <GtkWidget>, or #f.

It can only be set when the object is made, with #:widget.

Procedures

Method: animation:get-follow-enable-animations-setting? self ⇒ %return
Method: get-follow-enable-animations-setting? self ⇒ %return

Gets whether self should be skipped when animations are globally disabled.

self

Passed: a <AdwAnimation>.

an animation

%return

Returned: a boolean.

whether to follow the global setting

Method: animation:get-state self ⇒ %return
Method: get-state self ⇒ %return

Gets the current value of self.

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

self

Passed: a <AdwAnimation>.

an animation

%return

Returned: a <AdwAnimationState>.

the animation value

Method: animation:get-target self ⇒ %return
Method: get-target self ⇒ %return

Gets the target self animates.

self

Passed: a <AdwAnimation>.

an animation

%return

Returned: a <AdwAnimationTarget>.

the animation target

Method: animation:get-value self ⇒ %return
Method: get-value self ⇒ %return

Gets the current value of self.

self

Passed: a <AdwAnimation>.

an animation

%return

Returned: a real number.

the current value

Method: animation:get-widget self ⇒ %return
Method: get-widget self ⇒ %return

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.

self

Passed: a <AdwAnimation>.

an animation

%return

Returned: a <GtkWidget>.

the animation widget

Method: animation:pause self
Method: pause self

Pauses a playing animation for self.

Does nothing if the current state of self isn’t Adw.AnimationState.playing.

Sets Animation:state to Adw.AnimationState.paused.

self

Passed: a <AdwAnimation>.

an animation

Method: animation:play self
Method: play self

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.AnimationState.playing.

The animation will be automatically skipped if Animation:widget is unmapped, or if settings:gtk-enable-animations is FALSE.

As such, it’s not guaranteed that the animation will actually run. For example, when using 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.

self

Passed: a <AdwAnimation>.

an animation

Method: animation:reset self
Method: reset self

Resets the animation for self.

Sets Animation:state to Adw.AnimationState.idle.

self

Passed: a <AdwAnimation>.

an animation

Method: animation:resume self
Method: resume self

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.AnimationState.playing.

self

Passed: a <AdwAnimation>.

an animation

Method: animation:set-follow-enable-animations-setting self setting
Method: set-follow-enable-animations-setting self setting

Sets whether to skip self when animations are globally disabled.

The default behavior is to skip the animation. Set to FALSE to disable this behavior.

This can be useful for cases where animation is essential, like spinners, or in demo applications. Most other animations should keep it enabled.

See settings:gtk-enable-animations.

self

Passed: a <AdwAnimation>.

an animation

setting

Passed: a boolean.

whether to follow the global setting

Method: animation:set-target self target
Method: set-target self target

Sets the target self animates to target.

self

Passed: a <AdwAnimation>.

an animation

target

Passed: a <AdwAnimationTarget>.

an animation target

Method: animation:skip self
Method: skip self

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 "done" to be emitted.

Sets Animation:state to Adw.AnimationState.finished.

self

Passed: a <AdwAnimation>.

an animation

Signals

Signal: animation:done

Connect a handler with (connect object animation:done handler). It is called as (handler self).

This signal is emitted when the animation has been completed, either on its own or via calling Animation.skip.

self

Passed: a <AdwAnimation>.