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
|
|
|
|
|
2019-12-24 00:27:05 +00:00
|
|
|
Text string
|
|
|
|
TextAlign allg5.HorizontalAlignment
|
2019-12-19 05:59:45 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 15:03:57 +00:00
|
|
|
func NewButton(text string, onClick func()) *Button {
|
|
|
|
b := &Button{Text: text}
|
|
|
|
b.OnClick = onClick
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2019-12-19 05:59:45 +00:00
|
|
|
func (b *Button) DesiredSize(ctx *Context) geom.PointF32 {
|
|
|
|
font := ctx.Fonts.Get(b.Font)
|
2019-12-24 00:27:05 +00:00
|
|
|
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
|
|
|
|
}
|
2019-12-24 00:27:05 +00:00
|
|
|
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
|
|
|
}
|