krampus19/alui/button.go

32 lines
677 B
Go
Raw Normal View History

2019-12-19 05:59:45 +00:00
package alui
import (
"opslag.de/schobers/allg5"
"opslag.de/schobers/geom"
)
var _ Control = &Button{}
type Button struct {
ControlBase
Text string
TextAlign allg5.HorizontalAlignment
2019-12-19 05:59:45 +00:00
}
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)
2019-12-19 05:59:45 +00:00
}
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)
2019-12-19 05:59:45 +00:00
}