tins2020/largedialog.go

142 lines
3.3 KiB
Go
Raw Normal View History

package tins2020
2020-05-17 08:56:56 +00:00
import (
"opslag.de/schobers/zntg"
"opslag.de/schobers/zntg/ui"
)
// type DialogBase struct {
// }
// type Dialog interface {
// CloseDialog()
// OnShow() zntg.EventHandler
// ShowDialog(ui.Context, zntg.EventFn)
// }
// func (d *DialogBase) CloseDialog() {
// close := d.close
// if close != nil {
// close()
// }
// }
// func (d *DialogBase) Init(ctx ui.Context) error {
// d.AddChild(&d.content)
// return d.Container.Init(ctx)
// }
// func (d *DialogBase) OnShow() zntg.EventHandler {
// if d.onShow == nil {
// d.onShow = NewEvents()
// }
// return d.onShow
// }
// func (d *DialogBase) SetContent(control ui.Control) {
// d.content.Proxied = control
// }
// func (d *DialogBase) ShowDialog(ctx ui.Context, close zntg.EventFn) {
// d.close = close
// if d.onShow != nil {
// d.onShow.Notify(ctx)
// }
// }
2020-05-17 08:56:56 +00:00
type LargeDialog struct {
ui.StackPanel
2020-05-17 08:56:56 +00:00
titleBar *LargeDialogTitleBar
content ui.OverlayProxy
2020-05-17 08:56:56 +00:00
closeRequested ui.Events
2020-05-17 08:56:56 +00:00
onShow zntg.Events
close zntg.EventFn
}
2020-05-17 08:56:56 +00:00
func NewLargeDialog(title string, content ui.Control) *LargeDialog {
dialog := &LargeDialog{}
2020-05-11 12:41:42 +00:00
2020-05-17 08:56:56 +00:00
dialog.titleBar = NewLargeDialogTitleBar(title, func(ctx ui.Context, state interface{}) {
dialog.closeRequested.Notify(ctx, state)
})
dialog.content.Content = content
dialog.Children = []ui.Control{dialog.titleBar, &dialog.content}
2020-05-11 12:41:42 +00:00
2020-05-17 08:56:56 +00:00
return dialog
}
2020-05-17 08:56:56 +00:00
func (d *LargeDialog) Hidden() { d.content.Hidden() }
2020-05-17 08:56:56 +00:00
func (d *LargeDialog) Shown() { d.content.Shown() }
2020-05-17 08:56:56 +00:00
type LargeDialogTitleBar struct {
ui.ContainerBase
2020-05-17 08:56:56 +00:00
title ui.Label
close IconButton
}
2020-05-17 08:56:56 +00:00
func NewLargeDialogTitleBar(title string, closeRequested ui.EventFn) *LargeDialogTitleBar {
titleBar := &LargeDialogTitleBar{}
titleBar.Children = []ui.Control{&titleBar.title, &titleBar.close}
titleBar.close.ButtonClicked().AddHandler(func(ctx ui.Context, args ui.ControlClickedArgs) {
closeRequested(ctx, args)
})
return titleBar
}
2020-05-11 12:41:42 +00:00
2020-05-17 08:56:56 +00:00
// func (d *LargeDialog) Arrange(ctx ui.Context, bounds Rectangle) {
// const titleHeight = 64
// d.ControlBase.Arrange(ctx, bounds)
// d.title.Arrange(ctx, Rect(bounds.X, bounds.Y, bounds.W, titleHeight))
// d.close.Arrange(ctx, Rect(bounds.W-64, 0, 64, 64))
// d.content.Arrange(ctx, Rect(bounds.X+titleHeight, 96, bounds.W-2*titleHeight, bounds.H-titleHeight))
// }
// func (d *LargeDialog) Init(ctx ui.Context) error {
// d.title.Text = "Botanim"
// d.title.FontName = "title"
// d.title.Alignment = TextAlignmentCenter
// d.close = IconButton{
// Icon: "control-cancel",
// IconHover: HoverEffectColor,
// IconWidth: 32,
// }
// d.close.OnLeftMouseButtonClick = EmptyEvent(d.CloseDialog)
// d.AddChild(&d.title)
// d.AddChild(&d.close)
// return d.DialogBase.Init(ctx)
// }
// func (d *LargeDialog) Handle(ctx ui.Context, event sdl.Event) bool {
// if d.DialogBase.Handle(ctx, event) {
// return true
// }
// switch e := event.(type) {
// case *sdl.KeyboardEvent:
// if e.Type == sdl.KEYDOWN {
// switch e.Keysym.Sym {
// case sdl.K_ESCAPE:
// d.CloseDialog()
// return true
// case sdl.K_RETURN:
// d.CloseDialog()
// return true
// }
// }
// }
// return false
// }
// func (d *LargeDialog) Render(ctx ui.Context) {
// SetDrawColor(ctx.Renderer, MustHexColor("#356DAD"))
// ctx.Renderer.FillRect(d.Bounds.SDLPtr())
// d.DialogBase.Render(ctx)
// }