mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Rename Srgba to Color32
This commit is contained in:
@@ -62,7 +62,7 @@ impl ColorTest {
|
||||
ui.label("Use a color picker to ensure this color is (255, 165, 0) / #ffa500");
|
||||
ui.wrap(|ui| {
|
||||
ui.style_mut().spacing.item_spacing.y = 0.0; // No spacing between gradients
|
||||
let g = Gradient::one_color(Srgba::from_rgb(255, 165, 0));
|
||||
let g = Gradient::one_color(Color32::from_rgb(255, 165, 0));
|
||||
self.vertex_gradient(ui, "orange rgb(255, 165, 0) - vertex", WHITE, &g);
|
||||
self.tex_gradient(
|
||||
ui,
|
||||
@@ -91,13 +91,13 @@ impl ColorTest {
|
||||
ui.label(" vertex color =");
|
||||
});
|
||||
{
|
||||
let g = Gradient::one_color(Srgba::from(tex_color * vertex_color));
|
||||
let g = Gradient::one_color(Color32::from(tex_color * vertex_color));
|
||||
self.vertex_gradient(ui, "Ground truth (vertices)", WHITE, &g);
|
||||
self.tex_gradient(ui, tex_allocator, "Ground truth (texture)", WHITE, &g);
|
||||
}
|
||||
if let Some(tex_allocator) = &mut tex_allocator {
|
||||
ui.horizontal(|ui| {
|
||||
let g = Gradient::one_color(Srgba::from(tex_color));
|
||||
let g = Gradient::one_color(Color32::from(tex_color));
|
||||
let tex = self.tex_mngr.get(*tex_allocator, &g);
|
||||
let texel_offset = 0.5 / (g.0.len() as f32);
|
||||
let uv =
|
||||
@@ -146,7 +146,7 @@ impl ColorTest {
|
||||
ui,
|
||||
tex_allocator,
|
||||
RED,
|
||||
(TRANSPARENT, Srgba::from_rgba_premultiplied(0, 0, 255, 0)),
|
||||
(TRANSPARENT, Color32::from_rgba_premultiplied(0, 0, 255, 0)),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
@@ -156,8 +156,8 @@ impl ColorTest {
|
||||
&mut self,
|
||||
ui: &mut Ui,
|
||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||
bg_fill: Srgba,
|
||||
(left, right): (Srgba, Srgba),
|
||||
bg_fill: Color32,
|
||||
(left, right): (Color32, Color32),
|
||||
) {
|
||||
let is_opaque = left.is_opaque() && right.is_opaque();
|
||||
|
||||
@@ -251,7 +251,7 @@ impl ColorTest {
|
||||
ui: &mut Ui,
|
||||
tex_allocator: &mut Option<&mut dyn epi::TextureAllocator>,
|
||||
label: &str,
|
||||
bg_fill: Srgba,
|
||||
bg_fill: Color32,
|
||||
gradient: &Gradient,
|
||||
) {
|
||||
if !self.texture_gradients {
|
||||
@@ -272,7 +272,7 @@ impl ColorTest {
|
||||
}
|
||||
}
|
||||
|
||||
fn vertex_gradient(&mut self, ui: &mut Ui, label: &str, bg_fill: Srgba, gradient: &Gradient) {
|
||||
fn vertex_gradient(&mut self, ui: &mut Ui, label: &str, bg_fill: Color32, gradient: &Gradient) {
|
||||
if !self.vertex_gradients {
|
||||
return;
|
||||
}
|
||||
@@ -286,7 +286,7 @@ impl ColorTest {
|
||||
}
|
||||
}
|
||||
|
||||
fn vertex_gradient(ui: &mut Ui, bg_fill: Srgba, gradient: &Gradient) -> Response {
|
||||
fn vertex_gradient(ui: &mut Ui, bg_fill: Color32, gradient: &Gradient) -> Response {
|
||||
use egui::paint::*;
|
||||
let response = ui.allocate_response(GRADIENT_SIZE, Sense::hover());
|
||||
if bg_fill != Default::default() {
|
||||
@@ -315,16 +315,16 @@ fn vertex_gradient(ui: &mut Ui, bg_fill: Srgba, gradient: &Gradient) -> Response
|
||||
}
|
||||
|
||||
#[derive(Clone, Hash, PartialEq, Eq)]
|
||||
struct Gradient(pub Vec<Srgba>);
|
||||
struct Gradient(pub Vec<Color32>);
|
||||
|
||||
impl Gradient {
|
||||
pub fn one_color(srgba: Srgba) -> Self {
|
||||
pub fn one_color(srgba: Color32) -> Self {
|
||||
Self(vec![srgba, srgba])
|
||||
}
|
||||
pub fn texture_gradient(left: Srgba, right: Srgba) -> Self {
|
||||
pub fn texture_gradient(left: Color32, right: Color32) -> Self {
|
||||
Self(vec![left, right])
|
||||
}
|
||||
pub fn ground_truth_linear_gradient(left: Srgba, right: Srgba) -> Self {
|
||||
pub fn ground_truth_linear_gradient(left: Color32, right: Color32) -> Self {
|
||||
let left = Rgba::from(left);
|
||||
let right = Rgba::from(right);
|
||||
|
||||
@@ -333,19 +333,19 @@ impl Gradient {
|
||||
(0..=n)
|
||||
.map(|i| {
|
||||
let t = i as f32 / n as f32;
|
||||
Srgba::from(lerp(left..=right, t))
|
||||
Color32::from(lerp(left..=right, t))
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
/// This is how a bad person blends `sRGBA`
|
||||
pub fn ground_truth_bad_srgba_gradient(left: Srgba, right: Srgba) -> Self {
|
||||
pub fn ground_truth_bad_srgba_gradient(left: Color32, right: Color32) -> Self {
|
||||
let n = 255;
|
||||
Self(
|
||||
(0..=n)
|
||||
.map(|i| {
|
||||
let t = i as f32 / n as f32;
|
||||
Srgba::from_rgba_premultiplied(
|
||||
Color32::from_rgba_premultiplied(
|
||||
lerp((left[0] as f32)..=(right[0] as f32), t).round() as u8, // Don't ever do this please!
|
||||
lerp((left[1] as f32)..=(right[1] as f32), t).round() as u8, // Don't ever do this please!
|
||||
lerp((left[2] as f32)..=(right[2] as f32), t).round() as u8, // Don't ever do this please!
|
||||
@@ -357,20 +357,20 @@ impl Gradient {
|
||||
}
|
||||
|
||||
/// Do premultiplied alpha-aware blending of the gradient on top of the fill color
|
||||
pub fn with_bg_fill(self, bg: Srgba) -> Self {
|
||||
pub fn with_bg_fill(self, bg: Color32) -> Self {
|
||||
let bg = Rgba::from(bg);
|
||||
Self(
|
||||
self.0
|
||||
.into_iter()
|
||||
.map(|fg| {
|
||||
let fg = Rgba::from(fg);
|
||||
Srgba::from(bg * (1.0 - fg.a()) + fg)
|
||||
Color32::from(bg * (1.0 - fg.a()) + fg)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn to_pixel_row(&self) -> Vec<Srgba> {
|
||||
pub fn to_pixel_row(&self) -> Vec<Color32> {
|
||||
self.0.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ impl super::View for DancingStrings {
|
||||
let thickness = 10.0 / mode;
|
||||
cmds.push(paint::PaintCmd::line(
|
||||
points,
|
||||
Stroke::new(thickness, Srgba::additive_luminance(196)),
|
||||
Stroke::new(thickness, Color32::additive_luminance(196)),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ impl DemoWindow {
|
||||
let painter = ui.painter();
|
||||
let c = response.rect.center();
|
||||
let r = response.rect.width() / 2.0 - 1.0;
|
||||
let color = Srgba::gray(128);
|
||||
let color = Color32::gray(128);
|
||||
let stroke = Stroke::new(1.0, color);
|
||||
painter.circle_stroke(c, r, stroke);
|
||||
painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke);
|
||||
@@ -212,7 +212,7 @@ impl BoxPainting {
|
||||
ui.painter().rect(
|
||||
response.rect,
|
||||
self.corner_radius,
|
||||
Srgba::gray(64),
|
||||
Color32::gray(64),
|
||||
Stroke::new(self.stroke_width, WHITE),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct Widgets {
|
||||
radio: Enum,
|
||||
sliders: super::Sliders,
|
||||
angle: f32,
|
||||
color: Srgba,
|
||||
color: Color32,
|
||||
single_line_text_input: String,
|
||||
multiline_text_input: String,
|
||||
toggle_switch: bool,
|
||||
|
||||
@@ -129,7 +129,7 @@ impl FractalClock {
|
||||
];
|
||||
|
||||
let scale = self.zoom * rect.width().min(rect.height());
|
||||
let paint_line = |points: [Pos2; 2], color: Srgba, width: f32| {
|
||||
let paint_line = |points: [Pos2; 2], color: Color32, width: f32| {
|
||||
let line = [
|
||||
rect.center() + scale * points[0].to_vec2(),
|
||||
rect.center() + scale * points[1].to_vec2(),
|
||||
@@ -161,7 +161,7 @@ impl FractalClock {
|
||||
for (i, hand) in hands.iter().enumerate() {
|
||||
let center = pos2(0.0, 0.0);
|
||||
let end = center + hand.vec;
|
||||
paint_line([center, end], Srgba::additive_luminance(255), width);
|
||||
paint_line([center, end], Color32::additive_luminance(255), width);
|
||||
if i < 2 {
|
||||
nodes.push(Node {
|
||||
pos: end,
|
||||
@@ -191,7 +191,7 @@ impl FractalClock {
|
||||
};
|
||||
paint_line(
|
||||
[a.pos, b.pos],
|
||||
Srgba::additive_luminance(luminance_u8),
|
||||
Color32::additive_luminance(luminance_u8),
|
||||
width,
|
||||
);
|
||||
new_nodes.push(b);
|
||||
|
||||
@@ -239,7 +239,7 @@ impl ColoredText {
|
||||
ui.style_mut().spacing.item_spacing.x = 0.0;
|
||||
for (style, range) in line {
|
||||
let fg = style.foreground;
|
||||
let text_color = egui::Srgba::from_rgb(fg.r, fg.g, fg.b);
|
||||
let text_color = egui::Color32::from_rgb(fg.r, fg.g, fg.b);
|
||||
ui.add(egui::Label::new(range).monospace().text_color(text_color));
|
||||
}
|
||||
});
|
||||
@@ -277,7 +277,7 @@ impl TexMngr {
|
||||
|
||||
struct Image {
|
||||
size: (usize, usize),
|
||||
pixels: Vec<egui::Srgba>,
|
||||
pixels: Vec<egui::Color32>,
|
||||
}
|
||||
|
||||
impl Image {
|
||||
@@ -290,7 +290,7 @@ impl Image {
|
||||
assert_eq!(size.0 * size.1 * 4, pixels.len());
|
||||
let pixels = pixels
|
||||
.chunks(4)
|
||||
.map(|p| egui::Srgba::from_rgba_unmultiplied(p[0], p[1], p[2], p[3]))
|
||||
.map(|p| egui::Color32::from_rgba_unmultiplied(p[0], p[1], p[2], p[3]))
|
||||
.collect();
|
||||
|
||||
Some(Image { size, pixels })
|
||||
|
||||
@@ -78,7 +78,7 @@ impl FrameHistory {
|
||||
}];
|
||||
|
||||
let rect = rect.shrink(4.0);
|
||||
let line_stroke = Stroke::new(1.0, Srgba::additive_luminance(128));
|
||||
let line_stroke = Stroke::new(1.0, Color32::additive_luminance(128));
|
||||
|
||||
if let Some(mouse_pos) = ui.input().mouse.pos {
|
||||
if rect.contains(mouse_pos) {
|
||||
@@ -100,7 +100,7 @@ impl FrameHistory {
|
||||
}
|
||||
}
|
||||
|
||||
let circle_color = Srgba::additive_luminance(196);
|
||||
let circle_color = Color32::additive_luminance(196);
|
||||
let radius = 2.0;
|
||||
let right_side_time = ui.input().time; // Time at right side of screen
|
||||
|
||||
|
||||
Reference in New Issue
Block a user