diff options
| -rw-r--r-- | engine/UI/GridRow.go | 1 | ||||
| -rw-r--r-- | engine/UI/Label.go | 21 | ||||
| -rw-r--r-- | engine/main.go | 5 |
3 files changed, 20 insertions, 7 deletions
diff --git a/engine/UI/GridRow.go b/engine/UI/GridRow.go index 4e222a7..fed6051 100644 --- a/engine/UI/GridRow.go +++ b/engine/UI/GridRow.go @@ -85,6 +85,5 @@ func (base *GridRow) RecalculateCache(span *rl.Rectangle) { 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) } diff --git a/engine/UI/Label.go b/engine/UI/Label.go index e864c85..3a3528f 100644 --- a/engine/UI/Label.go +++ b/engine/UI/Label.go @@ -16,9 +16,17 @@ var defaultLabelStyle = &Style{ Roundness: &defaultLabelRoundness , } +type TextAlignment uint8 + +const ( + Center TextAlignment = iota + Start +) + type Label struct { WidthWeight float32 - Text string + Text string + Alignment TextAlignment Style Style } @@ -39,10 +47,15 @@ func (base *Label) Draw(position *rl.Rectangle) { *base.Style.Roundness, 0, // Assume the segments param is always 0 - it doesn't really matter without a border *base.Style.BacgroundColor) + var textHeight = base.getTextHeight(position) + var textY = int32(position.Y + *base.Style.Padding) + if base.Alignment == Center { + textY += (int32(position.Height) - textHeight) / 2 + } rl.DrawText(base.Text, - int32(position.X+*base.Style.Padding), - int32(position.Y+*base.Style.Padding), - base.getTextHeight(position), + int32(position.X + *base.Style.Padding), + textY, + textHeight, *base.Style.FontColor) } diff --git a/engine/main.go b/engine/main.go index ea29794..9a8030a 100644 --- a/engine/main.go +++ b/engine/main.go @@ -58,9 +58,10 @@ func menu_test() *ui.Menu { &ui.Button { EventType: ui.OnClick, DisplayElement: &ui.Label { - Text: "Center div", + Text: "Center button", + Alignment: ui.Center, Style: ui.Style { - BacgroundColor: &rl.White, + BacgroundColor: &rl.Pink, }, }, }, |
