1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Rename Srgba to Color32

This commit is contained in:
Emil Ernerfeldt
2021-01-02 17:02:18 +01:00
parent 4fc12bf324
commit 73f3d8cf46
31 changed files with 198 additions and 193 deletions

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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<Srgba, Hsva>,
pub(crate) color_cache: Cache<Color32, Hsva>,
/// Which popup-window is open (if any)?
/// Could be a combo box, color picker, menu etc.

View File

@@ -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<usize> for Srgba {
impl std::ops::Index<usize> for Color32 {
type Output = u8;
fn index(&self, index: usize) -> &u8 {
&self.0[index]
}
}
impl std::ops::IndexMut<usize> for Srgba {
impl std::ops::IndexMut<usize> 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<Rgba> for f32 {
// ----------------------------------------------------------------------------
// Color conversion:
impl From<Srgba> for Rgba {
fn from(srgba: Srgba) -> Rgba {
impl From<Color32> 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<Rgba> 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<Rgba> 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<Rgba> for Hsva {
}
}
impl From<Hsva> for Srgba {
fn from(hsva: Hsva) -> Srgba {
Srgba::from(Rgba::from(hsva))
impl From<Hsva> for Color32 {
fn from(hsva: Hsva) -> Color32 {
Color32::from(Rgba::from(hsva))
}
}
impl From<Srgba> for Hsva {
fn from(srgba: Srgba) -> Hsva {
impl From<Color32> 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));
}
}
}

View File

@@ -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<Pos2>, fill: impl Into<Srgba>, stroke: impl Into<Stroke>) -> Self {
pub fn polygon(points: Vec<Pos2>, fill: impl Into<Color32>, stroke: impl Into<Stroke>) -> Self {
Self::Path {
points,
closed: true,
@@ -88,7 +88,7 @@ impl PaintCmd {
}
}
pub fn circle_filled(center: Pos2, radius: f32, fill_color: impl Into<Srgba>) -> Self {
pub fn circle_filled(center: Pos2, radius: f32, fill_color: impl Into<Color32>) -> Self {
Self::Circle {
center,
radius,
@@ -106,7 +106,7 @@ impl PaintCmd {
}
}
pub fn rect_filled(rect: Rect, corner_radius: f32, fill_color: impl Into<Srgba>) -> Self {
pub fn rect_filled(rect: Rect, corner_radius: f32, fill_color: impl Into<Color32>) -> Self {
Self::Rect {
rect,
corner_radius,
@@ -130,7 +130,7 @@ impl PaintCmd {
anchor: (Align, Align),
text: impl Into<String>,
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<f32>, color: impl Into<Srgba>) -> Self {
pub fn new(width: impl Into<f32>, color: impl Into<Color32>) -> Self {
Self {
width: width.into(),
color: color.into(),
@@ -217,7 +217,7 @@ impl Stroke {
impl<Color> From<(f32, Color)> for Stroke
where
Color: Into<Srgba>,
Color: Into<Color32>,
{
fn from((width, color): (f32, Color)) -> Stroke {
Stroke::new(width, color)

View File

@@ -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,
}

View File

@@ -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),
}
}

View File

@@ -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 {

View File

@@ -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<Item = super::Srgba> + '_ {
use super::Srgba;
let srgba_from_luminance_lut: Vec<Srgba> = (0..=255).map(Srgba::white_alpha).collect();
pub fn srgba_pixels(&'_ self) -> impl Iterator<Item = super::Color32> + '_ {
use super::Color32;
let srgba_from_luminance_lut: Vec<Color32> = (0..=255).map(Color32::white_alpha).collect();
self.pixels
.iter()
.map(move |&l| srgba_from_luminance_lut[l as usize])

View File

@@ -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<String>) {
pub fn debug_rect(&mut self, rect: Rect, color: Color32, text: impl Into<String>) {
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<Srgba>,
fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>,
) {
self.add(PaintCmd::Circle {
@@ -180,7 +180,7 @@ impl Painter {
});
}
pub fn circle_filled(&self, center: Pos2, radius: f32, fill_color: impl Into<Srgba>) {
pub fn circle_filled(&self, center: Pos2, radius: f32, fill_color: impl Into<Color32>) {
self.add(PaintCmd::Circle {
center,
radius,
@@ -202,7 +202,7 @@ impl Painter {
&self,
rect: Rect,
corner_radius: f32,
fill_color: impl Into<Srgba>,
fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>,
) {
self.add(PaintCmd::Rect {
@@ -213,7 +213,7 @@ impl Painter {
});
}
pub fn rect_filled(&self, rect: Rect, corner_radius: f32, fill_color: impl Into<Srgba>) {
pub fn rect_filled(&self, rect: Rect, corner_radius: f32, fill_color: impl Into<Color32>) {
self.add(PaintCmd::Rect {
rect,
corner_radius,
@@ -257,7 +257,7 @@ impl Painter {
anchor: (Align, Align),
text: impl Into<String>,
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,

View File

@@ -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<Srgba>,
pub override_text_color: Option<Color32>,
/// 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);

View File

@@ -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<Srgba>, label: impl Into<Label>) -> Response {
pub fn colored_label(
&mut self,
color: impl Into<Color32>,
label: impl Into<Label>,
) -> Response {
self.add(label.into().text_color(color))
}
@@ -808,7 +812,7 @@ impl Ui {
impl Ui {
/// Shows a button with the given color.
/// If the user clicks the button, a full color picker is shown.
pub fn color_edit_button_srgba(&mut self, srgba: &mut Srgba) -> Response {
pub fn color_edit_button_srgba(&mut self, srgba: &mut Color32) -> Response {
widgets::color_picker::color_edit_button_srgba(self, srgba)
}
@@ -822,7 +826,7 @@ impl Ui {
/// If the user clicks the button, a full color picker is shown.
/// The given color is in `sRGBA` space with premultiplied alpha
pub fn color_edit_button_srgba_premultiplied(&mut self, srgba: &mut [u8; 4]) -> Response {
let mut color = Srgba(*srgba);
let mut color = Color32(*srgba);
let response = self.color_edit_button_srgba(&mut color);
*srgba = color.0;
response

View File

@@ -27,7 +27,7 @@ impl ImageButton {
}
/// Multiply image color with this. Default is WHITE (no tint).
pub fn tint(mut self, tint: impl Into<Srgba>) -> Self {
pub fn tint(mut self, tint: impl Into<Color32>) -> Self {
self.image = self.image.tint(tint);
self
}

View File

@@ -5,7 +5,7 @@ use crate::{
*,
};
fn contrast_color(color: impl Into<Rgba>) -> Srgba {
fn contrast_color(color: impl Into<Rgba>) -> Color32 {
if color.into().intensity() < 0.5 {
color::WHITE
} else {
@@ -19,8 +19,8 @@ fn contrast_color(color: impl Into<Rgba>) -> Srgba {
const N: u32 = 6 * 3;
fn background_checkers(painter: &Painter, rect: Rect) {
let mut top_color = Srgba::gray(128);
let mut bottom_color = Srgba::gray(32);
let mut top_color = Color32::gray(128);
let mut bottom_color = Color32::gray(32);
let checker_size = Vec2::splat(rect.height() / 2.0);
let n = (rect.width() / checker_size.x).round() as u32;
@@ -40,11 +40,11 @@ fn background_checkers(painter: &Painter, rect: Rect) {
painter.add(PaintCmd::triangles(triangles));
}
pub fn show_color(ui: &mut Ui, color: impl Into<Srgba>, desired_size: Vec2) -> Response {
pub fn show_color(ui: &mut Ui, color: impl Into<Color32>, desired_size: Vec2) -> Response {
show_srgba(ui, color.into(), desired_size)
}
fn show_srgba(ui: &mut Ui, srgba: Srgba, desired_size: Vec2) -> Response {
fn show_srgba(ui: &mut Ui, srgba: Color32, desired_size: Vec2) -> Response {
let response = ui.allocate_response(desired_size, Sense::hover());
background_checkers(ui.painter(), response.rect);
ui.painter().add(PaintCmd::Rect {
@@ -56,7 +56,7 @@ fn show_srgba(ui: &mut Ui, srgba: Srgba, desired_size: Vec2) -> Response {
response
}
fn color_button(ui: &mut Ui, color: Srgba) -> Response {
fn color_button(ui: &mut Ui, color: Color32) -> Response {
let desired_size = ui.style().spacing.interact_size;
let response = ui.allocate_response(desired_size, Sense::click());
let visuals = ui.style().interact(&response);
@@ -70,7 +70,7 @@ fn color_button(ui: &mut Ui, color: Srgba) -> Response {
response
}
fn color_slider_1d(ui: &mut Ui, value: &mut f32, color_at: impl Fn(f32) -> Srgba) -> Response {
fn color_slider_1d(ui: &mut Ui, value: &mut f32, color_at: impl Fn(f32) -> Color32) -> Response {
#![allow(clippy::identity_op)]
let desired_size = vec2(
@@ -132,7 +132,7 @@ fn color_slider_2d(
ui: &mut Ui,
x_value: &mut f32,
y_value: &mut f32,
color_at: impl Fn(f32, f32) -> Srgba,
color_at: impl Fn(f32, f32) -> Color32,
) -> Response {
let desired_size = Vec2::splat(ui.style().spacing.slider_width);
let response = ui.allocate_response(desired_size, Sense::click_and_drag());
@@ -246,7 +246,7 @@ pub fn color_edit_button_hsva(ui: &mut Ui, hsva: &mut Hsva) -> Response {
/// Shows a button with the given color.
/// If the user clicks the button, a full color picker is shown.
pub fn color_edit_button_srgba(ui: &mut Ui, srgba: &mut Srgba) -> Response {
pub fn color_edit_button_srgba(ui: &mut Ui, srgba: &mut Color32) -> Response {
// To ensure we keep hue slider when `srgba` is grey we store the
// full `Hsva` in a cache:
@@ -260,7 +260,7 @@ pub fn color_edit_button_srgba(ui: &mut Ui, srgba: &mut Srgba) -> Response {
let response = color_edit_button_hsva(ui, &mut hsva);
*srgba = Srgba::from(hsva);
*srgba = Color32::from(hsva);
ui.ctx().memory().color_cache.set(*srgba, hsva);
@@ -297,8 +297,8 @@ impl From<HsvaGamma> for Rgba {
}
}
impl From<HsvaGamma> for Srgba {
fn from(hsvag: HsvaGamma) -> Srgba {
impl From<HsvaGamma> for Color32 {
fn from(hsvag: HsvaGamma) -> Color32 {
Rgba::from(hsvag).into()
}
}

View File

@@ -7,8 +7,8 @@ pub struct Image {
texture_id: TextureId,
uv: Rect,
desired_size: Vec2,
bg_fill: Srgba,
tint: Srgba,
bg_fill: Color32,
tint: Color32,
}
impl Image {
@@ -29,13 +29,13 @@ impl Image {
}
/// A solid color to put behind the image. Useful for transparent images.
pub fn bg_fill(mut self, bg_fill: impl Into<Srgba>) -> Self {
pub fn bg_fill(mut self, bg_fill: impl Into<Color32>) -> Self {
self.bg_fill = bg_fill.into();
self
}
/// Multiply image color with this. Default is WHITE (no tint).
pub fn tint(mut self, tint: impl Into<Srgba>) -> Self {
pub fn tint(mut self, tint: impl Into<Color32>) -> Self {
self.tint = tint.into();
self
}

View File

@@ -37,7 +37,7 @@ pub struct Label {
pub(crate) text: String,
pub(crate) multiline: Option<bool>,
pub(crate) text_style: Option<TextStyle>,
pub(crate) text_color: Option<Srgba>,
pub(crate) text_color: Option<Color32>,
}
impl Label {
@@ -83,7 +83,7 @@ impl Label {
self.text_style(TextStyle::Small)
}
pub fn text_color(mut self, text_color: impl Into<Srgba>) -> Self {
pub fn text_color(mut self, text_color: impl Into<Color32>) -> Self {
self.text_color = Some(text_color.into());
self
}
@@ -303,10 +303,10 @@ impl Widget for Hyperlink {
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"]
pub struct Button {
text: String,
text_color: Option<Srgba>,
text_color: Option<Color32>,
text_style: TextStyle,
/// None means default for interact
fill: Option<Srgba>,
fill: Option<Color32>,
sense: Sense,
small: bool,
frame: bool,
@@ -325,12 +325,12 @@ impl Button {
}
}
pub fn text_color(mut self, text_color: Srgba) -> Self {
pub fn text_color(mut self, text_color: Color32) -> Self {
self.text_color = Some(text_color);
self
}
pub fn text_color_opt(mut self, text_color: Option<Srgba>) -> Self {
pub fn text_color_opt(mut self, text_color: Option<Color32>) -> Self {
self.text_color = text_color;
self
}
@@ -340,7 +340,7 @@ impl Button {
self
}
pub fn fill(mut self, fill: Option<Srgba>) -> Self {
pub fn fill(mut self, fill: Option<Color32>) -> Self {
self.fill = fill;
self
}
@@ -443,7 +443,7 @@ impl Widget for Button {
pub struct Checkbox<'a> {
checked: &'a mut bool,
text: String,
text_color: Option<Srgba>,
text_color: Option<Color32>,
}
impl<'a> Checkbox<'a> {
@@ -455,7 +455,7 @@ impl<'a> Checkbox<'a> {
}
}
pub fn text_color(mut self, text_color: Srgba) -> Self {
pub fn text_color(mut self, text_color: Color32) -> Self {
self.text_color = Some(text_color);
self
}
@@ -538,7 +538,7 @@ impl<'a> Widget for Checkbox<'a> {
pub struct RadioButton {
checked: bool,
text: String,
text_color: Option<Srgba>,
text_color: Option<Color32>,
}
impl RadioButton {
@@ -550,7 +550,7 @@ impl RadioButton {
}
}
pub fn text_color(mut self, text_color: Srgba) -> Self {
pub fn text_color(mut self, text_color: Color32) -> Self {
self.text_color = Some(text_color);
self
}

View File

@@ -44,7 +44,7 @@ pub struct Slider<'a> {
smart_aim: bool,
// TODO: label: Option<Label>
text: Option<String>,
text_color: Option<Srgba>,
text_color: Option<Color32>,
min_decimals: usize,
max_decimals: Option<usize>,
}
@@ -133,7 +133,7 @@ impl<'a> Slider<'a> {
self
}
pub fn text_color(mut self, text_color: Srgba) -> Self {
pub fn text_color(mut self, text_color: Color32) -> Self {
self.text_color = Some(text_color);
self
}

View File

@@ -121,7 +121,7 @@ pub struct TextEdit<'t> {
id: Option<Id>,
id_source: Option<Id>,
text_style: Option<TextStyle>,
text_color: Option<Srgba>,
text_color: Option<Color32>,
multiline: bool,
enabled: bool,
desired_width: Option<f32>,
@@ -180,12 +180,12 @@ impl<'t> TextEdit<'t> {
self
}
pub fn text_color(mut self, text_color: Srgba) -> Self {
pub fn text_color(mut self, text_color: Color32) -> Self {
self.text_color = Some(text_color);
self
}
pub fn text_color_opt(mut self, text_color: Option<Srgba>) -> Self {
pub fn text_color_opt(mut self, text_color: Option<Color32>) -> Self {
self.text_color = text_color;
self
}