2018-08-11 00:19:47 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
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
|
|
|
|
|
|
|
// Don't pass dimensions down any further than the body.
|
|
|
|
C.Width = 0
|
|
|
|
C.Height = 0
|
|
|
|
w.content.Configure(C)
|
2018-08-11 00:19:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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...)
|
|
|
|
}
|