Noah Petherbridge
36db160533
* Fix Supervisor event issues wrt. the window manager feature: if a focused window exists and Supervisor is running events for the "other" widgets not in managed windows, and the mouse cursor is over the rectangle of THE focused window, no widget under the cursor receives active (hover, click) events. Prevents being able to click "through" the window and interact with widgets and other windows below. * Adds Close, Maximize and Minimize buttons to windows. Maximize is still buggy and Minimize is implementation-defined behavior with no default event handler configured. * eg/windows has an example of the Window Manager for SDL2 and WebAssembly targets.
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package ui_test
|
|
|
|
import (
|
|
"git.kirsle.net/go/render"
|
|
"git.kirsle.net/go/ui"
|
|
)
|
|
|
|
// Example of using the Supervisor Window Manager.
|
|
func ExampleWindow() {
|
|
mw, err := ui.NewMainWindow("Window Manager Example", 800, 600)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Create a window as normal.
|
|
window := ui.NewWindow("Hello world!")
|
|
window.Configure(ui.Config{
|
|
Width: 320,
|
|
Height: 240,
|
|
})
|
|
|
|
// Configure its title bar colors (optional; these are the defaults)
|
|
window.ActiveTitleBackground = render.Blue
|
|
window.ActiveTitleForeground = render.White
|
|
window.InactiveTitleBackground = render.DarkGrey
|
|
window.InactiveTitleForeground = render.Grey
|
|
|
|
// Configure its window buttons (optional); default has no window buttons.
|
|
// Window buttons are only functional in managed windows.
|
|
window.SetButtons(ui.CloseButton | ui.MaximizeButton | ui.MinimizeButton)
|
|
|
|
// Add some widgets to the window.
|
|
btn := ui.NewButton("My Button", ui.NewLabel(ui.Label{
|
|
Text: "Hello world!",
|
|
}))
|
|
window.Place(btn, ui.Place{
|
|
Center: true,
|
|
Middle: true,
|
|
})
|
|
|
|
// To enable the window manager controls, the key step is to give it
|
|
// the Supervisor so it can be managed:
|
|
window.Compute(mw.Engine)
|
|
window.Supervise(mw.Supervisor())
|
|
|
|
// Each loop you must then:
|
|
// - Call Supervisor.Loop() as normal to handle events.
|
|
// - Call Supervisor.Present() to draw the managed windows.
|
|
// MainLoop() of the MainWindow does this for you.
|
|
mw.MainLoop()
|
|
}
|