diff options
Diffstat (limited to 'engine/UI/Label.go')
| -rw-r--r-- | engine/UI/Label.go | 21 |
1 files changed, 17 insertions, 4 deletions
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) } |
