diff --git a/CHANGELOG.md b/CHANGELOG.md index 586e426a..3353634b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed 🔧 +* Renamed `Srgba` to `Color32`. * Renamed `FontFamily::VariableWidth` to `FontFamily::Proportional`. -* Remove `pixels_per_point` from `FontDefinitions`. +* Removed `pixels_per_point` from `FontDefinitions`. ### Fixed 🐛 diff --git a/egui/src/containers/frame.rs b/egui/src/containers/frame.rs index 1092a883..d1adc7f2 100644 --- a/egui/src/containers/frame.rs +++ b/egui/src/containers/frame.rs @@ -9,7 +9,7 @@ pub struct Frame { pub margin: Vec2, pub corner_radius: f32, pub shadow: Shadow, - pub fill: Srgba, + pub fill: Color32, pub stroke: Stroke, } @@ -73,7 +73,7 @@ impl Frame { Self { margin: Vec2::new(10.0, 10.0), corner_radius: 5.0, - fill: Srgba::black_alpha(250), + fill: Color32::black_alpha(250), stroke: style.visuals.widgets.noninteractive.bg_stroke, ..Default::default() } @@ -81,7 +81,7 @@ impl Frame { } impl Frame { - pub fn fill(mut self, fill: Srgba) -> Self { + pub fn fill(mut self, fill: Color32) -> Self { self.fill = fill; self } diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 3401ba46..d08d590b 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -109,7 +109,7 @@ pub use { math::*, memory::Memory, paint::{ - color, FontDefinitions, FontFamily, PaintCmd, PaintJobs, Rgba, Srgba, Stroke, TextStyle, + color, Color32, FontDefinitions, FontFamily, PaintCmd, PaintJobs, Rgba, Stroke, TextStyle, Texture, TextureId, }, painter::Painter, diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 0be9838b..b5635f34 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet}; use crate::{ area, collapsing_header, menu, - paint::color::{Hsva, Srgba}, + paint::color::{Color32, Hsva}, resize, scroll_area, util::Cache, widgets::text_edit, @@ -47,7 +47,7 @@ pub struct Memory { /// Used by color picker #[cfg_attr(feature = "serde", serde(skip))] - pub(crate) color_cache: Cache, + pub(crate) color_cache: Cache, /// Which popup-window is open (if any)? /// Could be a combo box, color picker, menu etc. diff --git a/egui/src/paint/color.rs b/egui/src/paint/color.rs index 964d1ffa..d837048f 100644 --- a/egui/src/paint/color.rs +++ b/egui/src/paint/color.rs @@ -1,35 +1,35 @@ use crate::math::clamp; -/// This format is used for space-efficient color representation. +/// This format is used for space-efficient color representation (32 bits). /// /// Instead of manipulating this directly it is often better -/// to first convert it to either `Rgba` or `Hsva`. +/// to first convert it to either [`Rgba`] or [`Hsva`]. /// -/// 0-255 gamma space `sRGBA` color with premultiplied alpha. +/// Internally this uses 0-255 gamma space `sRGBA` color with premultiplied alpha. /// Alpha channel is in linear space. #[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -pub struct Srgba(pub(crate) [u8; 4]); +pub struct Color32(pub(crate) [u8; 4]); -impl std::ops::Index for Srgba { +impl std::ops::Index for Color32 { type Output = u8; fn index(&self, index: usize) -> &u8 { &self.0[index] } } -impl std::ops::IndexMut for Srgba { +impl std::ops::IndexMut for Color32 { fn index_mut(&mut self, index: usize) -> &mut u8 { &mut self.0[index] } } // TODO: remove ? -pub const fn srgba(r: u8, g: u8, b: u8, a: u8) -> Srgba { - Srgba::from_rgba_premultiplied(r, g, b, a) +pub const fn srgba(r: u8, g: u8, b: u8, a: u8) -> Color32 { + Color32::from_rgba_premultiplied(r, g, b, a) } -impl Srgba { +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]) @@ -108,16 +108,16 @@ impl Srgba { // ---------------------------------------------------------------------------- -pub const TRANSPARENT: Srgba = srgba(0, 0, 0, 0); -pub const BLACK: Srgba = srgba(0, 0, 0, 255); -pub const LIGHT_GRAY: Srgba = srgba(220, 220, 220, 255); -pub const GRAY: Srgba = srgba(160, 160, 160, 255); -pub const WHITE: Srgba = srgba(255, 255, 255, 255); -pub const RED: Srgba = srgba(255, 0, 0, 255); -pub const GREEN: Srgba = srgba(0, 255, 0, 255); -pub const BLUE: Srgba = srgba(0, 0, 255, 255); -pub const YELLOW: Srgba = srgba(255, 255, 0, 255); -pub const LIGHT_BLUE: Srgba = srgba(140, 160, 255, 255); +pub const TRANSPARENT: Color32 = srgba(0, 0, 0, 0); +pub const BLACK: Color32 = srgba(0, 0, 0, 255); +pub const LIGHT_GRAY: Color32 = srgba(220, 220, 220, 255); +pub const GRAY: Color32 = srgba(160, 160, 160, 255); +pub const WHITE: Color32 = srgba(255, 255, 255, 255); +pub const RED: Color32 = srgba(255, 0, 0, 255); +pub const GREEN: Color32 = srgba(0, 255, 0, 255); +pub const BLUE: Color32 = srgba(0, 0, 255, 255); +pub const YELLOW: Color32 = srgba(255, 255, 0, 255); +pub const LIGHT_BLUE: Color32 = srgba(140, 160, 255, 255); // ---------------------------------------------------------------------------- @@ -273,30 +273,30 @@ impl std::ops::Mul for f32 { // ---------------------------------------------------------------------------- // Color conversion: -impl From for Rgba { - fn from(srgba: Srgba) -> Rgba { +impl From for Rgba { + fn from(srgba: Color32) -> Rgba { Rgba([ - linear_from_srgb_byte(srgba[0]), - linear_from_srgb_byte(srgba[1]), - linear_from_srgb_byte(srgba[2]), + linear_from_gamma_byte(srgba[0]), + linear_from_gamma_byte(srgba[1]), + linear_from_gamma_byte(srgba[2]), linear_from_alpha_byte(srgba[3]), ]) } } -impl From for Srgba { - fn from(rgba: Rgba) -> Srgba { - Srgba([ - srgb_byte_from_linear(rgba[0]), - srgb_byte_from_linear(rgba[1]), - srgb_byte_from_linear(rgba[2]), +impl From for Color32 { + fn from(rgba: Rgba) -> Color32 { + Color32([ + gamma_byte_from_linear(rgba[0]), + gamma_byte_from_linear(rgba[1]), + gamma_byte_from_linear(rgba[2]), alpha_byte_from_linear(rgba[3]), ]) } } /// [0, 255] -> [0, 1] -fn linear_from_srgb_byte(s: u8) -> f32 { +fn linear_from_gamma_byte(s: u8) -> f32 { if s <= 10 { s as f32 / 3294.6 } else { @@ -309,7 +309,7 @@ fn linear_from_alpha_byte(a: u8) -> f32 { } /// [0, 1] -> [0, 255] -fn srgb_byte_from_linear(l: f32) -> u8 { +fn gamma_byte_from_linear(l: f32) -> u8 { if l <= 0.0 { 0 } else if l <= 0.0031308 { @@ -329,9 +329,9 @@ fn alpha_byte_from_linear(a: f32) -> u8 { fn test_srgba_conversion() { #![allow(clippy::float_cmp)] for b in 0..=255 { - let l = linear_from_srgb_byte(b); + let l = linear_from_gamma_byte(b); assert!(0.0 <= l && l <= 1.0); - assert_eq!(srgb_byte_from_linear(l), b); + assert_eq!(gamma_byte_from_linear(l), b); } } @@ -359,9 +359,9 @@ impl Hsva { /// From `sRGBA` with premultiplied alpha pub fn from_srgba_premultiplied(srgba: [u8; 4]) -> Self { Self::from_rgba_premultiplied([ - linear_from_srgb_byte(srgba[0]), - linear_from_srgb_byte(srgba[1]), - linear_from_srgb_byte(srgba[2]), + linear_from_gamma_byte(srgba[0]), + linear_from_gamma_byte(srgba[1]), + linear_from_gamma_byte(srgba[2]), linear_from_alpha_byte(srgba[3]), ]) } @@ -369,9 +369,9 @@ impl Hsva { /// From `sRGBA` without premultiplied alpha pub fn from_srgba_unmultiplied(srgba: [u8; 4]) -> Self { Self::from_rgba_unmultiplied([ - linear_from_srgb_byte(srgba[0]), - linear_from_srgb_byte(srgba[1]), - linear_from_srgb_byte(srgba[2]), + linear_from_gamma_byte(srgba[0]), + linear_from_gamma_byte(srgba[1]), + linear_from_gamma_byte(srgba[2]), linear_from_alpha_byte(srgba[3]), ]) } @@ -410,9 +410,9 @@ impl Hsva { pub fn to_srgba_premultiplied(&self) -> [u8; 4] { let [r, g, b, a] = self.to_rgba_premultiplied(); [ - srgb_byte_from_linear(r), - srgb_byte_from_linear(g), - srgb_byte_from_linear(b), + gamma_byte_from_linear(r), + gamma_byte_from_linear(g), + gamma_byte_from_linear(b), alpha_byte_from_linear(a), ] } @@ -420,9 +420,9 @@ impl Hsva { pub fn to_srgba_unmultiplied(&self) -> [u8; 4] { let [r, g, b, a] = self.to_rgba_unmultiplied(); [ - srgb_byte_from_linear(r), - srgb_byte_from_linear(g), - srgb_byte_from_linear(b), + gamma_byte_from_linear(r), + gamma_byte_from_linear(g), + gamma_byte_from_linear(b), alpha_byte_from_linear(a), ] } @@ -439,13 +439,13 @@ impl From for Hsva { } } -impl From for Srgba { - fn from(hsva: Hsva) -> Srgba { - Srgba::from(Rgba::from(hsva)) +impl From for Color32 { + fn from(hsva: Hsva) -> Color32 { + Color32::from(Rgba::from(hsva)) } } -impl From for Hsva { - fn from(srgba: Srgba) -> Hsva { +impl From for Hsva { + fn from(srgba: Color32) -> Hsva { Hsva::from(Rgba::from(srgba)) } } @@ -502,9 +502,9 @@ fn test_hsv_roundtrip() { for r in 0..=255 { for g in 0..=255 { for b in 0..=255 { - let srgba = Srgba::from_rgb(r, g, b); + let srgba = Color32::from_rgb(r, g, b); let hsva = Hsva::from(srgba); - assert_eq!(srgba, Srgba::from(hsva)); + assert_eq!(srgba, Color32::from(hsva)); } } } diff --git a/egui/src/paint/command.rs b/egui/src/paint/command.rs index 0b1f6e54..b5b0cdb9 100644 --- a/egui/src/paint/command.rs +++ b/egui/src/paint/command.rs @@ -1,5 +1,5 @@ use { - super::{fonts::TextStyle, Fonts, Galley, Srgba, Triangles}, + super::{fonts::TextStyle, Color32, Fonts, Galley, Triangles}, crate::{ align::{anchor_rect, Align}, math::{Pos2, Rect}, @@ -19,7 +19,7 @@ pub enum PaintCmd { Circle { center: Pos2, radius: f32, - fill: Srgba, + fill: Color32, stroke: Stroke, }, LineSegment { @@ -31,14 +31,14 @@ pub enum PaintCmd { /// If true, connect the first and last of the points together. /// This is required if `fill != TRANSPARENT`. closed: bool, - fill: Srgba, + fill: Color32, stroke: Stroke, }, Rect { rect: Rect, /// How rounded the corners are. Use `0.0` for no rounding. corner_radius: f32, - fill: Srgba, + fill: Color32, stroke: Stroke, }, Text { @@ -47,7 +47,7 @@ pub enum PaintCmd { /// The layed out text galley: Galley, text_style: TextStyle, // TODO: Font? - color: Srgba, + color: Color32, }, Triangles(Triangles), } @@ -79,7 +79,7 @@ impl PaintCmd { } } - pub fn polygon(points: Vec, fill: impl Into, stroke: impl Into) -> Self { + pub fn polygon(points: Vec, fill: impl Into, stroke: impl Into) -> Self { Self::Path { points, closed: true, @@ -88,7 +88,7 @@ impl PaintCmd { } } - pub fn circle_filled(center: Pos2, radius: f32, fill_color: impl Into) -> Self { + pub fn circle_filled(center: Pos2, radius: f32, fill_color: impl Into) -> Self { Self::Circle { center, radius, @@ -106,7 +106,7 @@ impl PaintCmd { } } - pub fn rect_filled(rect: Rect, corner_radius: f32, fill_color: impl Into) -> Self { + pub fn rect_filled(rect: Rect, corner_radius: f32, fill_color: impl Into) -> Self { Self::Rect { rect, corner_radius, @@ -130,7 +130,7 @@ impl PaintCmd { anchor: (Align, Align), text: impl Into, text_style: TextStyle, - color: Srgba, + color: Color32, ) -> Self { let font = &fonts[text_style]; let galley = font.layout_multiline(text.into(), f32::INFINITY); @@ -199,7 +199,7 @@ impl PaintCmd { #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Stroke { pub width: f32, - pub color: Srgba, + pub color: Color32, } impl Stroke { @@ -207,7 +207,7 @@ impl Stroke { Self::new(0.0, crate::color::TRANSPARENT) } - pub fn new(width: impl Into, color: impl Into) -> Self { + pub fn new(width: impl Into, color: impl Into) -> Self { Self { width: width.into(), color: color.into(), @@ -217,7 +217,7 @@ impl Stroke { impl From<(f32, Color)> for Stroke where - Color: Into, + Color: Into, { fn from((width, color): (f32, Color)) -> Stroke { Stroke::new(width, color) diff --git a/egui/src/paint/mod.rs b/egui/src/paint/mod.rs index ee382c6d..9939df9b 100644 --- a/egui/src/paint/mod.rs +++ b/egui/src/paint/mod.rs @@ -11,7 +11,7 @@ pub mod tessellator; mod texture_atlas; pub use { - color::{Rgba, Srgba}, + color::{Color32, Rgba}, command::{PaintCmd, Stroke}, fonts::{FontDefinitions, FontFamily, Fonts, TextStyle}, galley::*, @@ -27,6 +27,6 @@ pub(crate) struct PaintRect { pub rect: crate::Rect, /// How rounded the corners are. Use `0.0` for no rounding. pub corner_radius: f32, - pub fill: Srgba, + pub fill: Color32, pub stroke: Stroke, } diff --git a/egui/src/paint/shadow.rs b/egui/src/paint/shadow.rs index 54b7ee99..e2763723 100644 --- a/egui/src/paint/shadow.rs +++ b/egui/src/paint/shadow.rs @@ -5,7 +5,7 @@ use super::*; pub struct Shadow { // The shadow extends this much outside the rect. pub extrusion: f32, - pub color: Srgba, + pub color: Color32, } impl Shadow { @@ -13,7 +13,7 @@ impl Shadow { pub fn small() -> Self { Self { extrusion: 8.0, - color: Srgba::black_alpha(64), + color: Color32::black_alpha(64), } } @@ -21,7 +21,7 @@ impl Shadow { pub fn big() -> Self { Self { extrusion: 32.0, - color: Srgba::black_alpha(96), + color: Color32::black_alpha(96), } } diff --git a/egui/src/paint/tessellator.rs b/egui/src/paint/tessellator.rs index b6833ba5..326dfe02 100644 --- a/egui/src/paint/tessellator.rs +++ b/egui/src/paint/tessellator.rs @@ -7,7 +7,7 @@ use { super::{ - color::{self, srgba, Rgba, Srgba, TRANSPARENT}, + color::{self, srgba, Color32, Rgba, TRANSPARENT}, *, }, crate::math::*, @@ -54,7 +54,7 @@ pub struct Vertex { pub uv: Pos2, // 64 bit /// sRGBA with premultiplied alpha - pub color: Srgba, // 32 bit + pub color: Color32, // 32 bit } /// Textured triangles. @@ -123,7 +123,7 @@ impl Triangles { } } - pub fn colored_vertex(&mut self, pos: Pos2, color: Srgba) { + pub fn colored_vertex(&mut self, pos: Pos2, color: Color32) { debug_assert!(self.texture_id == TextureId::Egui); self.vertices.push(Vertex { pos, @@ -152,7 +152,7 @@ impl Triangles { } /// Rectangle with a texture and color. - pub fn add_rect_with_uv(&mut self, pos: Rect, uv: Rect, color: Srgba) { + pub fn add_rect_with_uv(&mut self, pos: Rect, uv: Rect, color: Color32) { let idx = self.vertices.len() as u32; self.add_triangle(idx + 0, idx + 1, idx + 2); self.add_triangle(idx + 2, idx + 1, idx + 3); @@ -184,7 +184,7 @@ impl Triangles { } /// Uniformly colored rectangle. - pub fn add_colored_rect(&mut self, rect: Rect, color: Srgba) { + pub fn add_colored_rect(&mut self, rect: Rect, color: Color32) { debug_assert!(self.texture_id == TextureId::Egui); self.add_rect_with_uv(rect, [WHITE_UV, WHITE_UV].into(), color) } @@ -475,7 +475,7 @@ impl Default for TessellationOptions { /// Tessellate the given convex area into a polygon. fn fill_closed_path( path: &[PathPoint], - color: Srgba, + color: Color32, options: TessellationOptions, out: &mut Triangles, ) { @@ -656,7 +656,7 @@ fn stroke_path( } } -fn mul_color(color: Srgba, factor: f32) -> Srgba { +fn mul_color(color: Color32, factor: f32) -> Color32 { debug_assert!(0.0 <= factor && factor <= 1.0); // sRGBA correct fading requires conversion to linear space and back again because of premultiplied alpha Rgba::from(color).multiply(factor).into() @@ -828,7 +828,7 @@ impl Tessellator { pos: Pos2, galley: &super::Galley, text_style: super::TextStyle, - color: Srgba, + color: Color32, out: &mut Triangles, ) { if color == TRANSPARENT { diff --git a/egui/src/paint/texture_atlas.rs b/egui/src/paint/texture_atlas.rs index ea52b469..05c79973 100644 --- a/egui/src/paint/texture_atlas.rs +++ b/egui/src/paint/texture_atlas.rs @@ -13,9 +13,9 @@ pub struct Texture { impl Texture { /// Returns the textures as `sRGBA` premultiplied pixels, row by row, top to bottom. - pub fn srgba_pixels(&'_ self) -> impl Iterator + '_ { - use super::Srgba; - let srgba_from_luminance_lut: Vec = (0..=255).map(Srgba::white_alpha).collect(); + pub fn srgba_pixels(&'_ self) -> impl Iterator + '_ { + use super::Color32; + let srgba_from_luminance_lut: Vec = (0..=255).map(Color32::white_alpha).collect(); self.pixels .iter() .map(move |&l| srgba_from_luminance_lut[l as usize]) diff --git a/egui/src/painter.rs b/egui/src/painter.rs index 68b86c60..7f7c002a 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -4,7 +4,7 @@ use crate::{ layers::PaintCmdIdx, math::{Pos2, Rect, Vec2}, paint::{Fonts, Galley, PaintCmd, Stroke, TextStyle}, - CtxRef, LayerId, Srgba, + Color32, CtxRef, LayerId, }; /// Helper to paint shapes and text to a specific region on a specific layer. @@ -133,7 +133,7 @@ impl Painter { /// ## Debug painting impl Painter { - pub fn debug_rect(&mut self, rect: Rect, color: Srgba, text: impl Into) { + pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl Into) { self.rect_stroke(rect, 0.0, (1.0, color)); let text_style = TextStyle::Monospace; self.text(rect.min, LEFT_TOP, text.into(), text_style, color); @@ -148,7 +148,7 @@ impl Painter { self.add(PaintCmd::Rect { rect: frame_rect, corner_radius: 0.0, - fill: Srgba::black_alpha(240), + fill: Color32::black_alpha(240), stroke: Stroke::new(1.0, color::RED), }); self.galley(rect.min, galley, text_style, color::RED); @@ -169,7 +169,7 @@ impl Painter { &self, center: Pos2, radius: f32, - fill_color: impl Into, + fill_color: impl Into, stroke: impl Into, ) { self.add(PaintCmd::Circle { @@ -180,7 +180,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(PaintCmd::Circle { center, radius, @@ -202,7 +202,7 @@ impl Painter { &self, rect: Rect, corner_radius: f32, - fill_color: impl Into, + fill_color: impl Into, stroke: impl Into, ) { self.add(PaintCmd::Rect { @@ -213,7 +213,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(PaintCmd::Rect { rect, corner_radius, @@ -257,7 +257,7 @@ impl Painter { anchor: (Align, Align), text: impl Into, text_style: TextStyle, - text_color: Srgba, + text_color: Color32, ) -> Rect { let font = &self.fonts()[text_style]; let galley = font.layout_multiline(text.into(), f32::INFINITY); @@ -267,7 +267,7 @@ impl Painter { } /// Paint text that has already been layed out in a `Galley`. - pub fn galley(&self, pos: Pos2, galley: Galley, text_style: TextStyle, color: Srgba) { + pub fn galley(&self, pos: Pos2, galley: Galley, text_style: TextStyle, color: Color32) { self.add(PaintCmd::Text { pos, galley, diff --git a/egui/src/style.rs b/egui/src/style.rs index fa0a6a97..f84ec0e1 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -118,7 +118,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, @@ -127,10 +127,10 @@ pub struct Visuals { /// e.g. the background of the slider or text edit, /// needs to look different from other interactive stuff. - pub dark_bg_color: Srgba, // TODO: remove, rename, or clarify what it is for + pub dark_bg_color: Color32, // TODO: remove, rename, or clarify what it is for /// The color used for `Hyperlink`, - pub hyperlink_color: Srgba, + pub hyperlink_color: Color32, pub window_corner_radius: f32, pub window_shadow: Shadow, @@ -156,7 +156,7 @@ impl Visuals { &self.widgets.noninteractive } - pub fn text_color(&self) -> Srgba { + pub fn text_color(&self) -> Color32 { self.override_text_color .unwrap_or_else(|| self.widgets.noninteractive.text_color()) } @@ -166,7 +166,7 @@ impl Visuals { #[derive(Clone, Copy, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Selection { - pub bg_fill: Srgba, + pub bg_fill: Color32, pub stroke: Stroke, } @@ -204,7 +204,7 @@ impl Widgets { #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct WidgetVisuals { /// Background color of widget - pub bg_fill: Srgba, + pub bg_fill: Color32, /// For surrounding rectangle of things that need it, /// like buttons, the box of the checkbox, etc. @@ -215,14 +215,14 @@ pub struct WidgetVisuals { /// Fill color of the interactive part of a component (slider grab, checkbox, ...) /// When you need a fill. - pub fg_fill: Srgba, + pub fg_fill: Color32, /// Stroke and text color of the interactive part of a component (button text, slider grab, check-mark, ...) pub fg_stroke: Stroke, } impl WidgetVisuals { - pub fn text_color(&self) -> Srgba { + pub fn text_color(&self) -> Color32 { self.fg_stroke.color } } @@ -273,8 +273,8 @@ impl Default for Visuals { override_text_color: None, widgets: Default::default(), selection: Default::default(), - dark_bg_color: Srgba::black_alpha(140), - hyperlink_color: Srgba::from_rgb(90, 170, 255), + dark_bg_color: Color32::black_alpha(140), + hyperlink_color: Color32::from_rgb(90, 170, 255), window_corner_radius: 10.0, window_shadow: Shadow::big(), resize_corner_size: 12.0, @@ -311,28 +311,28 @@ impl Default for Widgets { bg_stroke: Stroke::new(1.0, Rgba::white_alpha(0.5)), corner_radius: 4.0, fg_fill: srgba(100, 100, 150, 255), - fg_stroke: Stroke::new(1.5, Srgba::gray(240)), + fg_stroke: Stroke::new(1.5, Color32::gray(240)), }, inactive: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.04, 0.5).into(), bg_stroke: Stroke::new(1.0, Rgba::white_alpha(0.06)), // default window outline. Should be pretty readable corner_radius: 4.0, fg_fill: srgba(60, 60, 80, 255), - fg_stroke: Stroke::new(1.0, Srgba::gray(200)), // Should NOT look grayed out! + fg_stroke: Stroke::new(1.0, Color32::gray(200)), // Should NOT look grayed out! }, disabled: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.02, 0.5).into(), - bg_stroke: Stroke::new(0.5, Srgba::gray(70)), + bg_stroke: Stroke::new(0.5, Color32::gray(70)), corner_radius: 4.0, fg_fill: srgba(50, 50, 50, 255), - fg_stroke: Stroke::new(1.0, Srgba::gray(140)), // Should look grayed out + fg_stroke: Stroke::new(1.0, Color32::gray(140)), // Should look grayed out }, noninteractive: WidgetVisuals { bg_stroke: Stroke::new(1.0, Rgba::white_alpha(0.06)), bg_fill: Rgba::luminance_alpha(0.010, 0.975).into(), // window background corner_radius: 4.0, fg_fill: Default::default(), - fg_stroke: Stroke::new(1.0, Srgba::gray(160)), // text color + fg_stroke: Stroke::new(1.0, Color32::gray(160)), // text color }, } } @@ -577,7 +577,7 @@ fn ui_slider_vec2( .1 } -fn ui_color(ui: &mut Ui, srgba: &mut Srgba, text: &str) { +fn ui_color(ui: &mut Ui, srgba: &mut Color32, text: &str) { ui.horizontal(|ui| { ui.color_edit_button_srgba(srgba); ui.label(text); diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 5c6f9753..e7cd2466 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -502,7 +502,7 @@ impl Ui { if (debug_expand_width && too_wide) || (debug_expand_height && too_high) { self.painter.rect_stroke(rect, 0.0, (1.0, LIGHT_BLUE)); - let color = color::Srgba::from_rgb(200, 0, 0); + let color = color::Color32::from_rgb(200, 0, 0); let width = 2.5; let paint_line_seg = |a, b| self.painter().line_segment([a, b], (width, color)); @@ -649,7 +649,11 @@ impl Ui { } /// Shortcut for `add(Label::new(text).text_color(color))` - pub fn colored_label(&mut self, color: impl Into, label: impl Into