doodle/ui/label.go
Noah Petherbridge 94c1df050b Add initial User Interface Toolkit
With Labels and Buttons so far.

* Labels are pretty much complete, they wrap a render.Text and have a
  Compute() method that returns their Width and Height when rendered
  onto an SDL Surface.
* Buttons wrap a Label widget and Compute() its size and takes that into
  consideration when rendering itself. Buttons render themselves from
  scratch in a "Windows 95" themed way, with configurable colors, border
  widths and outline.
2018-07-25 09:03:49 -07:00

32 lines
550 B
Go

package ui
import "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 {
return &Label{
Text: t,
}
}
// Compute the size of the label widget.
func (w *Label) Compute(e render.Engine) {
rect, err := e.ComputeTextRect(w.Text)
w.Resize(rect)
_ = rect
_ = err
}
// Present the label widget.
func (w *Label) Present(e render.Engine) {
e.DrawText(w.Text, w.Point())
}