decipher3114 / Capter

A simple cross-platform screenshot tool made in rust
Apache License 2.0
89 stars 4 forks source link

Theme animation #2

Closed Brady-Simon closed 1 month ago

Brady-Simon commented 1 month ago

Implements a theme animation with the iced_anim crate. This changes the Config to contain a Spring<Theme> and implements Animate for Palette and Theme so that theme changes will be animated when the user changes the theme. A new Theme::Custom case is what enables animations because it takes any custom palette and allows the app to use that palette for theming. This Custom case is what allows the animated theme state to update and isn't serialized to disk at any point.

I also created a new StoredConfig struct that represents the serialized config, which is distinct from the Config struct since the latter may contain an animated state. This guarantees that the animated state value won't be serialized to disk. If you want to test this yourself, you can add a long response time to a SpringMotion on the Spring::new in utils/config.rs and exit the app before the animation is complete - you'll see that the final theme value is serialized and not the intermediate state.

Feel free to rename Config now that it represents less of a configuration and more of an app state - I went with StoredConfig to represent the new serialized config format just to avoid changing more of your app than necessary. Let me know if you have any questions!

https://github.com/user-attachments/assets/fb60e3a5-87fb-45c0-90ec-b74ce219f33b

decipher3114 commented 1 month ago

Instead of creating another config, you can use theme: Spring<Theme> as a field in ConfigWindow struct. It is there to store window specific data.

decipher3114 commented 1 month ago

Anyways, I am merging it. I'll fix that later