Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a default easing function in Style #5463

Open
FireFragment opened this issue Dec 11, 2024 · 3 comments
Open

Allow setting a default easing function in Style #5463

FireFragment opened this issue Dec 11, 2024 · 3 comments

Comments

@FireFragment
Copy link

Is your feature request related to a problem? Please describe.

Developer may prefer using certain easing function because of branding, coherence with easing used by rest of the system or personal preference. But now, the built-in animations such as SidePanel::show_animated or CollapsingHeader use the default, non-customizable easing.

Describe the solution you'd like

I would add new field to Style, something like easing being a struct containing three easing functions: ease_out, ease_in and ease_in_out. The built-in widgets would use these easing functions by default (eg. animate_bool_responsive would use ease_out).

Additionally, widgets built by the community could also use these default easings, making animations customizable while keeping them consistent.

Describe alternatives you've considered

  • Allowing to specify easing functions on the built-in widgets individually
  • Letting user specify only the ease_out function in the style, because AFAIK ease-in isn't used anywhere in egui right now. This would also eliminate the need for something like an Easings struct.
@lucasmerlin
Copy link
Collaborator

I would add new field to Style, something like easing being a struct containing three easing functions: ease_out, ease_in and ease_in_out.

I would also like this, but the problem with this solution would be that Style is De/Serializable and there is no way to to serialize a function :/ we could of course just set the default easings when deserializing but that would suck.

An alternative approach would be to add an Easing enum that has all the predefined easings, an an Easing::Custom(fn(...)), that would mean at least the build in easings would be serializable.

@FireFragment
Copy link
Author

@lucasmerlin

we could of course just set the default easings when deserializing but that would suck.

I thought that was okay, because Style::number_formatter already does this for the exact same reason:

#[cfg_attr(feature = "serde", serde(skip))]
pub number_formatter: NumberFormatter,

pub struct NumberFormatter(
Arc<dyn 'static + Sync + Send + Fn(f64, RangeInclusive<usize>) -> String>,
);

But I personally like the enum idea :).

@lucasmerlin
Copy link
Collaborator

Ah, good point, also I think serde support here isn't super important, since the biggest usecase is probably for exporting / importing ui themes and I don't think a lot of egui Apps do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants