doodle/ui/window.go
Noah Petherbridge b67c4b67b2 Add Initial "Doodad Palette" UX
* Add a tab bar to the top of the Palette window that has two
  radiobuttons for "Palette" and "Doodads"
* UI: add the concept of a Hidden() widget and the corresponding Hide()
  and Show() methods. Hidden widgets are skipped over when evaluating
  Frame packing, rendering, and event supervision.
* The Palette Window in editor mode now displays one of two tabs:
  * Palette: the old color swatch palette now lives here.
  * Doodads: the new Doodad palette.
* The Doodad Palette shows a grid of buttons (2 per row) showing the
  available Doodad drawings in the user's config folder.
* The Doodad buttons act as radiobuttons for now and have no other
  effect. TODO will be making them react to drag-drop events.
* UI: added a `Children()` method as the inverse of `Parent()` for
  container widgets (like Frame, Window and Button) to expose their
  children. The BaseWidget just returns an empty []Widget.
* Console: added a `repl` command that keeps the dev console open and
  prefixes every command with `$` filled out -- for rapid JavaScript
  console evaluation.
2018-10-08 13:06:42 -07:00

115 lines
2.1 KiB
Go

package ui
import (
"fmt"
"git.kirsle.net/apps/doodle/render"
)
// Window is a frame with a title bar.
type Window struct {
BaseWidget
Title string
Active bool
// Private widgets.
body *Frame
titleBar *Label
content *Frame
}
// NewWindow creates a new window.
func NewWindow(title string) *Window {
w := &Window{
Title: title,
body: NewFrame("body:" + title),
}
w.IDFunc(func() string {
return fmt.Sprintf("Window<%s>",
w.Title,
)
})
w.body.Configure(Config{
Background: render.Grey,
BorderSize: 2,
BorderStyle: BorderRaised,
})
// Title bar widget.
titleBar := NewLabel(Label{
TextVariable: &w.Title,
Font: render.Text{
Color: render.White,
Size: 10,
Stroke: render.DarkBlue,
Padding: 2,
},
})
titleBar.Configure(Config{
Background: render.Blue,
})
w.body.Pack(titleBar, Pack{
Anchor: N,
Fill: true,
})
w.titleBar = titleBar
// Window content frame.
content := NewFrame("content:" + title)
content.Configure(Config{
Background: render.Grey,
})
w.body.Pack(content, Pack{
Anchor: N,
Fill: true,
})
w.content = content
return w
}
// Children returns the window's child widgets.
func (w *Window) Children() []Widget {
return []Widget{
w.body,
}
}
// TitleBar returns the title bar widget.
func (w *Window) TitleBar() *Label {
return w.titleBar
}
// Configure the widget. Color and style changes are passed down to the inner
// content frame of the window.
func (w *Window) Configure(C Config) {
w.BaseWidget.Configure(C)
w.body.Configure(C)
// Don't pass dimensions down any further than the body.
C.Width = 0
C.Height = 0
w.content.Configure(C)
}
// ConfigureTitle configures the title bar widget.
func (w *Window) ConfigureTitle(C Config) {
w.titleBar.Configure(C)
}
// Compute the window.
func (w *Window) Compute(e render.Engine) {
w.body.Compute(e)
}
// Present the window.
func (w *Window) Present(e render.Engine, P render.Point) {
w.body.Present(e, P)
}
// Pack a widget into the window's frame.
func (w *Window) Pack(child Widget, config ...Pack) {
w.content.Pack(child, config...)
}