diff --git a/egui/src/containers/resize.rs b/egui/src/containers/resize.rs index 99869842..d4bf8842 100644 --- a/egui/src/containers/resize.rs +++ b/egui/src/containers/resize.rs @@ -305,12 +305,12 @@ impl Resize { if ui.ctx().style().visuals.debug_resize { ui.ctx().debug_painter().debug_rect( Rect::from_min_size(content_ui.min_rect().left_top(), state.desired_size), - color::GREEN, + Color32::GREEN, "desired_size", ); ui.ctx().debug_painter().debug_rect( Rect::from_min_size(content_ui.min_rect().left_top(), state.last_content_size), - color::LIGHT_BLUE, + Color32::LIGHT_BLUE, "last_content_size", ); } diff --git a/egui/src/context.rs b/egui/src/context.rs index 04987839..9b31d1f5 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -816,7 +816,7 @@ impl Context { { ui.ctx() .debug_painter() - .debug_rect(area.rect(), color::RED, ""); + .debug_rect(area.rect(), Color32::RED, ""); } } } diff --git a/egui/src/introspection.rs b/egui/src/introspection.rs index c5b96be7..50eff597 100644 --- a/egui/src/introspection.rs +++ b/egui/src/introspection.rs @@ -1,7 +1,7 @@ //! uis for egui types. use crate::{ math::*, - paint::{self, color::WHITE, PaintCmd, Texture, Triangles}, + paint::{self, PaintCmd, Texture, Triangles}, *, }; @@ -21,7 +21,11 @@ impl Texture { let response = ui.allocate_response(size, Sense::hover()); let rect = response.rect; let mut triangles = Triangles::default(); - triangles.add_rect_with_uv(rect, [pos2(0.0, 0.0), pos2(1.0, 1.0)].into(), WHITE); + triangles.add_rect_with_uv( + rect, + [pos2(0.0, 0.0), pos2(1.0, 1.0)].into(), + Color32::WHITE, + ); ui.painter().add(PaintCmd::triangles(triangles)); let (tex_w, tex_h) = (self.width as f32, self.height as f32); @@ -45,7 +49,7 @@ impl Texture { pos2((u + texel_radius) / tex_w, (v + texel_radius) / tex_h), ); let mut triangles = Triangles::default(); - triangles.add_rect_with_uv(zoom_rect, uv_rect, WHITE); + triangles.add_rect_with_uv(zoom_rect, uv_rect, Color32::WHITE); ui.painter().add(PaintCmd::triangles(triangles)); }); } diff --git a/egui/src/layout.rs b/egui/src/layout.rs index f4dcf16c..6055e6d5 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -501,7 +501,7 @@ impl Layout { let cursor = region.cursor; - let color = color::GREEN; + let color = Color32::GREEN; let stroke = Stroke::new(2.0, color); let align; diff --git a/egui/src/lib.rs b/egui/src/lib.rs index d08d590b..e8c55223 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -138,7 +138,7 @@ pub fn warn_if_debug_build(ui: &mut crate::Ui) { ui.label( crate::Label::new("‼ Debug build ‼") .small() - .text_color(crate::color::RED), + .text_color(crate::Color32::RED), ) .on_hover_text("Egui was compiled with debug assertions enabled."); } diff --git a/egui/src/menu.rs b/egui/src/menu.rs index 8b6629ff..dc78cdf3 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -15,7 +15,7 @@ //! } //! ``` -use crate::{color::TRANSPARENT, paint::Stroke, widgets::*, *}; +use crate::{paint::Stroke, widgets::*, *}; /// What is saved between frames. #[derive(Clone, Copy, Debug, Default)] @@ -44,11 +44,11 @@ pub fn bar(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Respo ui.horizontal(|ui| { let mut style = ui.style().clone(); style.spacing.button_padding = vec2(2.0, 0.0); - // style.visuals.widgets.active.bg_fill = TRANSPARENT; + // style.visuals.widgets.active.bg_fill = Color32::TRANSPARENT; style.visuals.widgets.active.bg_stroke = Stroke::none(); - // style.visuals.widgets.hovered.bg_fill = TRANSPARENT; + // style.visuals.widgets.hovered.bg_fill = Color32::TRANSPARENT; style.visuals.widgets.hovered.bg_stroke = Stroke::none(); - style.visuals.widgets.inactive.bg_fill = TRANSPARENT; + style.visuals.widgets.inactive.bg_fill = Color32::TRANSPARENT; style.visuals.widgets.inactive.bg_stroke = Stroke::none(); ui.set_style(style); @@ -104,11 +104,11 @@ fn menu_impl<'c>( frame.show(ui, |ui| { let mut style = ui.style().clone(); style.spacing.button_padding = vec2(2.0, 0.0); - // style.visuals.widgets.active.bg_fill = TRANSPARENT; + // style.visuals.widgets.active.bg_fill = Color32::TRANSPARENT; style.visuals.widgets.active.bg_stroke = Stroke::none(); - // style.visuals.widgets.hovered.bg_fill = TRANSPARENT; + // style.visuals.widgets.hovered.bg_fill = Color32::TRANSPARENT; style.visuals.widgets.hovered.bg_stroke = Stroke::none(); - style.visuals.widgets.inactive.bg_fill = TRANSPARENT; + style.visuals.widgets.inactive.bg_fill = Color32::TRANSPARENT; style.visuals.widgets.inactive.bg_stroke = Stroke::none(); ui.set_style(style); ui.with_layout(Layout::top_down_justified(Align::left()), add_contents); diff --git a/egui/src/paint/color.rs b/egui/src/paint/color.rs index a4a6c8a3..838e74f1 100644 --- a/egui/src/paint/color.rs +++ b/egui/src/paint/color.rs @@ -24,17 +24,22 @@ impl std::ops::IndexMut for Color32 { } } -// TODO: remove ? #[deprecated = "Replaced by Color32::from_rgb… family of functions."] pub const fn srgba(r: u8, g: u8, b: u8, a: u8) -> Color32 { Color32::from_rgba_premultiplied(r, g, b, a) } impl Color32 { - #[deprecated = "Use from_rgb(..), from_rgba_premultiplied(..) or from_srgba_unmultiplied(..)"] - pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self { - Self([r, g, b, a]) - } + pub const TRANSPARENT: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 0); + pub const BLACK: Color32 = Color32::from_rgb(0, 0, 0); + pub const LIGHT_GRAY: Color32 = Color32::from_rgb(220, 220, 220); + pub const GRAY: Color32 = Color32::from_rgb(160, 160, 160); + pub const WHITE: Color32 = Color32::from_rgb(255, 255, 255); + pub const RED: Color32 = Color32::from_rgb(255, 0, 0); + pub const GREEN: Color32 = Color32::from_rgb(0, 255, 0); + pub const BLUE: Color32 = Color32::from_rgb(0, 0, 255); + pub const YELLOW: Color32 = Color32::from_rgb(255, 255, 0); + pub const LIGHT_BLUE: Color32 = Color32::from_rgb(140, 160, 255); pub const fn from_rgb(r: u8, g: u8, b: u8) -> Self { Self([r, g, b, 255]) @@ -60,6 +65,11 @@ impl Color32 { } } + #[deprecated = "Use from_rgb(..), from_rgba_premultiplied(..) or from_srgba_unmultiplied(..)"] + pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self { + Self([r, g, b, a]) + } + pub const fn gray(l: u8) -> Self { Self([l, l, l, 255]) } @@ -109,19 +119,6 @@ impl Color32 { // ---------------------------------------------------------------------------- -pub const TRANSPARENT: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 0); -pub const BLACK: Color32 = Color32::from_rgb(0, 0, 0); -pub const LIGHT_GRAY: Color32 = Color32::from_rgb(220, 220, 220); -pub const GRAY: Color32 = Color32::from_rgb(160, 160, 160); -pub const WHITE: Color32 = Color32::from_rgb(255, 255, 255); -pub const RED: Color32 = Color32::from_rgb(255, 0, 0); -pub const GREEN: Color32 = Color32::from_rgb(0, 255, 0); -pub const BLUE: Color32 = Color32::from_rgb(0, 0, 255); -pub const YELLOW: Color32 = Color32::from_rgb(255, 255, 0); -pub const LIGHT_BLUE: Color32 = Color32::from_rgb(140, 160, 255); - -// ---------------------------------------------------------------------------- - /// 0-1 linear space `RGBA` color with premultiplied alpha. #[derive(Clone, Copy, Debug, Default, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] diff --git a/egui/src/paint/command.rs b/egui/src/paint/command.rs index b5b0cdb9..e702b587 100644 --- a/egui/src/paint/command.rs +++ b/egui/src/paint/command.rs @@ -204,7 +204,7 @@ pub struct Stroke { impl Stroke { pub fn none() -> Self { - Self::new(0.0, crate::color::TRANSPARENT) + Self::new(0.0, Color32::TRANSPARENT) } pub fn new(width: impl Into, color: impl Into) -> Self { diff --git a/egui/src/paint/tessellator.rs b/egui/src/paint/tessellator.rs index 0d5aad49..82727b97 100644 --- a/egui/src/paint/tessellator.rs +++ b/egui/src/paint/tessellator.rs @@ -7,7 +7,7 @@ use { super::{ - color::{self, Color32, Rgba, TRANSPARENT}, + color::{Color32, Rgba}, *, }, crate::math::*, @@ -479,7 +479,7 @@ fn fill_closed_path( options: TessellationOptions, out: &mut Triangles, ) { - if color == color::TRANSPARENT { + if color == Color32::TRANSPARENT { return; } @@ -487,7 +487,7 @@ fn fill_closed_path( if options.anti_alias { out.reserve_triangles(3 * n as usize); out.reserve_vertices(2 * n as usize); - let color_outer = color::TRANSPARENT; + let color_outer = Color32::TRANSPARENT; let idx_inner = out.vertices.len() as u32; let idx_outer = idx_inner + 1; for i in 2..n { @@ -525,7 +525,7 @@ fn stroke_path( options: TessellationOptions, out: &mut Triangles, ) { - if stroke.width <= 0.0 || stroke.color == color::TRANSPARENT { + if stroke.width <= 0.0 || stroke.color == Color32::TRANSPARENT { return; } @@ -534,7 +534,7 @@ fn stroke_path( if options.anti_alias { let color_inner = stroke.color; - let color_outer = color::TRANSPARENT; + let color_outer = Color32::TRANSPARENT; let thin_line = stroke.width <= options.aa_size; if thin_line { @@ -547,7 +547,7 @@ fn stroke_path( // Fade out as it gets thinner: let color_inner = mul_color(color_inner, stroke.width / options.aa_size); - if color_inner == color::TRANSPARENT { + if color_inner == Color32::TRANSPARENT { return; } @@ -639,7 +639,7 @@ fn stroke_path( // Fade out thin lines rather than making them thinner let radius = options.aa_size / 2.0; let color = mul_color(stroke.color, stroke.width / options.aa_size); - if color == color::TRANSPARENT { + if color == Color32::TRANSPARENT { return; } for p in path { @@ -756,7 +756,7 @@ impl Tessellator { path.add_open_points(&points); } - if fill != TRANSPARENT { + if fill != Color32::TRANSPARENT { debug_assert!( closed, "You asked to fill a path that is not closed. That makes no sense." @@ -831,7 +831,7 @@ impl Tessellator { color: Color32, out: &mut Triangles, ) { - if color == TRANSPARENT { + if color == Color32::TRANSPARENT { return; } galley.sanity_check(); diff --git a/egui/src/painter.rs b/egui/src/painter.rs index 7f7c002a..fab13a93 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -1,6 +1,5 @@ use crate::{ align::{anchor_rect, Align, LEFT_TOP}, - color, layers::PaintCmdIdx, math::{Pos2, Rect, Vec2}, paint::{Fonts, Galley, PaintCmd, Stroke, TextStyle}, @@ -149,9 +148,9 @@ impl Painter { rect: frame_rect, corner_radius: 0.0, fill: Color32::black_alpha(240), - stroke: Stroke::new(1.0, color::RED), + stroke: Stroke::new(1.0, Color32::RED), }); - self.galley(rect.min, galley, text_style, color::RED); + self.galley(rect.min, galley, text_style, Color32::RED); frame_rect } } diff --git a/egui/src/style.rs b/egui/src/style.rs index 19ced1f0..417f464f 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -301,10 +301,10 @@ impl Default for Widgets { Self { active: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.10, 0.5).into(), - bg_stroke: Stroke::new(2.0, WHITE), + bg_stroke: Stroke::new(2.0, Color32::WHITE), corner_radius: 4.0, fg_fill: Color32::from_rgb(120, 120, 200), - fg_stroke: Stroke::new(2.0, WHITE), + fg_stroke: Stroke::new(2.0, Color32::WHITE), }, hovered: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.06, 0.5).into(), diff --git a/egui/src/ui.rs b/egui/src/ui.rs index e7cd2466..f3ca243c 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -461,7 +461,7 @@ impl Ui { /// # let mut ui = egui::Ui::__test(); /// let response = ui.allocate_response(egui::vec2(100.0, 200.0), egui::Sense::click()); /// if response.clicked { /* … */ } - /// ui.painter().rect_stroke(response.rect, 0.0, (1.0, egui::color::WHITE)); + /// ui.painter().rect_stroke(response.rect, 0.0, (1.0, egui::Color32::WHITE)); /// ``` pub fn allocate_response(&mut self, desired_size: Vec2, sense: Sense) -> Response { let (id, rect) = self.allocate_space(desired_size); @@ -500,7 +500,8 @@ impl Ui { let debug_expand_height = self.style().visuals.debug_expand_height; if (debug_expand_width && too_wide) || (debug_expand_height && too_high) { - self.painter.rect_stroke(rect, 0.0, (1.0, LIGHT_BLUE)); + self.painter + .rect_stroke(rect, 0.0, (1.0, Color32::LIGHT_BLUE)); let color = color::Color32::from_rgb(200, 0, 0); let width = 2.5; diff --git a/egui/src/widgets/color_picker.rs b/egui/src/widgets/color_picker.rs index 524b38f4..3da236a5 100644 --- a/egui/src/widgets/color_picker.rs +++ b/egui/src/widgets/color_picker.rs @@ -7,9 +7,9 @@ use crate::{ fn contrast_color(color: impl Into) -> Color32 { if color.into().intensity() < 0.5 { - color::WHITE + Color32::WHITE } else { - color::BLACK + Color32::BLACK } } diff --git a/egui/src/widgets/image.rs b/egui/src/widgets/image.rs index 85823b49..640613a9 100644 --- a/egui/src/widgets/image.rs +++ b/egui/src/widgets/image.rs @@ -18,7 +18,7 @@ impl Image { uv: Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), desired_size: desired_size.into(), bg_fill: Default::default(), - tint: color::WHITE, + tint: Color32::WHITE, } } diff --git a/egui_demo_lib/src/apps/color_test.rs b/egui_demo_lib/src/apps/color_test.rs index 09c7ee25..27eb4174 100644 --- a/egui_demo_lib/src/apps/color_test.rs +++ b/egui_demo_lib/src/apps/color_test.rs @@ -3,6 +3,12 @@ use std::collections::HashMap; const GRADIENT_SIZE: Vec2 = vec2(256.0, 24.0); +const BLACK: Color32 = Color32::BLACK; +const GREEN: Color32 = Color32::GREEN; +const RED: Color32 = Color32::RED; +const TRANSPARENT: Color32 = Color32::TRANSPARENT; +const WHITE: Color32 = Color32::WHITE; + #[derive(serde::Deserialize, serde::Serialize)] pub struct ColorTest { #[serde(skip)] @@ -32,7 +38,7 @@ impl epi::App for ColorTest { egui::CentralPanel::default().show(ctx, |ui| { if frame.is_web() { ui.colored_label( - egui::color::RED, + RED, "NOTE: The current WebGL backend does NOT pass the color test!", ); ui.separator(); diff --git a/egui_demo_lib/src/apps/demo/demo_window.rs b/egui_demo_lib/src/apps/demo/demo_window.rs index b414c235..8ea63040 100644 --- a/egui_demo_lib/src/apps/demo/demo_window.rs +++ b/egui_demo_lib/src/apps/demo/demo_window.rs @@ -213,7 +213,7 @@ impl BoxPainting { response.rect, self.corner_radius, Color32::gray(64), - Stroke::new(self.stroke_width, WHITE), + Stroke::new(self.stroke_width, Color32::WHITE), ); } }); @@ -388,7 +388,11 @@ impl Tree { } fn children_ui(&mut self, ui: &mut Ui, depth: usize) -> Action { - if depth > 0 && ui.add(Button::new("delete").text_color(color::RED)).clicked { + if depth > 0 + && ui + .add(Button::new("delete").text_color(Color32::RED)) + .clicked + { return Action::Delete; } diff --git a/egui_demo_lib/src/apps/demo/painting.rs b/egui_demo_lib/src/apps/demo/painting.rs index 8543a29a..d41d282b 100644 --- a/egui_demo_lib/src/apps/demo/painting.rs +++ b/egui_demo_lib/src/apps/demo/painting.rs @@ -11,7 +11,7 @@ impl Default for Painting { fn default() -> Self { Self { lines: Default::default(), - stroke: Stroke::new(1.0, color::LIGHT_BLUE), + stroke: Stroke::new(1.0, Color32::LIGHT_BLUE), } } } diff --git a/egui_demo_lib/src/apps/demo/scrolls.rs b/egui_demo_lib/src/apps/demo/scrolls.rs index bf004275..44a693ce 100644 --- a/egui_demo_lib/src/apps/demo/scrolls.rs +++ b/egui_demo_lib/src/apps/demo/scrolls.rs @@ -48,7 +48,7 @@ impl Scrolls { const ALIGNS: [Align; 3] = [Align::Min, Align::Center, Align::Max]; ui.columns(3, |cols| { for (i, col) in cols.iter_mut().enumerate() { - col.colored_label(WHITE, TITLES[i]); + col.colored_label(Color32::WHITE, TITLES[i]); let mut scroll_area = ScrollArea::from_max_height(200.0).id_source(i); if scroll_offset { self.tracking = false; @@ -62,7 +62,8 @@ impl Scrolls { ui.vertical(|ui| { for item in 1..=50 { if self.tracking && item == self.track_item { - let response = ui.colored_label(YELLOW, format!("Item {}", item)); + let response = + ui.colored_label(Color32::YELLOW, format!("Item {}", item)); response.scroll_to_me(ALIGNS[i]); } else { ui.label(format!("Item {}", item)); @@ -80,7 +81,10 @@ impl Scrolls { ui.min_rect().height() - ui.clip_rect().height() + 2.0 * margin, ) }); - col.colored_label(WHITE, format!("{:.0}/{:.0}", current_scroll, max_scroll)); + col.colored_label( + Color32::WHITE, + format!("{:.0}/{:.0}", current_scroll, max_scroll), + ); } }); } diff --git a/egui_demo_lib/src/apps/http_app.rs b/egui_demo_lib/src/apps/http_app.rs index f9dfd66b..61d917e3 100644 --- a/egui_demo_lib/src/apps/http_app.rs +++ b/egui_demo_lib/src/apps/http_app.rs @@ -100,7 +100,7 @@ impl epi::App for HttpApp { } Err(error) => { // This should only happen if the fetch API isn't available or something similar. - ui.add(egui::Label::new(error).text_color(egui::color::RED)); + ui.add(egui::Label::new(error).text_color(egui::Color32::RED)); } } } diff --git a/egui_demo_lib/src/frame_history.rs b/egui_demo_lib/src/frame_history.rs index 022b8cb5..097d988e 100644 --- a/egui_demo_lib/src/frame_history.rs +++ b/egui_demo_lib/src/frame_history.rs @@ -95,7 +95,7 @@ impl FrameHistory { align::LEFT_BOTTOM, text, TextStyle::Monospace, - color::WHITE, + Color32::WHITE, )); } }