diff options
| author | Physcik <mynameisgennadiy@vk.com> | 2026-02-02 13:29:21 +0500 |
|---|---|---|
| committer | Physcik <mynameisgennadiy@vk.com> | 2026-02-02 13:29:21 +0500 |
| commit | 7d0b734ddf915d2f585d972a347c5203e8ef2ba7 (patch) | |
| tree | 23c44e4a5838aa268093f3876be081c6886130bf /engine/UI | |
| parent | 7383f73a5b1589d3257b44407e46adfe987e2530 (diff) | |
Label text centering
Diffstat (limited to 'engine/UI')
| -rw-r--r-- | engine/UI/GridRow.go | 1 | ||||
| -rw-r--r-- | engine/UI/Label.go | 21 |
2 files changed, 17 insertions, 5 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) } |
