diff --git a/egui/src/containers/frame.rs b/egui/src/containers/frame.rs index a81710bc..d5e75517 100644 --- a/egui/src/containers/frame.rs +++ b/egui/src/containers/frame.rs @@ -11,7 +11,7 @@ pub struct Frame { pub margin: Vec2, pub corner_radius: f32, pub shadow: Shadow, - pub fill: Color32, + pub fill: Rgba, pub stroke: Stroke, } @@ -85,7 +85,7 @@ impl Frame { Self { margin: Vec2::new(10.0, 10.0), corner_radius: style.visuals.widgets.noninteractive.corner_radius, - fill: Color32::from_black_alpha(250), + fill: Color32::from_black_alpha(250).into(), stroke: style.visuals.window_stroke(), ..Default::default() } @@ -93,7 +93,7 @@ impl Frame { } impl Frame { - pub fn fill(mut self, fill: Color32) -> Self { + pub fn fill(mut self, fill: Rgba) -> Self { self.fill = fill; self } @@ -120,9 +120,9 @@ impl Frame { } pub fn multiply_with_opacity(mut self, opacity: f32) -> Self { - self.fill = self.fill.linear_multiply(opacity); - self.stroke.color = self.stroke.color.linear_multiply(opacity); - self.shadow.color = self.shadow.color.linear_multiply(opacity); + self.fill = self.fill * opacity; + self.stroke.color = self.stroke.color * opacity; + self.shadow.color = self.shadow.color * opacity; self } } diff --git a/egui/src/containers/resize.rs b/egui/src/containers/resize.rs index 2450ad27..e118ef37 100644 --- a/egui/src/containers/resize.rs +++ b/egui/src/containers/resize.rs @@ -303,12 +303,12 @@ impl Resize { if ui.ctx().style().debug.show_resize { ui.ctx().debug_painter().debug_rect( Rect::from_min_size(content_ui.min_rect().left_top(), state.desired_size), - Color32::GREEN, + Rgba::GREEN, "desired_size", ); ui.ctx().debug_painter().debug_rect( Rect::from_min_size(content_ui.min_rect().left_top(), state.last_content_size), - Color32::LIGHT_BLUE, + Rgba::LIGHT_BLUE, "last_content_size", ); } diff --git a/egui/src/context.rs b/egui/src/context.rs index 2ae81b47..ae3da2e3 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -888,7 +888,7 @@ impl Context { { ui.ctx() .debug_painter() - .debug_rect(area.rect(), Color32::RED, ""); + .debug_rect(area.rect(), Rgba::RED, ""); } } } diff --git a/egui/src/introspection.rs b/egui/src/introspection.rs index af5d2bff..01ae21b7 100644 --- a/egui/src/introspection.rs +++ b/egui/src/introspection.rs @@ -20,11 +20,7 @@ impl Widget for &epaint::Texture { } let (rect, response) = ui.allocate_at_least(size, Sense::hover()); let mut mesh = Mesh::default(); - mesh.add_rect_with_uv( - rect, - [pos2(0.0, 0.0), pos2(1.0, 1.0)].into(), - Color32::WHITE, - ); + mesh.add_rect_with_uv(rect, [pos2(0.0, 0.0), pos2(1.0, 1.0)].into(), Rgba::WHITE); ui.painter().add(Shape::mesh(mesh)); let (tex_w, tex_h) = (self.width as f32, self.height as f32); @@ -46,7 +42,7 @@ impl Widget for &epaint::Texture { pos2((u + texel_radius) / tex_w, (v + texel_radius) / tex_h), ); let mut mesh = Mesh::default(); - mesh.add_rect_with_uv(zoom_rect, uv_rect, Color32::WHITE); + mesh.add_rect_with_uv(zoom_rect, uv_rect, Rgba::WHITE); ui.painter().add(Shape::mesh(mesh)); } }); diff --git a/egui/src/menu.rs b/egui/src/menu.rs index db2810a0..b43c9cbd 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -43,11 +43,11 @@ pub fn bar(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResp ui.horizontal(|ui| { let mut style = (**ui.style()).clone(); style.spacing.button_padding = vec2(2.0, 0.0); - // style.visuals.widgets.active.bg_fill = Color32::TRANSPARENT; + // style.visuals.widgets.active.bg_fill = Rgba::TRANSPARENT; style.visuals.widgets.active.bg_stroke = Stroke::none(); - // style.visuals.widgets.hovered.bg_fill = Color32::TRANSPARENT; + // style.visuals.widgets.hovered.bg_fill = Rgba::TRANSPARENT; style.visuals.widgets.hovered.bg_stroke = Stroke::none(); - style.visuals.widgets.inactive.bg_fill = Color32::TRANSPARENT; + style.visuals.widgets.inactive.bg_fill = Rgba::TRANSPARENT; style.visuals.widgets.inactive.bg_stroke = Stroke::none(); ui.set_style(style); @@ -114,11 +114,11 @@ fn menu_impl<'c, R>( .show(ui, |ui| { let mut style = (**ui.style()).clone(); style.spacing.button_padding = vec2(2.0, 0.0); - // style.visuals.widgets.active.bg_fill = Color32::TRANSPARENT; + // style.visuals.widgets.active.bg_fill = Rgba::TRANSPARENT; style.visuals.widgets.active.bg_stroke = Stroke::none(); - // style.visuals.widgets.hovered.bg_fill = Color32::TRANSPARENT; + // style.visuals.widgets.hovered.bg_fill = Rgba::TRANSPARENT; style.visuals.widgets.hovered.bg_stroke = Stroke::none(); - style.visuals.widgets.inactive.bg_fill = Color32::TRANSPARENT; + style.visuals.widgets.inactive.bg_fill = Rgba::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/painter.rs b/egui/src/painter.rs index f62e652c..155da505 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -1,7 +1,7 @@ use crate::{ emath::{Align2, Pos2, Rect, Vec2}, layers::{LayerId, PaintList, ShapeIdx}, - Color32, CtxRef, + Color32, CtxRef, Rgba, }; use epaint::{ mutex::Mutex, @@ -28,7 +28,7 @@ pub struct Painter { /// If set, all shapes will have their colors modified to be closer to this. /// This is used to implement grayed out interfaces. - fade_to_color: Option, + fade_to_color: Option, } impl Painter { @@ -62,17 +62,17 @@ impl Painter { } /// If set, colors will be modified to look like this - pub(crate) fn set_fade_to_color(&mut self, fade_to_color: Option) { + pub(crate) fn set_fade_to_color(&mut self, fade_to_color: Option) { self.fade_to_color = fade_to_color; } pub(crate) fn visible(&self) -> bool { - self.fade_to_color != Some(Color32::TRANSPARENT) + self.fade_to_color != Some(Rgba::TRANSPARENT) } /// If `false`, nothing added to the painter will be visible pub(crate) fn set_invisible(&mut self) { - self.fade_to_color = Some(Color32::TRANSPARENT) + self.fade_to_color = Some(Rgba::TRANSPARENT) } /// Create a painter for a sub-region of this `Painter`. @@ -155,7 +155,7 @@ impl Painter { /// Can be used for free painting. /// NOTE: all coordinates are screen coordinates! pub fn add(&self, mut shape: Shape) -> ShapeIdx { - if self.fade_to_color == Some(Color32::TRANSPARENT) { + if self.fade_to_color == Some(Rgba::TRANSPARENT) { self.paint_list.lock().add(self.clip_rect, Shape::Noop) } else { self.transform_shape(&mut shape); @@ -167,7 +167,7 @@ impl Painter { /// /// Calling this once is generally faster than calling [`Self::add`] multiple times. pub fn extend(&self, mut shapes: Vec) { - if self.fade_to_color == Some(Color32::TRANSPARENT) { + if self.fade_to_color == Some(Rgba::TRANSPARENT) { return; } if !shapes.is_empty() { @@ -183,7 +183,7 @@ impl Painter { /// Modify an existing [`Shape`]. pub fn set(&self, idx: ShapeIdx, mut shape: Shape) { - if self.fade_to_color == Some(Color32::TRANSPARENT) { + if self.fade_to_color == Some(Rgba::TRANSPARENT) { return; } self.transform_shape(&mut shape); @@ -194,7 +194,7 @@ impl Painter { /// ## Debug painting impl Painter { #[allow(clippy::needless_pass_by_value)] - pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl ToString) { + pub fn debug_rect(&mut self, rect: Rect, color: Rgba, text: impl ToString) { self.rect_stroke(rect, 0.0, (1.0, color)); let text_style = TextStyle::Monospace; self.text( @@ -207,18 +207,12 @@ impl Painter { } pub fn error(&self, pos: Pos2, text: impl std::fmt::Display) -> Rect { - self.debug_text(pos, Align2::LEFT_TOP, Color32::RED, format!("🔥 {}", text)) + self.debug_text(pos, Align2::LEFT_TOP, Rgba::RED, format!("🔥 {}", text)) } /// text with a background #[allow(clippy::needless_pass_by_value)] - pub fn debug_text( - &self, - pos: Pos2, - anchor: Align2, - color: Color32, - text: impl ToString, - ) -> Rect { + pub fn debug_text(&self, pos: Pos2, anchor: Align2, color: Rgba, text: impl ToString) -> Rect { let galley = self .fonts() .layout_no_wrap(TextStyle::Monospace, text.to_string()); @@ -227,7 +221,7 @@ impl Painter { self.add(Shape::Rect { rect: frame_rect, corner_radius: 0.0, - fill: Color32::from_black_alpha(240), + fill: Color32::from_black_alpha(240).into(), // stroke: Stroke::new(1.0, color), stroke: Default::default(), }); @@ -249,7 +243,7 @@ impl Painter { &self, center: Pos2, radius: f32, - fill_color: impl Into, + fill_color: impl Into, stroke: impl Into, ) { self.add(Shape::Circle { @@ -260,7 +254,7 @@ impl Painter { }); } - pub fn circle_filled(&self, center: Pos2, radius: f32, fill_color: impl Into) { + pub fn circle_filled(&self, center: Pos2, radius: f32, fill_color: impl Into) { self.add(Shape::Circle { center, radius, @@ -282,7 +276,7 @@ impl Painter { &self, rect: Rect, corner_radius: f32, - fill_color: impl Into, + fill_color: impl Into, stroke: impl Into, ) { self.add(Shape::Rect { @@ -293,7 +287,7 @@ impl Painter { }); } - pub fn rect_filled(&self, rect: Rect, corner_radius: f32, fill_color: impl Into) { + pub fn rect_filled(&self, rect: Rect, corner_radius: f32, fill_color: impl Into) { self.add(Shape::Rect { rect, corner_radius, @@ -341,7 +335,7 @@ impl Painter { anchor: Align2, text: impl ToString, text_style: TextStyle, - text_color: Color32, + text_color: Rgba, ) -> Rect { let galley = self.layout_no_wrap(text_style, text.to_string()); let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size)); @@ -377,7 +371,7 @@ impl Painter { /// /// You can create the `Galley` with [`Self::layout_no_wrap`] or [`Self::layout_multiline`]. #[inline(always)] - pub fn galley(&self, pos: Pos2, galley: std::sync::Arc, color: Color32) { + pub fn galley(&self, pos: Pos2, galley: std::sync::Arc, color: Rgba) { self.galley_with_italics(pos, galley, color, false) } @@ -385,7 +379,7 @@ impl Painter { &self, pos: Pos2, galley: std::sync::Arc, - color: Color32, + color: Rgba, fake_italics: bool, ) { if !galley.is_empty() { @@ -399,8 +393,8 @@ impl Painter { } } -fn tint_shape_towards(shape: &mut Shape, target: Color32) { +fn tint_shape_towards(shape: &mut Shape, target: Rgba) { epaint::shape_transform::adjust_colors(shape, &|color| { - *color = crate::color::tint_color_towards(*color, target); + *color = crate::color::tint_rgba_towards(*color, target); }); } diff --git a/egui/src/style.rs b/egui/src/style.rs index 95936b86..e602eac5 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -189,7 +189,7 @@ pub struct Visuals { /// so that `visuals.text_color` is always used, /// but its alpha may be different based on whether or not /// it is disabled, non-interactive, hovered etc. - pub override_text_color: Option, + pub override_text_color: Option, /// Visual styles of widgets pub widgets: Widgets, @@ -197,19 +197,19 @@ pub struct Visuals { pub selection: Selection, /// The color used for `Hyperlink`, - pub hyperlink_color: Color32, + pub hyperlink_color: Rgba, /// Something just barely different from the background color. /// Used for [`crate::Grid::striped`]. - pub faint_bg_color: Color32, + pub faint_bg_color: Rgba, /// Very dark or light color (for corresponding theme). /// Used as the background of text edits, scroll bars and others things /// that needs to look different from other interactive stuff. - pub extreme_bg_color: Color32, + pub extreme_bg_color: Rgba, /// Background color behind code-styled monospaced labels. - pub code_bg_color: Color32, + pub code_bg_color: Rgba, pub window_corner_radius: f32, pub window_shadow: Shadow, @@ -237,20 +237,20 @@ impl Visuals { &self.widgets.noninteractive } - pub fn text_color(&self) -> Color32 { + pub fn text_color(&self) -> Rgba { self.override_text_color .unwrap_or_else(|| self.widgets.noninteractive.text_color()) } - pub fn weak_text_color(&self) -> Color32 { - crate::color::tint_color_towards(self.text_color(), self.window_fill()) + pub fn weak_text_color(&self) -> Rgba { + crate::color::tint_rgba_towards(self.text_color(), self.window_fill()) } - pub fn strong_text_color(&self) -> Color32 { + pub fn strong_text_color(&self) -> Rgba { self.widgets.active.text_color() } - pub fn window_fill(&self) -> Color32 { + pub fn window_fill(&self) -> Rgba { self.widgets.noninteractive.bg_fill } @@ -264,7 +264,7 @@ impl Visuals { #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "persistence", serde(default))] pub struct Selection { - pub bg_fill: Color32, + pub bg_fill: Rgba, pub stroke: Stroke, } @@ -307,7 +307,7 @@ impl Widgets { #[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))] pub struct WidgetVisuals { /// Background color of widget. - pub bg_fill: Color32, + pub bg_fill: Rgba, /// For surrounding rectangle of things that need it, /// like buttons, the box of the checkbox, etc. @@ -325,7 +325,7 @@ pub struct WidgetVisuals { } impl WidgetVisuals { - pub fn text_color(&self) -> Color32 { + pub fn text_color(&self) -> Rgba { self.fg_stroke.color } } @@ -398,10 +398,10 @@ impl Visuals { override_text_color: None, widgets: Widgets::default(), selection: Selection::default(), - hyperlink_color: Color32::from_rgb(90, 170, 255), - faint_bg_color: Color32::from_gray(24), - extreme_bg_color: Color32::from_gray(10), - code_bg_color: Color32::from_gray(64), + hyperlink_color: Color32::from_rgb(90, 170, 255).into(), + faint_bg_color: Color32::from_gray(24).into(), + extreme_bg_color: Color32::from_gray(10).into(), + code_bg_color: Color32::from_gray(64).into(), window_corner_radius: 6.0, window_shadow: Shadow::big_dark(), popup_shadow: Shadow::small_dark(), @@ -420,10 +420,10 @@ impl Visuals { dark_mode: false, widgets: Widgets::light(), selection: Selection::light(), - hyperlink_color: Color32::from_rgb(0, 155, 255), - faint_bg_color: Color32::from_gray(240), - extreme_bg_color: Color32::from_gray(250), - code_bg_color: Color32::from_gray(200), + hyperlink_color: Color32::from_rgb(0, 155, 255).into(), + faint_bg_color: Color32::from_gray(240).into(), + extreme_bg_color: Color32::from_gray(250).into(), + code_bg_color: Color32::from_gray(200).into(), window_shadow: Shadow::big_light(), popup_shadow: Shadow::small_light(), ..Self::dark() @@ -440,13 +440,13 @@ impl Default for Visuals { impl Selection { fn dark() -> Self { Self { - bg_fill: Color32::from_rgb(0, 92, 128), + bg_fill: Color32::from_rgb(0, 92, 128).into(), stroke: Stroke::new(1.0, Color32::from_rgb(192, 222, 255)), } } fn light() -> Self { Self { - bg_fill: Color32::from_rgb(144, 209, 255), + bg_fill: Color32::from_rgb(144, 209, 255).into(), stroke: Stroke::new(1.0, Color32::from_rgb(0, 83, 125)), } } @@ -462,35 +462,35 @@ impl Widgets { pub fn dark() -> Self { Self { noninteractive: WidgetVisuals { - bg_fill: Color32::from_gray(27), // window background + bg_fill: Color32::from_gray(27).into(), // window background bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines, windows outlines fg_stroke: Stroke::new(1.0, Color32::from_gray(140)), // normal text color corner_radius: 2.0, expansion: 0.0, }, inactive: WidgetVisuals { - bg_fill: Color32::from_gray(60), // button background + bg_fill: Color32::from_gray(60).into(), // button background bg_stroke: Default::default(), fg_stroke: Stroke::new(1.0, Color32::from_gray(180)), // button text corner_radius: 2.0, expansion: 0.0, }, hovered: WidgetVisuals { - bg_fill: Color32::from_gray(70), + bg_fill: Color32::from_gray(70).into(), bg_stroke: Stroke::new(1.0, Color32::from_gray(150)), // e.g. hover over window edge or button fg_stroke: Stroke::new(1.5, Color32::from_gray(240)), corner_radius: 3.0, expansion: 1.0, }, active: WidgetVisuals { - bg_fill: Color32::from_gray(55), - bg_stroke: Stroke::new(1.0, Color32::WHITE), - fg_stroke: Stroke::new(2.0, Color32::WHITE), + bg_fill: Color32::from_gray(55).into(), + bg_stroke: Stroke::new(1.0, Rgba::WHITE), + fg_stroke: Stroke::new(2.0, Rgba::WHITE), corner_radius: 2.0, expansion: 1.0, }, open: WidgetVisuals { - bg_fill: Color32::from_gray(27), + bg_fill: Color32::from_gray(27).into(), bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), fg_stroke: Stroke::new(1.0, Color32::from_gray(210)), corner_radius: 2.0, @@ -502,37 +502,37 @@ impl Widgets { pub fn light() -> Self { Self { noninteractive: WidgetVisuals { - bg_fill: Color32::from_gray(235), // window background + bg_fill: Color32::from_gray(235).into(), // window background bg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // separators, indentation lines, windows outlines fg_stroke: Stroke::new(1.0, Color32::from_gray(100)), // normal text color corner_radius: 2.0, expansion: 0.0, }, inactive: WidgetVisuals { - bg_fill: Color32::from_gray(215), // button background + bg_fill: Color32::from_gray(215).into(), // button background bg_stroke: Default::default(), fg_stroke: Stroke::new(1.0, Color32::from_gray(80)), // button text corner_radius: 2.0, expansion: 0.0, }, hovered: WidgetVisuals { - bg_fill: Color32::from_gray(210), + bg_fill: Color32::from_gray(210).into(), bg_stroke: Stroke::new(1.0, Color32::from_gray(105)), // e.g. hover over window edge or button - fg_stroke: Stroke::new(1.5, Color32::BLACK), + fg_stroke: Stroke::new(1.5, Rgba::BLACK), corner_radius: 3.0, expansion: 1.0, }, active: WidgetVisuals { - bg_fill: Color32::from_gray(165), - bg_stroke: Stroke::new(1.0, Color32::BLACK), - fg_stroke: Stroke::new(2.0, Color32::BLACK), + bg_fill: Color32::from_gray(165).into(), + bg_stroke: Stroke::new(1.0, Rgba::BLACK), + fg_stroke: Stroke::new(2.0, Rgba::BLACK), corner_radius: 2.0, expansion: 1.0, }, open: WidgetVisuals { - bg_fill: Color32::from_gray(220), + bg_fill: Color32::from_gray(220).into(), bg_stroke: Stroke::new(1.0, Color32::from_gray(160)), - fg_stroke: Stroke::new(1.0, Color32::BLACK), + fg_stroke: Stroke::new(1.0, Rgba::BLACK), corner_radius: 2.0, expansion: 0.0, }, @@ -934,9 +934,9 @@ fn slider_vec2<'a>( } } -fn ui_color(ui: &mut Ui, srgba: &mut Color32, text: impl Into