gx: add hex to rgb color
parent
58fb055763
commit
f5a8d883d2
|
@ -93,6 +93,15 @@ pub fn rgb(r, g, b int) Color {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hex(color int) Color {
|
||||||
|
res := Color {
|
||||||
|
r: (color >> 16) & 0xFF
|
||||||
|
g: (color >> 8) & 0xFF
|
||||||
|
b: color & 0xFF
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
// fn text_width_char(c char) int {
|
// fn text_width_char(c char) int {
|
||||||
// return text_width(char2string(c))
|
// return text_width(char2string(c))
|
||||||
// // return C.text_width_char(c)
|
// // return C.text_width_char(c)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import gx
|
||||||
|
|
||||||
|
fn test_hex() {
|
||||||
|
// valid colors
|
||||||
|
color_a := gx.hex(0x6c5ce7)
|
||||||
|
color_b := gx.rgb(108, 92, 231)
|
||||||
|
assert color_a.eq(color_b) == true
|
||||||
|
|
||||||
|
// doesn't give right value with short hex value
|
||||||
|
short_color := gx.hex(0xfff)
|
||||||
|
white_color := gx.rgb(255, 255, 255)
|
||||||
|
assert short_color.eq(white_color) == false
|
||||||
|
}
|
Loading…
Reference in New Issue