Repository: iced-rs/iced (language: rust)

Issue:
Bad short hex format handling in macro color!()
### Is your issue REALLY a bug?

- [X] My issue is indeed a bug!
- [X] I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

### Is there an existing issue for this?

- [X] I have searched the existing issues.

### Is this issue related to iced?

- [X] My hardware is compatible and my graphics drivers are up-to-date.

### What happened?

Using the macro color!() with the value 0x0000ff produces the wrong color.
Here is the debug print:
`color!(0x0000ff) = Color {
    r: 0.0,
    g: 1.0,
    b: 1.0,
    a: 1.0,
}`

### What is the expected behavior?

Expected behavior is:
`color!(0x0000ff) = Color {
    r: 0.0,
    g: 0.0,
    b: 1.0,
    a: 1.0,
}`

I believe the problem is in this line.
Its a pretty bad way to handle short form hex.
https://github.com/iced-rs/iced/blob/b78b8bc8e3c8dcb778b4e76bb9ef0ab1b88f633d/core/src/color.rs#L269

### Version

crates.io release

### Operating System

macOS

### Do you have any log output?

_No response_


Discussion / hints:

Fix patch:
diff --git a/core/src/color.rs b/core/src/color.rs
index 46fe9ecd97..827d028953 100644
--- a/core/src/color.rs
+++ b/core/src/color.rs
@@ -229,13 +229,12 @@ impl From<[f32; 4]> for Color {
 /// assert_eq!(color!(0, 0, 0, 0.0), Color::TRANSPARENT);
 /// assert_eq!(color!(0xffffff), Color::from_rgb(1.0, 1.0, 1.0));
 /// assert_eq!(color!(0xffffff, 0.), Color::from_rgba(1.0, 1.0, 1.0, 0.0));
-/// assert_eq!(color!(0x123), Color::from_rgba8(0x11, 0x22, 0x33, 1.0));
-/// assert_eq!(color!(0x123), color!(0x112233));
+/// assert_eq!(color!(0x0000ff), Color::from_rgba(0.0, 0.0, 1.0, 1.0));
 /// ```
 #[macro_export]
 macro_rules! color {
     ($r:expr, $g:expr, $b:expr) => {
-        color!($r, $g, $b, 1.0)
+        $crate::color!($r, $g, $b, 1.0)
     };
     ($r:expr, $g:expr, $b:expr, $a:expr) => {{
         let r = $r as f32 / 255.0;
@@ -261,29 +260,18 @@ macro_rules! color {
         $crate::Color { r, g, b, a: $a }
     }};
     ($hex:expr) => {{
-        color!($hex, 1.0)
+        $crate::color!($hex, 1.0)
     }};
     ($hex:expr, $a:expr) => {{
         let hex = $hex as u32;
 
-        if hex <= 0xfff {
-            let r = (hex & 0xf00) >> 8;
-            let g = (hex & 0x0f0) >> 4;
-            let b = (hex & 0x00f);
+        debug_assert!(hex <= 0xffffff, "color! value must not exceed 0xffffff");
 
-            color!((r << 4 | r), (g << 4 | g), (b << 4 | b), $a)
-        } else {
-            debug_assert!(
-                hex <= 0xffffff,
-                "color! value must not exceed 0xffffff"
-            );
+        let r = (hex & 0xff0000) >> 16;
+        let g = (hex & 0xff00) >> 8;
+        let b = (hex & 0xff);
 
-            let r = (hex & 0xff0000) >> 16;
-            let g = (hex & 0xff00) >> 8;
-            let b = (hex & 0xff);
-
-            color!(r, g, b, $a)
-        }
+        $crate::color!(r, g, b, $a)
     }};
 }
 


Test patch: