Change `ui.disable()` to modify opacity (#7282)
* Closes https://github.com/emilk/egui/pull/6765 Branched off of https://github.com/emilk/egui/pull/6765 by @tye-exe. I needed to branch off to update snapshot images --------- Co-authored-by: tye-exe <tye@mailbox.org> Co-authored-by: Tye <131195812+tye-exe@users.noreply.github.com>
This commit is contained in:
parent
b2995dcb83
commit
9e021f78da
|
|
@ -83,6 +83,7 @@ impl Painter {
|
|||
}
|
||||
|
||||
/// If set, colors will be modified to look like this
|
||||
#[deprecated = "Use `multiply_opacity` instead"]
|
||||
pub fn set_fade_to_color(&mut self, fade_to_color: Option<Color32>) {
|
||||
self.fade_to_color = fade_to_color;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1019,6 +1019,9 @@ pub struct Visuals {
|
|||
|
||||
/// How to display numeric color values.
|
||||
pub numeric_color_space: NumericColorSpace,
|
||||
|
||||
/// How much to modify the alpha of a disabled widget.
|
||||
pub disabled_alpha: f32,
|
||||
}
|
||||
|
||||
impl Visuals {
|
||||
|
|
@ -1054,17 +1057,32 @@ impl Visuals {
|
|||
}
|
||||
|
||||
/// When fading out things, we fade the colors towards this.
|
||||
// TODO(emilk): replace with an alpha
|
||||
#[inline(always)]
|
||||
#[deprecated = "Use disabled_alpha(). Fading is now handled by modifying the alpha channel."]
|
||||
pub fn fade_out_to_color(&self) -> Color32 {
|
||||
self.widgets.noninteractive.weak_bg_fill
|
||||
}
|
||||
|
||||
/// Returned a "grayed out" version of the given color.
|
||||
/// Disabled widgets have their alpha modified by this.
|
||||
#[inline(always)]
|
||||
pub fn disabled_alpha(&self) -> f32 {
|
||||
self.disabled_alpha
|
||||
}
|
||||
|
||||
/// Returns a "disabled" version of the given color.
|
||||
///
|
||||
/// This function modifies the opcacity of the given color.
|
||||
/// If this is undesirable use [`gray_out`](Self::gray_out).
|
||||
#[inline(always)]
|
||||
pub fn disable(&self, color: Color32) -> Color32 {
|
||||
color.gamma_multiply(self.disabled_alpha())
|
||||
}
|
||||
|
||||
/// Returns a "grayed out" version of the given color.
|
||||
#[doc(alias = "grey_out")]
|
||||
#[inline(always)]
|
||||
pub fn gray_out(&self, color: Color32) -> Color32 {
|
||||
crate::ecolor::tint_color_towards(color, self.fade_out_to_color())
|
||||
crate::ecolor::tint_color_towards(color, self.widgets.noninteractive.weak_bg_fill)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1384,6 +1402,7 @@ impl Visuals {
|
|||
image_loading_spinners: true,
|
||||
|
||||
numeric_color_space: NumericColorSpace::GammaByte,
|
||||
disabled_alpha: 0.5,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2063,6 +2082,7 @@ impl Visuals {
|
|||
image_loading_spinners,
|
||||
|
||||
numeric_color_space,
|
||||
disabled_alpha,
|
||||
} = self;
|
||||
|
||||
ui.collapsing("Background Colors", |ui| {
|
||||
|
|
@ -2191,6 +2211,8 @@ impl Visuals {
|
|||
ui.label("Color picker type");
|
||||
numeric_color_space.toggle_button_ui(ui);
|
||||
});
|
||||
|
||||
ui.add(Slider::new(disabled_alpha, 0.0..=1.0).text("Disabled element alpha"));
|
||||
});
|
||||
|
||||
ui.vertical_centered(|ui| reset_button(ui, self, "Reset visuals"));
|
||||
|
|
|
|||
|
|
@ -522,7 +522,7 @@ impl Ui {
|
|||
self.enabled = false;
|
||||
if self.is_visible() {
|
||||
self.painter
|
||||
.set_fade_to_color(Some(self.visuals().fade_out_to_color()));
|
||||
.multiply_opacity(self.visuals().disabled_alpha());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2963,8 +2963,8 @@ impl Ui {
|
|||
|
||||
if is_anything_being_dragged && !can_accept_what_is_being_dragged {
|
||||
// When dragging something else, show that it can't be dropped here:
|
||||
fill = self.visuals().gray_out(fill);
|
||||
stroke.color = self.visuals().gray_out(stroke.color);
|
||||
fill = self.visuals().disable(fill);
|
||||
stroke.color = self.visuals().disable(stroke.color);
|
||||
}
|
||||
|
||||
frame.frame.fill = fill;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8cf6d0b20f127f22d49daefed27fc2d0ca43d645fe1486cf7f6fcbb676bdec82
|
||||
size 179065
|
||||
oid sha256:2849afd01ec3dae797b15893e28908f6b037588b3712fb6dec556edb7b230b5d
|
||||
size 179082
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a0b999914adab3d44c614bdf3b28abd268a4ff6162c5680b43035b3f71cb69bb
|
||||
size 23999
|
||||
oid sha256:6d5f3129e34e22b15245212904e0a3537a0c7e70f1d35fd3e9c784af707038b5
|
||||
size 24018
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0c975c8b646425878b704f32198286010730746caf5d463ca8cbcfe539922816
|
||||
size 99087
|
||||
oid sha256:5d05c74583024825d82f1fe8dbeb2a793e366016e87a639f51d46945831de82a
|
||||
size 99106
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3110fab8444cb41dffe8b27277fa5dafd0d335aaf13dca511bcccc8b53fb25c8
|
||||
size 24046
|
||||
oid sha256:17f7065c47712f140e4a9fd9eed61a7118fe12cd79cf0745642a02921eaa596b
|
||||
size 24065
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f0e3eeca8abb4fba632cef4621d478fb66af1a0f13e099dda9a79420cc2b6301
|
||||
size 115320
|
||||
oid sha256:7e80bf8c79e6e431806c85385a0bd9262796efc0a1e74d431a1b896dde0b8651
|
||||
size 115338
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f90d56d40004f61628e3f66cfac817c426cd18eb4b9c69ea1b3a6fe5e75e3f05
|
||||
size 70354
|
||||
oid sha256:16dc96246f011c6e9304409af7b4084f28e20cd813e44abca73834386e98b9b1
|
||||
size 70373
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c4d6a15094eee5d96a8af5c44ea9d0c962d650ee9b867344c86d1229e526dcb5
|
||||
size 12822
|
||||
oid sha256:26e4828e42f54da24d032f384f8829e42bcebaee072923f277db582f84302911
|
||||
size 12847
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:02abc0cbab97e572218f422f4b167957869d4e2b4b388355444c20148d998015
|
||||
size 35200
|
||||
oid sha256:4a4520aa68d6752992fd2f87090a317e6e5e24b5cdb5ee2e82daf07f9471ca80
|
||||
size 35251
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b567d4038fd73986c80d2bd12197a6df037fde043545993fa9fe4160d0af446c
|
||||
size 54829
|
||||
oid sha256:c33617dfde24071fa65aff2543f22883f5526152fb344997b1877aeb38df72fe
|
||||
size 54848
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:99f64e581b97df6694cb7c85ee7728a955e3c1a851ab660e8b6091eee1885bbe
|
||||
size 9719
|
||||
oid sha256:a573976aacbb629c88c285089fca28ba7998a0c28ecee9f783920d67929a1e2d
|
||||
size 9735
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d39ec25b91f5f5d68305d2cb7cc0285d715fe30ccbd66369efbe7327d1899b52
|
||||
size 10753
|
||||
oid sha256:9fbb9aca2006aeca555c138f1ebdb89409026f1bed48da74cd0fa03dcd8facbe
|
||||
size 10746
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:46d86987ba895ead9b28efcc37e1b4374f34eedebac83d1db9eaa8e5a3202ee3
|
||||
size 13203
|
||||
oid sha256:f74f5ff20b842c1990c50d8a66ab5b34e248786f01b1592485620d31426ce5ae
|
||||
size 13302
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f9151f1c9d8a769ac2143a684cabf5d9ed1e453141fff555da245092003f1df1
|
||||
size 13563
|
||||
oid sha256:df84f3fce07a45a208f6169f0df701b7971fc7d467151870d56d90ce49a2c819
|
||||
size 13522
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e03cf99a3d28f73d4a72c0e616dc54198663b94bf5cffda694cf4eb4dee01be8
|
||||
size 13445
|
||||
oid sha256:ec75c3fccec8d6a72b808aba593f8c289618b6f95db08eb3cdb20a255b9d986e
|
||||
size 13450
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e86a37c7b259a6bad61897545d927d75e8307916dc78d256e4d33c410fcd6876
|
||||
size 7306
|
||||
oid sha256:c7e66a490236b306ce03c504d29490cdadc3708a79e21e3b46d11df8eb22a26b
|
||||
size 7309
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d1a172cfadc91467529e5546e686673be73ba0071a55d55abc7a41fb1d07214d
|
||||
size 11700
|
||||
oid sha256:895914fa37608ff68c5ae7fdd22d0363da26907c78d4980f6bf1ed19f7e5f388
|
||||
size 11697
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0ef91dfedc74cae59099bce32b2e42cb04649e84442e8010282a9c1ff2a7f2c8
|
||||
size 12469
|
||||
oid sha256:0e0c4277eebadb0c350b5110d5ea7ff9292ab2b0231d6b36e9ada3aeefc7c198
|
||||
size 12510
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:1892358a4552af3f529141d314cd18e4cf55a629d870798278a5470e3e0a8a94
|
||||
size 11030
|
||||
oid sha256:ec09e0e3432668c0d08bbba0aa8608c4eefba33d57f2335fdf105d144791406d
|
||||
size 11036
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7300a0b88d4fdb6c1e543bfaf50e8964b2f84aaaf8197267b671d0cf3c8da30a
|
||||
size 7033
|
||||
oid sha256:9353e6d39d309e7a6e6c0a17be819809c2dbea8979e9e73b3c73b67b07124a36
|
||||
size 7031
|
||||
|
|
|
|||
Loading…
Reference in New Issue