1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Use Rgba (4xf32) instead of Color32 in all interfaces

This simplifies a few things, but some benchmarks gets worse,
probably due to the increased memory use (and thus more cache misses).

I don't plan to merge this, but leave it here as an experiment
This commit is contained in:
Emil Ernerfeldt
2021-08-15 20:15:14 +02:00
parent 96c45716be
commit 5dd68337c4
42 changed files with 285 additions and 371 deletions

View File

@@ -303,7 +303,7 @@ fn vertex_gradient(ui: &mut Ui, bg_fill: Color32, gradient: &Gradient) -> Respon
let (rect, response) = ui.allocate_at_least(GRADIENT_SIZE, Sense::hover());
if bg_fill != Default::default() {
let mut mesh = Mesh::default();
mesh.add_colored_rect(rect, bg_fill);
mesh.add_colored_rect(rect, bg_fill.into());
ui.painter().add(Shape::mesh(mesh));
}
{
@@ -313,8 +313,8 @@ fn vertex_gradient(ui: &mut Ui, bg_fill: Color32, gradient: &Gradient) -> Respon
for (i, &color) in gradient.0.iter().enumerate() {
let t = i as f32 / (n as f32 - 1.0);
let x = lerp(rect.x_range(), t);
mesh.colored_vertex(pos2(x, rect.top()), color);
mesh.colored_vertex(pos2(x, rect.bottom()), color);
mesh.colored_vertex(pos2(x, rect.top()), color.into());
mesh.colored_vertex(pos2(x, rect.bottom()), color.into());
if i < n - 1 {
let i = i as u32;
mesh.add_triangle(2 * i, 2 * i + 1, 2 * i + 2);
@@ -333,9 +333,11 @@ impl Gradient {
pub fn one_color(srgba: Color32) -> Self {
Self(vec![srgba, srgba])
}
pub fn texture_gradient(left: Color32, right: Color32) -> Self {
Self(vec![left, right])
}
pub fn ground_truth_linear_gradient(left: Color32, right: Color32) -> Self {
let left = Rgba::from(left);
let right = Rgba::from(right);
@@ -350,6 +352,7 @@ impl Gradient {
.collect(),
)
}
/// This is how a bad person blends `sRGBA`
pub fn ground_truth_bad_srgba_gradient(left: Color32, right: Color32) -> Self {
let n = 255;

View File

@@ -199,7 +199,7 @@ impl DemoWindows {
// Native: WrapApp uses a transparent window, so let's show that off:
// NOTE: the OS compositor assumes "normal" blending, so we need to hack it:
let [r, g, b, _] = fill.to_array();
fill = egui::Color32::from_rgba_premultiplied(r, g, b, 180);
fill = egui::Rgba::from_rgba_premultiplied(r, g, b, 0.70);
}
let frame = egui::Frame::none().fill(fill);
egui::CentralPanel::default().frame(frame).show(ctx, |_| {});

View File

@@ -59,8 +59,8 @@ pub fn drop_target<R>(
let mut stroke = style.bg_stroke;
if is_being_dragged && !can_accept_what_is_being_dragged {
// gray out:
fill = color::tint_color_towards(fill, ui.visuals().window_fill());
stroke.color = color::tint_color_towards(stroke.color, ui.visuals().window_fill());
fill = color::tint_rgba_towards(fill, ui.visuals().window_fill());
stroke.color = color::tint_rgba_towards(stroke.color, ui.visuals().window_fill());
}
ui.painter().set(

View File

@@ -363,7 +363,7 @@ impl Tree {
fn children_ui(&mut self, ui: &mut Ui, depth: usize) -> Action {
if depth > 0
&& ui
.add(Button::new("delete").text_color(Color32::RED))
.add(Button::new("delete").text_color(Rgba::RED))
.clicked()
{
return Action::Delete;