From f27f67b76be7ce614680487e85fb2728d5c53ea8 Mon Sep 17 00:00:00 2001 From: Erlend Walstad <96946613+lampsitter@users.noreply.github.com> Date: Mon, 16 May 2022 16:38:14 +0200 Subject: [PATCH] Make color-hex optional (#1632) --- egui/Cargo.toml | 2 ++ egui/src/lib.rs | 4 +++- epaint/CHANGELOG.md | 2 +- epaint/Cargo.toml | 3 +-- epaint/src/color.rs | 3 +++ epaint/src/lib.rs | 1 + 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/egui/Cargo.toml b/egui/Cargo.toml index 1d28c1e0..35434fc1 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -46,6 +46,8 @@ persistence = ["serde", "epaint/serde", "ron"] # implement serde on most types. serde = ["dep:serde", "epaint/serde"] +# Ease of use hex to Color32 macro +color-hex = ["epaint/color-hex"] [dependencies] epaint = { version = "0.18.1", path = "../epaint", default-features = false } diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 0f5d45a1..1ed39060 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -322,8 +322,10 @@ pub use epaint; pub use epaint::emath; pub use emath::{lerp, pos2, remap, remap_clamp, vec2, Align, Align2, NumExt, Pos2, Rect, Vec2}; +#[cfg(feature = "color-hex")] +pub use epaint::hex_color; pub use epaint::{ - color, hex_color, mutex, + color, mutex, text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak}, textures::TexturesDelta, ClippedPrimitive, Color32, ColorImage, FontImage, ImageData, Mesh, PaintCallback, diff --git a/epaint/CHANGELOG.md b/epaint/CHANGELOG.md index 45949d28..6d437345 100644 --- a/epaint/CHANGELOG.md +++ b/epaint/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to the epaint crate will be documented in this file. ## Unreleased * Optimize tessellation of filled circles by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)). -* Added `epaint::hex_rgb*!()` macros to create Color32's from hex strings ([#1596](https://github.com/emilk/egui/pull/1596)). +* Added `epaint::hex_color` macro to create Color32's from hex strings under the `color-hex` feature ([#1596](https://github.com/emilk/egui/pull/1596)). ## 0.18.1 - 2022-05-01 * Change `Shape::Callback` from `&dyn Any` to `&mut dyn Any` to support more backends. diff --git a/epaint/Cargo.toml b/epaint/Cargo.toml index 2a39aad0..1b414c5f 100644 --- a/epaint/Cargo.toml +++ b/epaint/Cargo.toml @@ -53,9 +53,8 @@ emath = { version = "0.18.0", path = "../emath" } ab_glyph = "0.2.11" nohash-hasher = "0.2" -color-hex = "0.2.0" - # Optional: +color-hex = { version = "0.2.0", optional = true } ahash = { version = "0.7", default-features = false, features = ["std"] } bytemuck = { version = "1.7.2", optional = true, features = ["derive"] } cint = { version = "0.3.1", optional = true } diff --git a/epaint/src/color.rs b/epaint/src/color.rs index c603872d..7a531c44 100644 --- a/epaint/src/color.rs +++ b/epaint/src/color.rs @@ -192,6 +192,7 @@ impl Color32 { /// assert_eq!(hex_color!("#202122"), Color32::from_rgb(0x20, 0x21, 0x22)); /// assert_eq!(hex_color!("#abcdef12"), Color32::from_rgba_unmultiplied(0xab, 0xcd, 0xef, 0x12)); /// ``` +#[cfg(feature = "color-hex")] #[macro_export] macro_rules! hex_color { ($s:literal) => {{ @@ -205,6 +206,7 @@ macro_rules! hex_color { }}; } +#[cfg(feature = "color-hex")] #[test] fn test_from_rgb_hex() { assert_eq!(Color32::from_rgb(0x20, 0x21, 0x22), hex_color!("#202122")); @@ -214,6 +216,7 @@ fn test_from_rgb_hex() { ); } +#[cfg(feature = "color-hex")] #[test] fn test_from_rgba_hex() { assert_eq!( diff --git a/epaint/src/lib.rs b/epaint/src/lib.rs index 5cd17c1f..f4a9e3a1 100644 --- a/epaint/src/lib.rs +++ b/epaint/src/lib.rs @@ -49,6 +49,7 @@ pub use emath::{pos2, vec2, Pos2, Rect, Vec2}; pub use ahash; pub use emath; +#[cfg(feature = "color-hex")] pub use color_hex; /// The UV coordinate of a white region of the texture mesh.