101 lines
2.6 KiB
Go
101 lines
2.6 KiB
Go
package tins2020
|
|
|
|
import (
|
|
"image/color"
|
|
|
|
"opslag.de/schobers/geom"
|
|
"opslag.de/schobers/zntg"
|
|
"opslag.de/schobers/zntg/ui"
|
|
)
|
|
|
|
const titleBarHeight = 64
|
|
|
|
type LargeDialog struct {
|
|
ui.StackPanel
|
|
|
|
titleBar *LargeDialogTitleBar
|
|
content ui.Proxy
|
|
|
|
closeRequested ui.Events
|
|
}
|
|
|
|
func NewLargeDialog(title string, content ui.Control) *LargeDialog {
|
|
dialog := &LargeDialog{}
|
|
|
|
dialog.Orientation = ui.OrientationVertical
|
|
dialog.titleBar = NewLargeDialogTitleBar(title, func(ctx ui.Context, state interface{}) {
|
|
dialog.closeRequested.Notify(ctx, state)
|
|
})
|
|
dialog.content.Content = ui.Margins(content, titleBarHeight, 20, titleBarHeight, 0)
|
|
dialog.Children = []ui.Control{dialog.titleBar, &dialog.content}
|
|
|
|
return dialog
|
|
}
|
|
|
|
func (d *LargeDialog) CloseRequested() ui.EventHandler { return &d.closeRequested }
|
|
|
|
func (d *LargeDialog) Handle(ctx ui.Context, e ui.Event) bool {
|
|
if d.StackPanel.Handle(ctx, e) {
|
|
return true
|
|
}
|
|
|
|
switch e := e.(type) {
|
|
case *ui.KeyDownEvent:
|
|
switch e.Key {
|
|
case ui.KeyEscape:
|
|
d.closeRequested.Notify(ctx, nil)
|
|
return true
|
|
case ui.KeyEnter:
|
|
d.closeRequested.Notify(ctx, nil)
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (d *LargeDialog) Hidden() { d.content.Hidden() }
|
|
|
|
func (d *LargeDialog) Render(ctx ui.Context) {
|
|
ctx.Renderer().Clear(zntg.MustHexColor("#356DAD"))
|
|
d.StackPanel.Render(ctx)
|
|
}
|
|
|
|
func (d *LargeDialog) Shown() { d.content.Shown() }
|
|
|
|
type LargeDialogTitleBar struct {
|
|
ui.ContainerBase
|
|
|
|
title ui.Label
|
|
close ui.Button
|
|
}
|
|
|
|
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)
|
|
})
|
|
titleBar.title.Font.Color = color.White
|
|
titleBar.title.Font.Name = "title"
|
|
titleBar.title.Text = title
|
|
titleBar.title.TextAlignment = ui.AlignCenter
|
|
|
|
titleBar.close.Icon = "control-cancel"
|
|
titleBar.close.IconHeight = 32
|
|
titleBar.close.Type = ui.ButtonTypeIcon
|
|
titleBar.close.HoverColor = zntg.MustHexColor(`#ABCAED`)
|
|
|
|
return titleBar
|
|
}
|
|
|
|
func (b *LargeDialogTitleBar) Arrange(ctx ui.Context, bounds geom.RectangleF32, offset geom.PointF32, parent ui.Control) {
|
|
b.ControlBase.Arrange(ctx, bounds, offset, parent)
|
|
b.title.Arrange(ctx, bounds, offset, parent)
|
|
height := bounds.Dy()
|
|
b.close.Arrange(ctx, geom.RectRelF32(bounds.Max.X-height, bounds.Min.Y, height, height), offset, parent)
|
|
}
|
|
|
|
func (b *LargeDialogTitleBar) DesiredSize(ctx ui.Context, size geom.PointF32) geom.PointF32 {
|
|
return geom.PtF32(size.X, titleBarHeight)
|
|
}
|