summaryrefslogtreecommitdiff
path: root/engine/UI/FlexElement.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/UI/FlexElement.go
parente071f6670cf2d379237bf9cc66bd99696e48df8d (diff)
Menu description pt. 1
Diffstat (limited to 'engine/UI/FlexElement.go')
-rw-r--r--engine/UI/FlexElement.go20
1 files changed, 17 insertions, 3 deletions
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)
+}