1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Add ui.set_enabled(false) to disable all widgets in a Ui

Closes https://github.com/emilk/egui/issues/50
This commit is contained in:
Emil Ernerfeldt
2021-02-07 10:55:45 +01:00
parent d07a17ac6a
commit bca722ddf8
20 changed files with 303 additions and 77 deletions

View File

@@ -682,3 +682,30 @@ impl From<Hsva> for HsvaGamma {
}
}
}
// ----------------------------------------------------------------------------
/// Cheap and ugly.
/// Made for graying out disabled `Ui`:s.
pub fn tint_color_towards(color: Color32, target: Color32) -> Color32 {
let [mut r, mut g, mut b, mut a] = color.to_array();
if a == 0 {
r /= 2;
g /= 2;
b /= 2;
} else if a < 170 {
// Cheapish and looks ok.
// Works for e.g. grid stripes.
let div = (2 * 255 / a as i32) as u8;
r = r / 2 + target.r() / div;
g = g / 2 + target.g() / div;
b = b / 2 + target.b() / div;
a /= 2;
} else {
r = r / 2 + target.r() / 2;
g = g / 2 + target.g() / 2;
b = b / 2 + target.b() / 2;
}
Color32::from_rgba_premultiplied(r, g, b, a)
}

View File

@@ -49,6 +49,7 @@ mod mesh;
pub mod mutex;
mod shadow;
mod shape;
pub mod shape_transform;
pub mod stats;
mod stroke;
pub mod tessellator;

View File

@@ -0,0 +1,35 @@
use crate::*;
pub fn adjust_colors(shape: &mut Shape, adjust_color: &impl Fn(&mut Color32)) {
match shape {
Shape::Noop => {}
Shape::Vec(shapes) => {
for shape in shapes {
adjust_colors(shape, adjust_color)
}
}
Shape::Circle { fill, stroke, .. } => {
adjust_color(fill);
adjust_color(&mut stroke.color);
}
Shape::LineSegment { stroke, .. } => {
adjust_color(&mut stroke.color);
}
Shape::Path { fill, stroke, .. } => {
adjust_color(fill);
adjust_color(&mut stroke.color);
}
Shape::Rect { fill, stroke, .. } => {
adjust_color(fill);
adjust_color(&mut stroke.color);
}
Shape::Text { color, .. } => {
adjust_color(color);
}
Shape::Mesh(mesh) => {
for v in &mut mesh.vertices {
adjust_color(&mut v.color);
}
}
}
}