2018-08-01 00:18:13 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-12-30 22:22:50 +00:00
|
|
|
"git.kirsle.net/apps/doodle/lib/render"
|
2018-08-01 00:18:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Frame is a widget that contains other widgets.
|
|
|
|
type Frame struct {
|
2018-08-02 01:52:52 +00:00
|
|
|
Name string
|
2018-08-01 00:18:13 +00:00
|
|
|
BaseWidget
|
|
|
|
packs map[Anchor][]packedWidget
|
|
|
|
widgets []Widget
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFrame creates a new Frame.
|
2018-08-02 01:52:52 +00:00
|
|
|
func NewFrame(name string) *Frame {
|
|
|
|
w := &Frame{
|
|
|
|
Name: name,
|
2018-08-01 00:18:13 +00:00
|
|
|
packs: map[Anchor][]packedWidget{},
|
|
|
|
widgets: []Widget{},
|
|
|
|
}
|
2018-08-02 01:52:52 +00:00
|
|
|
w.IDFunc(func() string {
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
return fmt.Sprintf("Frame<%s>",
|
2018-08-02 01:52:52 +00:00
|
|
|
name,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
return w
|
2018-08-01 00:18:13 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 02:52:09 +00:00
|
|
|
// Setup ensures all the Frame's data is initialized and not null.
|
|
|
|
func (w *Frame) Setup() {
|
|
|
|
if w.packs == nil {
|
|
|
|
w.packs = map[Anchor][]packedWidget{}
|
2018-08-01 00:18:13 +00:00
|
|
|
}
|
2018-08-02 02:52:09 +00:00
|
|
|
if w.widgets == nil {
|
|
|
|
w.widgets = []Widget{}
|
2018-08-01 00:18:13 +00:00
|
|
|
}
|
2018-08-02 02:52:09 +00:00
|
|
|
}
|
2018-08-01 00:18:13 +00:00
|
|
|
|
2018-10-08 20:06:42 +00:00
|
|
|
// Children returns all of the child widgets.
|
|
|
|
func (w *Frame) Children() []Widget {
|
|
|
|
return w.widgets
|
|
|
|
}
|
|
|
|
|
2018-08-02 02:52:09 +00:00
|
|
|
// Compute the size of the Frame.
|
|
|
|
func (w *Frame) Compute(e render.Engine) {
|
|
|
|
w.computePacked(e)
|
2018-08-01 00:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Present the Frame.
|
2018-08-05 19:54:57 +00:00
|
|
|
func (w *Frame) Present(e render.Engine, P render.Point) {
|
2018-10-08 20:06:42 +00:00
|
|
|
if w.Hidden() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-01 00:18:13 +00:00
|
|
|
var (
|
|
|
|
S = w.Size()
|
|
|
|
)
|
|
|
|
|
|
|
|
// Draw the widget's border and everything.
|
2018-08-05 19:54:57 +00:00
|
|
|
w.DrawBox(e, P)
|
2018-08-01 00:18:13 +00:00
|
|
|
|
|
|
|
// Draw the background color.
|
|
|
|
e.DrawBox(w.Background(), render.Rect{
|
|
|
|
X: P.X + w.BoxThickness(1),
|
|
|
|
Y: P.Y + w.BoxThickness(1),
|
|
|
|
W: S.W - w.BoxThickness(2),
|
|
|
|
H: S.H - w.BoxThickness(2),
|
|
|
|
})
|
|
|
|
|
|
|
|
// Draw the widgets.
|
|
|
|
for _, child := range w.widgets {
|
2018-08-05 19:54:57 +00:00
|
|
|
// child.Compute(e)
|
2018-08-01 00:18:13 +00:00
|
|
|
p := child.Point()
|
2018-08-05 19:54:57 +00:00
|
|
|
moveTo := render.NewPoint(
|
2018-08-01 00:18:13 +00:00
|
|
|
P.X+p.X+w.BoxThickness(1),
|
|
|
|
P.Y+p.Y+w.BoxThickness(1),
|
2018-08-05 19:54:57 +00:00
|
|
|
)
|
2018-10-08 17:38:49 +00:00
|
|
|
// if child.ID() == "Canvas" {
|
|
|
|
// log.Debug("Frame X=%d Child X=%d Box=%d Point=%s", P.X, p.X, w.BoxThickness(1), p)
|
|
|
|
// log.Debug("Frame Y=%d Child Y=%d Box=%d MoveTo=%s", P.Y, p.Y, w.BoxThickness(1), moveTo)
|
|
|
|
// }
|
|
|
|
// child.MoveTo(moveTo) // TODO: if uncommented the child will creep down the parent each tick
|
|
|
|
// if child.ID() == "Canvas" {
|
|
|
|
// log.Debug("New Point: %s", child.Point())
|
|
|
|
// }
|
2018-08-05 19:54:57 +00:00
|
|
|
child.Present(e, moveTo)
|
2018-08-01 00:18:13 +00:00
|
|
|
}
|
|
|
|
}
|