summaryrefslogtreecommitdiff
path: root/engine/Dynamic/Descriptors/Style.go
diff options
context:
space:
mode:
authorPhyscik <mynameisgennadiy@vk.com>2026-02-06 01:55:27 +0500
committerPhyscik <mynameisgennadiy@vk.com>2026-02-06 01:55:27 +0500
commit85666467056ccae2011128e0d38ea2dbd1efee8a (patch)
treefa91af8a8e9be05e6ef87a4ecddc6b3f0303dea4 /engine/Dynamic/Descriptors/Style.go
parente071f6670cf2d379237bf9cc66bd99696e48df8d (diff)
Menu description pt. 1
Diffstat (limited to 'engine/Dynamic/Descriptors/Style.go')
-rw-r--r--engine/Dynamic/Descriptors/Style.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/engine/Dynamic/Descriptors/Style.go b/engine/Dynamic/Descriptors/Style.go
new file mode 100644
index 0000000..b7b9510
--- /dev/null
+++ b/engine/Dynamic/Descriptors/Style.go
@@ -0,0 +1,78 @@
+package descriptors
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/gookit/color"
+
+ ui "github.com/DegustatorPonos/RuinesOfRafdolon/UI"
+ rl "github.com/gen2brain/raylib-go/raylib"
+)
+
+// Using this method instead of the base style structs allows us to use
+// hex values as colours since golang's implimetation of JSON deserializer
+// doesn't really like color.RGBA
+type StyleDescriptor struct {
+ BackgroundColor string
+ FontColor string
+ Padding *float32
+ Roundness *float32
+}
+
+func (base *StyleDescriptor) Parse() ui.Style {
+ var outp = ui.Style {
+ BacgroundColor: base.getBackgroundColor(),
+ FontColor: base.getFontColor(),
+ Roundness: base.Roundness,
+ Padding: base.Padding,
+ }
+ return outp
+}
+
+func (base *StyleDescriptor) getBackgroundColor() *rl.Color {
+ if len(base.BackgroundColor) == 0 {
+ return nil
+ }
+ var outp, err = parseColor(base.BackgroundColor)
+ if err != nil {
+ rl.TraceLog(rl.LogWarning, "Failed to parse the background color %s in style: %s", base.BackgroundColor, err.Error())
+ return nil
+ }
+ return outp
+}
+
+func (base *StyleDescriptor) getFontColor() *rl.Color {
+ if len(base.FontColor) == 0 {
+ return nil
+ }
+ var outp, err = parseColor(base.FontColor)
+ if err != nil {
+ rl.TraceLog(rl.LogWarning, "Failed to parse the font color %s in style: %s", base.FontColor, err.Error())
+ return nil
+ }
+ return outp
+}
+
+func parseColor(val string) (*rl.Color, error) {
+ val = strings.TrimPrefix(val, "#")
+ if !isColorValid(val) {
+ return nil, fmt.Errorf("Invalid color notation")
+ }
+ var parsed = color.HEX(val)
+ var outp = rl.NewColor(parsed[0], parsed[1], parsed[2], parsed[3])
+ // If there is no alpha cahnnel
+ if len(val) % 2 == 0 {
+ outp.A = 0xFF
+ }
+ return &outp, nil
+}
+
+func isColorValid(val string) bool {
+ switch len(val) {
+ // #RGB, #RGBA, #RRGGBB, #RRGGBBAA
+ case 3, 4, 6, 8:
+ return true
+ }
+ return false
+}