krampus19/alui/button.go
Sander Schobers 0cd5cb4ad1 Added simple main menu.
Refactored some structs from public to internal.
Separated navigation from game.
Added utility methods for drawing text.
Stackpanel will uses all available width when layouting.
2019-12-24 01:27:05 +01:00

32 lines
677 B
Go

package alui
import (
"opslag.de/schobers/allg5"
"opslag.de/schobers/geom"
)
var _ Control = &Button{}
type Button struct {
ControlBase
Text string
TextAlign allg5.HorizontalAlignment
}
func (b *Button) DesiredSize(ctx *Context) geom.PointF32 {
font := ctx.Fonts.Get(b.Font)
w := font.TextWidth(b.Text)
return geom.PtF32(w+8, font.Height()+8)
}
func (b *Button) Render(ctx *Context, bounds geom.RectangleF32) {
fore := ctx.Palette.Primary
if b.Over {
fore = ctx.Palette.Dark
ctx.Cursor = allg5.MouseCursorLink
}
font := ctx.Fonts.Get(b.Font)
ctx.Fonts.DrawAlignFont(font, bounds.Min.X+4, bounds.Min.Y+4, bounds.Max.X-4, fore, b.TextAlign, b.Text)
}