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

BackgroundColor support #97

Merged
merged 4 commits into from
Oct 28, 2023
Merged

BackgroundColor support #97

merged 4 commits into from
Oct 28, 2023

Conversation

Sjael
Copy link
Contributor

@Sjael Sjael commented Jul 19, 2023

I's pretty common to need the ability to fade UI elements/images on and off, so I added a lens for BackgroundColor.

Simply tween the alpha value for two Color::rgb().set_a()

let selected_color = Color::RED;
let tween_opac = Tween::new(
    EaseFunction::QuadraticIn,
    Duration::from_secs(1),
    UiBackgroundColorLens {
        start: selected_color.set_a(0.9),
        end: selected_color.set_a(0.0),
    },
);
let animator = Animator::new(tween_opac);

It's very nice for flashing something on screen and removing after a delay, like a killfeed notification.

let selected_color = Color::RED;
let tween_opac_in = Tween::new(
    EaseFunction::QuadraticIn,
    Duration::from_millis(500),
    UiBackgroundColorLens {
        start: selected_color.set_a(0.0),
        end: selected_color.set_a(0.9),
    },
);
let tween_opac_out = Tween::new(
    EaseFunction::QuadraticIn,
    Duration::from_secs(1),
    UiBackgroundColorLens {
        start: selected_color.set_a(0.9),
        end: selected_color.set_a(0.0),
    },
).with_completed_event(
    TweenEvents::KillNotifEnded as u64,
);
let animator =  Animator::new(tween_opac_in
    .then(Delay::new(
        Duration::from_secs(15),
    ))
    .then(tween_opac_out)
);

This would also work for going between any 2 colors, but I think the opacity will be most used.

added background color support, mainly for opacity
Copy link
Owner

@djeedai djeedai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the change!

I'm generally against adding more lenses, as really the system is designed for users to write their own, and I don't want to have to maintain every single use case. That being said, here I appreciate how common this is, and is in a sense an unfortunate regression of Bevy newtyping all its UI type a few releases ago. So OK for this change.

@djeedai djeedai added the enhancement New feature or request label Jul 29, 2023
Copy link
Owner

@djeedai djeedai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update the CHANGELOG, and ideally add a small test for that new lens? Thanks!

Copy link
Owner

@djeedai djeedai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need CHANGELOG update

Copy link
Owner

@djeedai djeedai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the CHANGELOG change myself just to complete the PR as we're nearing the Bevy 0.12 release and I want to be ready :) Thanks!

@djeedai djeedai merged commit 54ea432 into djeedai:main Oct 28, 2023
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants