summaryrefslogtreecommitdiff
path: root/engine/UI/GridRow.go
diff options
context:
space:
mode:
authorPhyscik <mynameisgennadiy@vk.com>2026-02-02 02:00:29 +0500
committerPhyscik <mynameisgennadiy@vk.com>2026-02-02 02:00:29 +0500
commit7383f73a5b1589d3257b44407e46adfe987e2530 (patch)
tree8848132dea8f270df9d38ad508792b333b16aae2 /engine/UI/GridRow.go
parentb4bb2cc1de2004153a1357e2e6678df7377b42e3 (diff)
Span system rework pt 1
Diffstat (limited to 'engine/UI/GridRow.go')
-rw-r--r--engine/UI/GridRow.go75
1 files changed, 70 insertions, 5 deletions
diff --git a/engine/UI/GridRow.go b/engine/UI/GridRow.go
index bb9ffe3..4e222a7 100644
--- a/engine/UI/GridRow.go
+++ b/engine/UI/GridRow.go
@@ -1,25 +1,90 @@
package ui
-import rl "github.com/gen2brain/raylib-go/raylib"
+import (
+ "image/color"
+
+ rl "github.com/gen2brain/raylib-go/raylib"
+)
+
+var defaultGridPadding float32 = 0
+var defaultGridRoundness float32 = 0
+
+var defaultGridStyle = &Style {
+ BacgroundColor: &color.RGBA{0, 0, 0, 0},
+ FontColor: &rl.DarkGray,
+ Padding: &defaultGridPadding,
+ Roundness: &defaultGridRoundness,
+}
type GridRow struct {
// A portion of the screen the row will occupy. Works similar to CSS's 'flex-grow'
HeightWeight float32
// The objects that lay in this row
Objects []UIElement
+ // Spaces between the columns
+ Spacing float32
+ // Styling preferences
+ Style *Style
location rl.Rectangle
+ cache layoutCache
+}
+
+func (base *GridRow) GetElements() []UIElement {
+ return base.Objects
+}
+
+func (base *GridRow) GetSpacing() float32 {
+ return base.Spacing
}
func (base *GridRow) Init(parent *Menu) {
+ base.Style = InitStyle(base.Style, defaultGridStyle)
for _, v := range base.Objects {
v.Init(parent)
}
+ base.cache = layoutCache {
+ ScreenResolution: rl.Vector2{ X:0, Y:0 },
+ }
}
-func (base *GridRow) Draw(span rl.Rectangle) {
- // TODO: Add horizontal spacing
- for _, v := range base.Objects {
- v.Draw(&span)
+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
+}
+
+// Draw the element with the given size
+func (base *GridRow) Draw(span *rl.Rectangle) {
+ if !base.cache.IsValid() {
+ base.RecalculateCache(span)
+ }
+ for i, v := range base.Objects {
+ var offset = base.cache.RowLocations[i]
+ var elemSpan = rl.Rectangle {
+ X: offset.X,
+ Y: span.Y + *base.Style.Padding,
+ Width: offset.Y,
+ Height: span.Height - *base.Style.Padding * 2,
+ }
+ v.Draw(&elemSpan)
+ }
+}
+
+func (base *GridRow) RecalculateCache(span *rl.Rectangle) {
+ base.cache.SpanResolution = rl.Vector2{
+ X: span.Width,
+ Y: span.Height,
+ }
+ base.cache.ScreenResolution = rl.Vector2 {
+ X: float32(rl.GetScreenWidth()),
+ Y: float32(rl.GetScreenHeight()),
}
+ base.cache.CalculateOffsets(span.Width, span.Height, *base.Style.Padding, *base.Style.Padding)
+ var weightToScale = getWeightToPixelsRatio(base, base.cache.Width)
+ var spacingPx = base.Spacing * span.Width
+ rl.TraceLog(rl.LogInfo, "Spacing: %v (%v px)", base.Spacing, spacingPx)
+ base.cache.CalculateRowsLocations(base.Objects, weightToScale, spacingPx, span.X)
}