summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/Dynamic/Descriptors/Style.go78
-rw-r--r--engine/Dynamic/Descriptors/UIElement.go84
-rw-r--r--engine/Dynamic/Manager.go2
-rw-r--r--engine/MainMenu.json21
-rw-r--r--engine/UI/Button.go5
-rw-r--r--engine/UI/FlexElement.go20
-rw-r--r--engine/UI/GridColumn.go13
-rw-r--r--engine/UI/GridRow.go24
-rw-r--r--engine/UI/Label.go24
-rw-r--r--engine/UI/Menu.go12
-rw-r--r--engine/UI/Style.go8
-rw-r--r--engine/UI/Void.go36
-rw-r--r--engine/go.mod5
-rw-r--r--engine/go.sum4
-rw-r--r--engine/main.go78
15 files changed, 357 insertions, 57 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
+}
diff --git a/engine/Dynamic/Descriptors/UIElement.go b/engine/Dynamic/Descriptors/UIElement.go
new file mode 100644
index 0000000..e0540ee
--- /dev/null
+++ b/engine/Dynamic/Descriptors/UIElement.go
@@ -0,0 +1,84 @@
+package descriptors
+
+import (
+ "fmt"
+ "strings"
+
+ ui "github.com/DegustatorPonos/RuinesOfRafdolon/UI"
+ rl "github.com/gen2brain/raylib-go/raylib"
+)
+
+type UIElementDescriptor struct {
+ Type string
+ Weight float32
+ Style StyleDescriptor
+
+ // For labels
+ Text string
+ Alignment string
+
+ // For grid elements
+ Children []UIElementDescriptor
+ Spacing float32
+}
+
+func InitUIParser() {
+ typeParsers = map[string]func(*UIElementDescriptor) ui.UIElement {
+ ui.VoidTypeName: parseAsVoid,
+ ui.LabelTypeName: parseAsLabel,
+ ui.GridRowTypeName: parseAsGridRow,
+ }
+}
+
+// The item type to its parser relationship
+var typeParsers map[string]func(*UIElementDescriptor) ui.UIElement
+
+func (base *UIElementDescriptor) Parse() (ui.UIElement, error) {
+ var elemType = strings.ToLower(base.Type)
+ var descFunc, exists = typeParsers[elemType]
+ if exists {
+ return descFunc(base), nil
+ }
+ return nil, fmt.Errorf("Unknown UI element type")
+}
+
+func parseAsVoid(base *UIElementDescriptor) ui.UIElement {
+ return &ui.Void {
+ Weight: base.Weight,
+ }
+}
+
+func parseAsLabel(base *UIElementDescriptor) ui.UIElement {
+ var alignment ui.TextAlignment
+ switch strings.ToLower(base.Alignment) {
+ case "center":
+ alignment = ui.Center
+ case "start":
+ alignment = ui.Start
+ }
+
+ return &ui.Label {
+ WidthWeight: base.Weight,
+ Text: base.Text,
+ Alignment: alignment,
+ Style: base.Style.Parse(),
+ }
+}
+
+func parseAsGridRow(base *UIElementDescriptor) ui.UIElement {
+ var outp = ui.GridRow {
+ Weight: base.Weight,
+ Spacing: base.Spacing,
+ Style: base.Style.Parse(),
+ Objects: make([]ui.UIElement, 0, len(base.Children)),
+ }
+ for _, v := range base.Children {
+ var child, parseErr = v.Parse()
+ if parseErr != nil {
+ rl.TraceLog(rl.LogWarning, "Failed to parse a parent element of a grid row: %v", parseErr.Error())
+ continue
+ }
+ outp.Objects = append(outp.Objects, child)
+ }
+ return &outp
+}
diff --git a/engine/Dynamic/Manager.go b/engine/Dynamic/Manager.go
index 5e2001c..e67b0a8 100644
--- a/engine/Dynamic/Manager.go
+++ b/engine/Dynamic/Manager.go
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
+ descriptors "github.com/DegustatorPonos/RuinesOfRafdolon/Dynamic/Descriptors"
settings "github.com/DegustatorPonos/RuinesOfRafdolon/Settings"
utils "github.com/DegustatorPonos/RuinesOfRafdolon/Utils"
rl "github.com/gen2brain/raylib-go/raylib"
@@ -46,6 +47,7 @@ func loadPackages() (*PackageManager, error) {
// Loads the packages from the specified in settings directory. Panics on serious error
func Init() {
+ descriptors.InitUIParser()
var manager, err = loadPackages()
if err != nil {
panic(fmt.Sprintf("Failed to load packages: %v", err.Error()))
diff --git a/engine/MainMenu.json b/engine/MainMenu.json
new file mode 100644
index 0000000..e154ae0
--- /dev/null
+++ b/engine/MainMenu.json
@@ -0,0 +1,21 @@
+{
+ "Type": "gridrow",
+ "Weight": 2,
+ "Children": [
+ {
+ "Type": "label",
+ "Text": "xdd",
+ "Style": {
+ "Padding": 0,
+ "BackgroundColor": "#FFAAFF"
+ }
+ },
+ {
+ "Type": "label",
+ "Text": "xdd",
+ "Style": {
+ "Padding": 0
+ }
+ }
+ ]
+}
diff --git a/engine/UI/Button.go b/engine/UI/Button.go
index a8b9168..f865c5f 100644
--- a/engine/UI/Button.go
+++ b/engine/UI/Button.go
@@ -16,6 +16,7 @@ type Button struct {
DisplayElement UIElement
EventType DetectionType
ButtonType rl.MouseButton
+ OnClick func()
clicked func(rl.MouseButton) bool
}
@@ -43,10 +44,10 @@ func (base *Button) GetOccupationWeight() float32 {
func (base *Button) Draw(position *rl.Rectangle) {
base.DisplayElement.Draw(position)
- if base.clicked(base.ButtonType) {
+ if base.OnClick != nil && base.clicked(base.ButtonType) {
var mousePos = rl.GetMousePosition()
if rl.CheckCollisionPointRec(mousePos, *position) {
- rl.TraceLog(rl.LogInfo, "xdx")
+ base.OnClick()
}
}
}
diff --git a/engine/UI/FlexElement.go b/engine/UI/FlexElement.go
index b8d1b38..4ec0f35 100644
--- a/engine/UI/FlexElement.go
+++ b/engine/UI/FlexElement.go
@@ -1,6 +1,8 @@
package ui
import (
+ "encoding/json"
+ "fmt"
"image/color"
rl "github.com/gen2brain/raylib-go/raylib"
@@ -32,13 +34,14 @@ func getWeightToPixelsRatio(base flexElement, totalSpace float32) float32 {
}
var spacingPx = totalSpace * base.GetSpacing()
var totalSpacing = float32(len(elements) - 1) * spacingPx
- if totalSpace < 0 {
- totalSpace = 0
+ if totalSpacing < 0 {
+ totalSpacing = 0
}
+ rl.TraceLog(rl.LogInfo, "SpacingPx %v \t Total spacing: %v", spacingPx, totalSpacing)
return (totalSpace - totalSpacing) / totalWeights
}
-
+// A list of values that are used in the span calculations
type layoutCache struct {
// The screen resolution the cache was calculated for
ScreenResolution rl.Vector2
@@ -62,6 +65,7 @@ func (base layoutCache) IsValid() bool {
base.ScreenResolution.Y == float32(rl.GetScreenHeight())
}
+// Fills in the offsets and width/height of a layout
func (base *layoutCache) CalculateOffsets(X float32, Y float32, paddingX float32, paddingY float32) {
base.OffsetX = (X * paddingX)
base.OffsetY = (Y * paddingY)
@@ -69,6 +73,8 @@ func (base *layoutCache) CalculateOffsets(X float32, Y float32, paddingX float32
base.Height = Y - base.OffsetY * 2
}
+// Fills in the RowLocations field of the cache.
+// Requires rows, WeightToPixels multiplyer, spacing (in px) and base offset (in px) that will be used as a start of a span.
func (base *layoutCache) CalculateRowsLocations (rows []UIElement, WeightToPixels float32, spacing float32, baseOffset float32) {
base.RowLocations = make([]rl.Vector2, len(rows))
var ptr float32 = baseOffset
@@ -82,3 +88,11 @@ func (base *layoutCache) CalculateRowsLocations (rows []UIElement, WeightToPixel
ptr += elemSpace + spacing
}
}
+
+func (base layoutCache) String() string {
+ var outp, jsonErr = json.Marshal(base)
+ if jsonErr != nil {
+ return fmt.Sprintf("Failed to parse settings: %s", jsonErr.Error())
+ }
+ return string(outp)
+}
diff --git a/engine/UI/GridColumn.go b/engine/UI/GridColumn.go
index 359d0d4..b933cf4 100644
--- a/engine/UI/GridColumn.go
+++ b/engine/UI/GridColumn.go
@@ -4,20 +4,20 @@ import rl "github.com/gen2brain/raylib-go/raylib"
type GridColumn struct {
// A portion of the screen the row will occupy. Works similar to CSS's 'flex-grow'
- WidthWeight float32
- // The objects that lay in this row
- Spacing float32
+ Weight float32
// Spaces between the columns
Objects []UIElement
+ // The objects that lay in this row
+ Spacing float32
// Styling preferences
- Style *Style
+ Style Style `json:"-"`
location rl.Rectangle
cache layoutCache
}
func (base *GridColumn) Init(parent *Menu) {
- base.Style = InitStyle(base.Style, defaultGridStyle)
+ base.Style.FillMissing(defaultGridStyle)
for _, v := range base.Objects {
v.Init(parent)
}
@@ -31,7 +31,7 @@ func (base *GridColumn) Destroy() {
// Gets the scale width of the element. Works similar to CSS's 'flex-grow'
func (base *GridColumn) GetOccupationWeight() float32 {
- return base.WidthWeight
+ return base.Weight
}
// Draw the element with the given size
@@ -41,6 +41,7 @@ func (base *GridColumn) Draw(span *rl.Rectangle) {
}
for i, v := range base.Objects {
var offset = base.cache.RowLocations[i]
+ rl.TraceLog(rl.LogInfo, "Cache: %v", base.cache)
var elemSpan = rl.Rectangle {
X: span.X + *base.Style.Padding,
Y: offset.X,
diff --git a/engine/UI/GridRow.go b/engine/UI/GridRow.go
index 3139d97..4940948 100644
--- a/engine/UI/GridRow.go
+++ b/engine/UI/GridRow.go
@@ -1,18 +1,23 @@
package ui
import (
+ "encoding/json"
+ "fmt"
+
rl "github.com/gen2brain/raylib-go/raylib"
)
+const GridRowTypeName string = "gridrow"
+
type GridRow struct {
// A portion of the screen the row will occupy. Works similar to CSS's 'flex-grow'
- HeightWeight float32
+ Weight float32
// The objects that lay in this row
Objects []UIElement
// Spaces between the columns
Spacing float32
// Styling preferences
- Style *Style
+ Style Style `json:"-"`
location rl.Rectangle
cache layoutCache
@@ -27,7 +32,7 @@ func (base *GridRow) GetSpacing() float32 {
}
func (base *GridRow) Init(parent *Menu) {
- base.Style = InitStyle(base.Style, defaultGridStyle)
+ base.Style.FillMissing(defaultGridStyle)
for _, v := range base.Objects {
v.Init(parent)
}
@@ -41,7 +46,7 @@ func (base *GridRow) Destroy() {
// Gets the scale width of the element. Works similar to CSS's 'flex-grow'
func (base *GridRow) GetOccupationWeight() float32 {
- return base.HeightWeight
+ return base.Weight
}
// Draw the element with the given size
@@ -51,6 +56,7 @@ func (base *GridRow) Draw(span *rl.Rectangle) {
}
for i, v := range base.Objects {
var offset = base.cache.RowLocations[i]
+ // rl.TraceLog(rl.LogInfo, "Cache: %v", base.cache)
var elemSpan = rl.Rectangle {
X: offset.X,
Y: span.Y + *base.Style.Padding,
@@ -70,8 +76,18 @@ func (base *GridRow) RecalculateCache(span *rl.Rectangle) {
X: float32(rl.GetScreenWidth()),
Y: float32(rl.GetScreenHeight()),
}
+ rl.TraceLog(rl.LogInfo, "Span: %vx%v \tPadding: %v", span.Width, span.Height, *base.Style.Padding)
base.cache.CalculateOffsets(span.Width, span.Height, *base.Style.Padding, *base.Style.Padding)
var weightToScale = getWeightToPixelsRatio(base, base.cache.Width)
+ rl.TraceLog(rl.LogInfo, "Ratio: %v", weightToScale)
var spacingPx = base.Spacing * span.Width
base.cache.CalculateRowsLocations(base.Objects, weightToScale, spacingPx, span.X)
}
+
+func (base GridRow) String() string {
+ var outp, jsonErr = json.Marshal(base)
+ if jsonErr != nil {
+ return fmt.Sprintf("Failed to parse settings: %s", jsonErr.Error())
+ }
+ return string(outp)
+}
diff --git a/engine/UI/Label.go b/engine/UI/Label.go
index 3a3528f..53c6e96 100644
--- a/engine/UI/Label.go
+++ b/engine/UI/Label.go
@@ -1,8 +1,15 @@
package ui
-import rl "github.com/gen2brain/raylib-go/raylib"
+import (
+ "encoding/json"
+ "fmt"
-var defaultLabelPadding float32 = 5
+ rl "github.com/gen2brain/raylib-go/raylib"
+)
+
+const LabelTypeName string = "label"
+
+var defaultLabelPadding float32 = 0.1
var defaultLabelRoundness float32 = 0.2
// If the text formation formula is applied without it the text is
@@ -13,7 +20,7 @@ var defaultLabelStyle = &Style{
BacgroundColor: &rl.LightGray,
FontColor: &rl.DarkGray,
Padding: &defaultLabelPadding,
- Roundness: &defaultLabelRoundness ,
+ Roundness: &defaultLabelRoundness,
}
type TextAlignment uint8
@@ -23,12 +30,13 @@ const (
Start
)
+// A UI element containing a text field
type Label struct {
WidthWeight float32
Text string
Alignment TextAlignment
- Style Style
+ Style Style `json:"-"`
}
func (base *Label) Init(*Menu) {
@@ -73,3 +81,11 @@ func (base *Label) getTextHeight(position *rl.Rectangle) int32 {
}
return int32(outp)
}
+
+func (base Label) String() string {
+ var outp, jsonErr = json.Marshal(base)
+ if jsonErr != nil {
+ return fmt.Sprintf("Failed to parse settings: %s", jsonErr.Error())
+ }
+ return string(outp)
+}
diff --git a/engine/UI/Menu.go b/engine/UI/Menu.go
index fa3888b..32e0dcc 100644
--- a/engine/UI/Menu.go
+++ b/engine/UI/Menu.go
@@ -1,6 +1,9 @@
package ui
import (
+ "encoding/json"
+ "fmt"
+
coreobjects "github.com/DegustatorPonos/RuinesOfRafdolon/CoreObjects"
settings "github.com/DegustatorPonos/RuinesOfRafdolon/Settings"
rl "github.com/gen2brain/raylib-go/raylib"
@@ -23,6 +26,7 @@ func (base *Menu) Create(manager *coreobjects.SceneManager) {
base.manager = manager
base.cache = &layoutCache{}
base.Contents.Init(base)
+ // rl.TraceLog(rl.LogInfo, "Parsed: %s", base)
}
func (base *Menu) Destroy() {
@@ -92,3 +96,11 @@ func (base *Menu) RecalculateCache() {
base.PaddingX,
base.PaddingY)
}
+
+func (base Menu) String() string {
+ var outp, jsonErr = json.MarshalIndent(base, "", " ")
+ if jsonErr != nil {
+ return fmt.Sprintf("Failed to parse: %s", jsonErr.Error())
+ }
+ return string(outp)
+}
diff --git a/engine/UI/Style.go b/engine/UI/Style.go
index 1e05bcf..f308fba 100644
--- a/engine/UI/Style.go
+++ b/engine/UI/Style.go
@@ -17,16 +17,16 @@ type Style struct {
// Fills up not specifiend elements with default ones
func (base *Style) FillMissing(defaultStyle *Style) {
if base.BacgroundColor == nil {
- base.BacgroundColor = defaultLabelStyle.BacgroundColor
+ base.BacgroundColor = defaultStyle.BacgroundColor
}
if base.Padding == nil {
- base.Padding = defaultLabelStyle.Padding
+ base.Padding = defaultStyle.Padding
}
if base.FontColor == nil {
- base.FontColor = defaultLabelStyle.FontColor
+ base.FontColor = defaultStyle.FontColor
}
if base.Roundness == nil {
- base.Roundness = defaultLabelStyle.Roundness
+ base.Roundness = defaultStyle.Roundness
}
}
diff --git a/engine/UI/Void.go b/engine/UI/Void.go
new file mode 100644
index 0000000..f167f30
--- /dev/null
+++ b/engine/UI/Void.go
@@ -0,0 +1,36 @@
+package ui
+
+import (
+ "encoding/json"
+ "fmt"
+
+ rl "github.com/gen2brain/raylib-go/raylib"
+)
+
+type Void struct {
+ Weight float32
+}
+
+// Used in the element parsing from JSON
+const VoidTypeName string = "void"
+
+func (base *Void) Init(*Menu) {
+}
+
+func (base *Void) Destroy() {
+}
+
+func (base *Void) GetOccupationWeight() float32 {
+ return base.Weight
+}
+
+func (base *Void) Draw(*rl.Rectangle) {
+}
+
+func (base Void) String() string {
+ var outp, jsonErr = json.Marshal(base)
+ if jsonErr != nil {
+ return fmt.Sprintf("Failed to parse settings: %s", jsonErr.Error())
+ }
+ return string(outp)
+}
diff --git a/engine/go.mod b/engine/go.mod
index f318073..0e7b30f 100644
--- a/engine/go.mod
+++ b/engine/go.mod
@@ -2,9 +2,12 @@ module github.com/DegustatorPonos/RuinesOfRafdolon
go 1.25.4
+require github.com/gen2brain/raylib-go/raylib v0.55.1
+
require (
github.com/ebitengine/purego v0.9.1 // indirect
- github.com/gen2brain/raylib-go/raylib v0.55.1 // indirect
+ github.com/gookit/color v1.6.0 // indirect
+ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 // indirect
golang.org/x/sys v0.39.0 // indirect
)
diff --git a/engine/go.sum b/engine/go.sum
index 91b100b..ac27249 100644
--- a/engine/go.sum
+++ b/engine/go.sum
@@ -2,6 +2,10 @@ github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s
github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/gen2brain/raylib-go/raylib v0.55.1 h1:1rdc10WvvYjtj7qijHnV9T38/WuvlT6IIL+PaZ6cNA8=
github.com/gen2brain/raylib-go/raylib v0.55.1/go.mod h1:BaY76bZk7nw1/kVOSQObPY1v1iwVE1KHAGMfvI6oK1Q=
+github.com/gookit/color v1.6.0 h1:JjJXBTk1ETNyqyilJhkTXJYYigHG24TM9Xa2M1xAhRA=
+github.com/gookit/color v1.6.0/go.mod h1:9ACFc7/1IpHGBW8RwuDm/0YEnhg3dwwXpoMsmtyHfjs=
+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 h1:fQsdNF2N+/YewlRZiricy4P1iimyPKZ/xwniHj8Q2a0=
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
diff --git a/engine/main.go b/engine/main.go
index de8ff34..b9fb611 100644
--- a/engine/main.go
+++ b/engine/main.go
@@ -1,11 +1,14 @@
package main
import (
+ "encoding/json"
"log"
+ "os"
components "github.com/DegustatorPonos/RuinesOfRafdolon/Components"
coreobjects "github.com/DegustatorPonos/RuinesOfRafdolon/CoreObjects"
dynamic "github.com/DegustatorPonos/RuinesOfRafdolon/Dynamic"
+ descriptors "github.com/DegustatorPonos/RuinesOfRafdolon/Dynamic/Descriptors"
render "github.com/DegustatorPonos/RuinesOfRafdolon/Render"
settings "github.com/DegustatorPonos/RuinesOfRafdolon/Settings"
ui "github.com/DegustatorPonos/RuinesOfRafdolon/UI"
@@ -28,55 +31,64 @@ func main() {
}
log.Printf("Resource manager: %s", &components.Resources)
- // var field = descriptor.GenerateMap()
-
-
var manager = coreobjects.InitSceneManager()
// render.StartLoop(manager, components.Resources.Worlds["MainWorld"])
var menu = menu_test()
render.StartLoop(manager, menu)
}
+func test_desc() (ui.UIElement, error) {
+ var file, fErr = os.ReadFile("MainMenu.json")
+ if fErr != nil {
+ return nil, fErr
+ }
+ var desc = descriptors.UIElementDescriptor{}
+ if jsonErr := json.Unmarshal(file, &desc); jsonErr != nil {
+ return nil, jsonErr
+ }
+ var parsed, parseErr = desc.Parse()
+ if parseErr != nil {
+ return nil, parseErr
+ }
+ return parsed, nil
+}
+
func menu_test() *ui.Menu {
+ var loadedMenu, loadErr = test_desc()
+ if loadErr != nil {
+ panic(loadErr.Error())
+ }
+
+ var prerender = false
+
+ if !prerender {
+ return &ui.Menu {
+ PaddingX: 0.05,
+ PaddingY: 0.1,
+ Contents: loadedMenu,
+ }
+ }
+
return &ui.Menu {
PaddingX: 0.05,
PaddingY: 0.1,
- Contents: &ui.GridColumn{
- Spacing: 0.025,
+ Contents: &ui.GridColumn {
+ Weight: 2,
Objects: []ui.UIElement {
- &ui.GridRow {
- HeightWeight: 1,
- Spacing: 0.01,
- Objects: []ui.UIElement {
- &ui.Label{ Text: "First piece" },
- &ui.Label{ Text: "Wide piece", WidthWeight: 2 },
- &ui.Label{ Text: "Another piece" },
+ &ui.Label {
+ Text: "xdx",
+ Style: ui.Style {
+ BacgroundColor: &rl.Pink,
},
},
- &ui.GridRow {
- HeightWeight: 2,
- Objects: []ui.UIElement {
- &ui.Button {
- EventType: ui.OnClick,
- DisplayElement: &ui.Label {
- Text: "Center button",
- Alignment: ui.Center,
- Style: ui.Style {
- BacgroundColor: &rl.Pink,
- },
- },
- },
- },
- },
- &ui.GridRow {
- HeightWeight: 1,
- Objects: []ui.UIElement {
- &ui.Label{ Text: "A very very long text that is bigger than a window" },
+ &ui.Label {
+ Text: "xdx",
+ Style: ui.Style {
+ BacgroundColor: &rl.Pink,
},
},
},
},
- // Rows: []ui.UIElement {
- // },
}
+
}