142 lines
3.3 KiB
Go
142 lines
3.3 KiB
Go
package tins2020
|
|
|
|
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)
|
|
// }
|
|
// }
|
|
|
|
type LargeDialog struct {
|
|
ui.StackPanel
|
|
|
|
titleBar *LargeDialogTitleBar
|
|
content ui.OverlayProxy
|
|
|
|
closeRequested ui.Events
|
|
|
|
onShow zntg.Events
|
|
close zntg.EventFn
|
|
}
|
|
|
|
func NewLargeDialog(title string, content ui.Control) *LargeDialog {
|
|
dialog := &LargeDialog{}
|
|
|
|
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}
|
|
|
|
return dialog
|
|
}
|
|
|
|
func (d *LargeDialog) Hidden() { d.content.Hidden() }
|
|
|
|
func (d *LargeDialog) Shown() { d.content.Shown() }
|
|
|
|
type LargeDialogTitleBar struct {
|
|
ui.ContainerBase
|
|
|
|
title ui.Label
|
|
close IconButton
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// 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)
|
|
// }
|