From 85666467056ccae2011128e0d38ea2dbd1efee8a Mon Sep 17 00:00:00 2001 From: Physcik Date: Fri, 6 Feb 2026 01:55:27 +0500 Subject: Menu description pt. 1 --- engine/UI/GridRow.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'engine/UI/GridRow.go') 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) +} -- cgit v1.3