Noah Petherbridge
cbef5a46cb
* Frame.Pack() now supports Fill and Expand and works like Tk. * The GUITest Scene now draws a large window with two fixed side panels, an expanding body panel, and a fixed footer with buttons. The panels are filled with other buttons and widgets showing off the Frame packing.
60 lines
978 B
Go
60 lines
978 B
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.kirsle.net/apps/doodle/render"
|
|
)
|
|
|
|
// Label is a simple text label widget.
|
|
type Label struct {
|
|
BaseWidget
|
|
width int32
|
|
height int32
|
|
Text render.Text
|
|
}
|
|
|
|
// NewLabel creates a new label.
|
|
func NewLabel(t render.Text) *Label {
|
|
w := &Label{
|
|
Text: t,
|
|
}
|
|
w.Configure(Config{
|
|
Padding: 4,
|
|
})
|
|
w.IDFunc(func() string {
|
|
return fmt.Sprintf("Label<%s>", w.Text.Text)
|
|
})
|
|
return w
|
|
}
|
|
|
|
// Compute the size of the label widget.
|
|
func (w *Label) Compute(e render.Engine) {
|
|
rect, _ := e.ComputeTextRect(w.Text)
|
|
|
|
if !w.FixedSize() {
|
|
w.resizeAuto(render.Rect{
|
|
W: rect.W + w.Padding(),
|
|
H: rect.H + w.Padding(),
|
|
})
|
|
}
|
|
|
|
w.MoveTo(render.Point{
|
|
X: rect.X + w.BoxThickness(1),
|
|
Y: rect.Y + w.BoxThickness(1),
|
|
})
|
|
}
|
|
|
|
// Present the label widget.
|
|
func (w *Label) Present(e render.Engine) {
|
|
var (
|
|
P = w.Point()
|
|
border = w.BoxThickness(1)
|
|
)
|
|
w.DrawBox(e)
|
|
e.DrawText(w.Text, render.Point{
|
|
X: P.X + border,
|
|
Y: P.Y + border,
|
|
})
|
|
}
|