forked from mbk-lab/rui_orig
2
0
Fork 0

Added NamedColors() function

This commit is contained in:
Alexei Anoshenko 2022-04-14 17:58:58 +03:00
parent 8a625dcc78
commit 456744de82
1 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package rui
import "sort"
const (
// Black color constant
Black Color = 0xff000000
@ -446,3 +448,23 @@ var colorConstants = map[string]Color{
"whitesmoke": 0xfff5f5f5,
"yellowgreen": 0xff9acd32,
}
type NamedColor struct {
Name string
Color Color
}
// NamedColors returns the list of named colors
func NamedColors() []NamedColor {
count := len(colorConstants)
result := make([]NamedColor, 0, count)
for name, color := range colorConstants {
result = append(result, NamedColor{Name: name, Color: color})
}
sort.Slice(result, func(i, j int) bool {
return result[i].Name < result[j].Name
})
return result
}