Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: colors convert from hex #1493

Closed
wants to merge 2 commits into from
Closed

feat: colors convert from hex #1493

wants to merge 2 commits into from

Conversation

kkharji
Copy link
Contributor

@kkharji kkharji commented Apr 13, 2022

Closes #1492

@kkharji
Copy link
Contributor Author

kkharji commented Apr 13, 2022

fix: resulting colors are incorrect

@emilk emilk marked this pull request as draft April 13, 2022 20:08
@kkharji
Copy link
Contributor Author

kkharji commented Apr 13, 2022

@emilk 🤔 that's odd one test fail with

thread 'color::test_to_hex_to_rgba' panicked at 'assertion failed: `(left == right)`
  left: `Color32([20, 1, 7, 2])`,
 right: `Color32([245, 40, 145, 255])`', epaint/src/color.rs:587:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I explicitly set rgba to Color32::from_rgba_unmultiplied(245, 40, 145, 2); but it produced [20, 1, 7, 2]

btw 2 because I wanted 0.2 not sure if this is correct

Comment on lines +585 to +587
let rgba = Color32::from_rgba_unmultiplied(245, 40, 145, 2);
let hex = Color32::from_hex("#f5289133").unwrap();
assert_eq!(rgba, hex);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let rgba = Color32::from_rgba_unmultiplied(245, 40, 145, 2);
let hex = Color32::from_hex("#f5289133").unwrap();
assert_eq!(rgba, hex);
let rgba = Color32::from_rgba_unmultiplied(0xf5, 0x28, 0x91, 0x33);
let hex = Color32::from_hex("#f5289133").unwrap();
assert_eq!(rgba, hex);

@emilk
Copy link
Owner

emilk commented Apr 14, 2022

The benefit with a macro (e.g. egui::color!(#f5289133)) is that errors can be caught at compilation time. If users want to have dynamic string they should probably be using one of the many css color parsing crates.

@emilk
Copy link
Owner

emilk commented Jul 3, 2022

Closed by #1596

@emilk emilk closed this Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color32 from hex value
2 participants