iced icon indicating copy to clipboard operation
iced copied to clipboard

feat: animations for default widgets

Open lazytanuki opened this issue 1 week ago • 0 comments

Hi!

This PR is the continuation / replacement of my previous work in #1855 which needed a heavy rebase as well as improvements for some edge cases.

This PR implements internal animations for some of the default widgets. The goal here is to make Iced applications appear smooth when hovering / clicking things, without breaking the API. This heavily uses the frame subscription API.

Motivation

In most other toolkits out there, such as GTK, app developers can make GUIs without needing to handle widget animations by themselves, which makes for a better coding experience and a coherent ecosystem.

Implementation

Animations are handled by an AnimationTimeline (in core/src/animations.rs) that is stored in the State of some widgets. These timelines are updated on certain actions such as user events and frame subscriptions.

Two animations "effects" are provided: linear and ease-out.

Widgets that have got animations are:

  • buttons: hover and click style transitions
  • text input cursor: cursor fades in and out when idle
  • togglers
  • checkboxes
  • scrollables: scrolling using the mouse wheel and clicking on the scrollbar follows an eased-out trajectory, whereas scrolling by grabbing the scrollbar remains instantaneous

This PR is divided in six separate commits for an easier reviewing: one for the example animation, one for the animations's core and buttons implementation, then one per additional widget that has got animations.

https://github.com/iced-rs/iced/assets/43273245/3959b0c9-2116-44bc-8a94-4cd996da12a7

What's next

If and when this PR lands, some more widgets can receive animations. However the most important step that I intend to implement is a global animation speed multiplier, so that users can set it according to their preferences in the COSMIC desktop, for instance.

lazytanuki avatar Jun 28 '24 17:06 lazytanuki