Noah Petherbridge
5956863996
* 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.
76 lines
1.4 KiB
Go
76 lines
1.4 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.kirsle.net/apps/doodle/render"
|
|
)
|
|
|
|
// Frame is a widget that contains other widgets.
|
|
type Frame struct {
|
|
Name string
|
|
BaseWidget
|
|
packs map[Anchor][]packedWidget
|
|
widgets []Widget
|
|
}
|
|
|
|
// NewFrame creates a new Frame.
|
|
func NewFrame(name string) *Frame {
|
|
w := &Frame{
|
|
Name: name,
|
|
packs: map[Anchor][]packedWidget{},
|
|
widgets: []Widget{},
|
|
}
|
|
w.IDFunc(func() string {
|
|
return fmt.Sprintf("Frame<%s>",
|
|
name,
|
|
)
|
|
})
|
|
return w
|
|
}
|
|
|
|
// 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{}
|
|
}
|
|
if w.widgets == nil {
|
|
w.widgets = []Widget{}
|
|
}
|
|
}
|
|
|
|
// Compute the size of the Frame.
|
|
func (w *Frame) Compute(e render.Engine) {
|
|
w.computePacked(e)
|
|
}
|
|
|
|
// Present the Frame.
|
|
func (w *Frame) Present(e render.Engine, P render.Point) {
|
|
var (
|
|
S = w.Size()
|
|
)
|
|
|
|
// Draw the widget's border and everything.
|
|
w.DrawBox(e, P)
|
|
|
|
// 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 {
|
|
// child.Compute(e)
|
|
p := child.Point()
|
|
moveTo := render.NewPoint(
|
|
P.X+p.X+w.BoxThickness(1),
|
|
P.Y+p.Y+w.BoxThickness(1),
|
|
)
|
|
child.MoveTo(moveTo)
|
|
child.Present(e, moveTo)
|
|
}
|
|
}
|