From 456744de8266e67fa702ee4f86376f814d623638 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Thu, 14 Apr 2022 17:58:58 +0300 Subject: [PATCH] Added NamedColors() function --- colorConstants.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/colorConstants.go b/colorConstants.go index dee5c48..5d194e9 100644 --- a/colorConstants.go +++ b/colorConstants.go @@ -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 +}