egui icon indicating copy to clipboard operation
egui copied to clipboard

Changed `ui.disable()` to modify opacity.

Open tye-exe opened this issue 8 months ago • 16 comments

It previously tinted elements, which could have lackluster effects.

New looks

(I say new but I tried to keep them as similar as possible to previous)

Light mode

light_mode.webm

Dark mode

dark_mode.webm

Additional remarks

Since the opacity is being change, elements that are on-top of other elements now show some of the underneath element (this can be seen with the slider in the sent videos).

tye-exe avatar Apr 16 '25 19:04 tye-exe

This has far-reaching consequences for the visual of existing egui apps other than just fixing the linked issue.

I think this change should be configurable; otherwise, significant considerations should be put into messing up existing visuals.

juh9870 avatar Apr 16 '25 20:04 juh9870

That's a fair viewpoint.

What other possible solutions to this issue do you recommend?

I tried modifying the fade_out_to_color method (as also suggested in the issue) to modify the alpha channel. However, this was not able to prevent the issue on light mode, even at the extremes of the alpha channel.

Relevant method: https://github.com/emilk/egui/blob/5d6aaa239b98ad20d365626dc664531b08b2537d/crates/egui/src/style.rs#L1055-L1060

Out of interest in which situations will this be an issue for (so I could potentially work on solving them)?

tye-exe avatar Apr 17 '25 06:04 tye-exe

The problem is exactly what you mentioned in the Additional remarks sections.

I believe that a method of fading out (color or transparency) should be an option in the style. Maybe as an enum variant akin to

enum FadeOutMethod {
    NonInteractiveWeakBgFill,
    CustomColor(Color32),
    DimTransparency(f32)
}

the exact shape of variants and naming should be discussed ofc

juh9870 avatar Apr 17 '25 07:04 juh9870

I agree with being able to override the fade out colour, but that does lean towards a more major change, as Visuals is a commonly used data structure.

Also adding more default colours increases the maintenance burden in the future. i'm not sure if that would be needed if the user can customise the fade out colour.

tye-exe avatar Apr 17 '25 10:04 tye-exe

A possible option for setting a custom fade out colour would be to add a feild like override_fade: Option<Color32>, which can default to None.

tye-exe avatar Apr 17 '25 10:04 tye-exe

Preview available at https://egui-pr-preview.github.io/pr/6765-defaultaffectsopacity Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

github-actions[bot] avatar Apr 22 '25 09:04 github-actions[bot]

Will it be a good idea to add an attribute to Visuals that is returned from fade_out_opacity?

Because currently the value is hard-coded, so it cannot be changed.

tye-exe avatar Apr 25 '25 12:04 tye-exe

I have added the option for user-customization that i suggested & created a pull request against the branch in my fork for anyone to look at.

I can easily merge these changes into the branch in this egui pull request.

tye-exe avatar Apr 30 '25 18:04 tye-exe

emilk, do you want me to merge the user-customisation code?

tye-exe avatar May 18 '25 12:05 tye-exe

Yes, adding a Visuals::disabled_alpha: f32 that default to 0.5 sounds like a great idea

emilk avatar May 19 '25 08:05 emilk

Yes, adding a Visuals::disabled_alpha: f32 that default to 0.5 sounds like a great idea

:+1: I have done so.

tye-exe avatar May 19 '25 08:05 tye-exe

There is a problem with this approach: Visuals::weak_text_color uses Visuals::gray_out, but gray_out no longer makes the text gray; it makes it transparent. This may be fine, but we should probably rename gray_out, and we also need to update snapshot tests.

emilk avatar May 21 '25 11:05 emilk

I will be able to work on this at the weekend

tye-exe avatar May 22 '25 18:05 tye-exe

I've restored gray_out to its previous state, and created the new function disable that returns the colour with the alpha modified.

This allows for either to be used if modifying the alpha if undesirable.

tye-exe avatar May 25 '25 08:05 tye-exe

An issue with the modify opacity approach is that the "colour picker" widget does not look very good when disabled on light mode.

Colour picker on light mode.webm

tye-exe avatar May 25 '25 09:05 tye-exe

Should i re-add the fade_out_to_color function, but annotated it as deprecated? This will give time for users to stop using this function instead of having an instant compile error.

tye-exe avatar May 25 '25 09:05 tye-exe

Should i re-add the fade_out_to_color function, but annotated it as deprecated? This will give time for users to stop using this function instead of having an instant compile error.

Yeah, why not.

You also need to update the snapshot images (again), because of a merge race (sorry!)

emilk avatar Jun 16 '25 00:06 emilk

I think that you have to run the CI to generate the images again for me to pull them from the CI, apologies.

tye-exe avatar Jun 17 '25 12:06 tye-exe

This should do it!

tye-exe avatar Jun 18 '25 11:06 tye-exe