gx: add hex to rgb color

pull/3951/head
Nguyen Viet Hung 2020-03-07 16:30:35 +13:00 committed by GitHub
parent 58fb055763
commit f5a8d883d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -93,6 +93,15 @@ pub fn rgb(r, g, b int) Color {
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 {
// return text_width(char2string(c))
// // return C.text_width_char(c)

13
vlib/gx/gx_test.v 100644
View File

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