NewDialog now returns a window.

This commit is contained in:
Sasha Koshka 2023-01-12 14:12:24 -05:00
parent 26c1dc062b
commit 84ea6178b0

View File

@ -4,6 +4,7 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/elements/basic" import "git.tebibyte.media/sashakoshka/tomo/elements/basic"
import "git.tebibyte.media/sashakoshka/tomo/elements/layouts" import "git.tebibyte.media/sashakoshka/tomo/elements/layouts"
// DialogKind defines the semantic role of a dialog window.
type DialogKind int type DialogKind int
const ( const (
@ -13,13 +14,25 @@ const (
DialogKindError DialogKindError
) )
// Button represents a dialog response button.
type Button struct { type Button struct {
// Name contains the text to display on the button.
Name string Name string
// OnPress specifies a callback to run when the button is pressed. If
// this callback is nil, the button will appear disabled.
OnPress func () OnPress func ()
} }
func NewDialog (kind DialogKind, title, message string, buttons ...Button) { // NewDialog creates a new dialog window and returns it.
window, _ := tomo.NewWindow(2, 2) func NewDialog (
kind DialogKind,
title, message string,
buttons ...Button,
) (
window tomo.Window,
) {
window, _ = tomo.NewWindow(2, 2)
window.SetTitle(title) window.SetTitle(title)
container := basic.NewContainer(layouts.Dialog { true, true }) container := basic.NewContainer(layouts.Dialog { true, true })
@ -46,4 +59,5 @@ func NewDialog (kind DialogKind, title, message string, buttons ...Button) {
} }
window.Show() window.Show()
return
} }