Compare commits

...

1 Commits

Author SHA1 Message Date
ef52e22c1e WIP Modals 2020-10-28 18:53:57 -07:00
2 changed files with 54 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import (
"git.kirsle.net/apps/doodle/pkg/branding" "git.kirsle.net/apps/doodle/pkg/branding"
"git.kirsle.net/apps/doodle/pkg/level" "git.kirsle.net/apps/doodle/pkg/level"
"git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/log"
"git.kirsle.net/apps/doodle/pkg/modal"
"git.kirsle.net/apps/doodle/pkg/native" "git.kirsle.net/apps/doodle/pkg/native"
"git.kirsle.net/apps/doodle/pkg/scripting" "git.kirsle.net/apps/doodle/pkg/scripting"
"git.kirsle.net/apps/doodle/pkg/uix" "git.kirsle.net/apps/doodle/pkg/uix"
@ -112,10 +113,15 @@ func (s *MainScene) Setup(d *Doodle) error {
Name: "Edit a Level", Name: "Edit a Level",
Func: d.GotoLoadMenu, Func: d.GotoLoadMenu,
}, },
// { {
// Name: "Settings", Name: "Settings",
// Func: d.GotoSettingsMenu, Func: func() {
// }, log.Error("TEST Alert()")
modal.Alert("Hello world!").then(func() {
d.Flash("Alert has been clicked thru!")
})
},
},
} }
for _, button := range buttons { for _, button := range buttons {
button := button button := button

44
pkg/modal/modal.go Normal file
View File

@ -0,0 +1,44 @@
// Package modal provides global pop-up confirmation modals (Alert, Confirm).
package modal
import (
"git.kirsle.net/go/render"
"git.kirsle.net/go/ui"
)
// Global state variables.
var (
// Darkening screen that covers the whole window.
screen = *ui.Frame
modalActive bool
)
func init() {
screen = ui.NewFrame("screen")
screen.SetBackground(render.RGBA(0, 0, 0, 180))
}
type Modal struct {
type string
title string
message string
}
func (m *Modal) Then(fn func) {
}
// Present the modal view.
func Present(e render.Engine) {
}
// Alert the user to an important message. The callback function is invoked
// after the user confirms the message.
func Alert(message string, v ...interface{}) Modal {
return Modal{
type: "alert",
title: "Alert!",
message: fmt.Sprintf(message, v...),
}
}