tins2020/largedialog.go

106 lines
2.9 KiB
Go
Raw Normal View History

package tins2020
2020-05-17 08:56:56 +00:00
import (
"image/color"
"opslag.de/schobers/geom"
2020-05-17 08:56:56 +00:00
"opslag.de/schobers/zntg"
"opslag.de/schobers/zntg/ui"
)
const titleBarHeight = 64
2020-05-17 08:56:56 +00:00
type LargeDialog struct {
ui.StackPanel
2020-05-17 08:56:56 +00:00
titleBar *LargeDialogTitleBar
2020-05-17 18:24:44 +00:00
content ui.Proxy
2020-05-17 08:56:56 +00:00
closeRequested ui.Events
}
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
dialog.Orientation = ui.OrientationVertical
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 = ui.Margins(content, titleBarHeight, 20, titleBarHeight, 0)
2020-05-17 08:56:56 +00:00
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
}
func (d *LargeDialog) CloseRequested() ui.EventHandler { return &d.closeRequested }
// func (d *LargeDialog) Arrange(ctx ui.Context, bounds geom.RectangleF32, offset geom.PointF32, parent ui.Control) {
// d.titleBar.Arrange(ctx, bounds.Min.RectRel2D(bounds.Dx(), titleHeight), offset, d)
// d.content.Arrange(ctx, geom.RectRelF32(bounds.Min.X+titleHeight, bounds.Min.Y, bounds.Dx(), bounds.Dy()-titleHeight), offset, d)
// }
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
}
2020-05-17 08:56:56 +00:00
func (d *LargeDialog) Hidden() { d.content.Hidden() }
func (d *LargeDialog) Render(ctx ui.Context) {
ctx.Renderer().Clear(zntg.MustHexColor("#356DAD"))
d.StackPanel.Render(ctx)
}
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)
})
titleBar.title.Font.Color = color.White
titleBar.title.Font.Name = "title"
titleBar.title.Text = title
titleBar.title.TextAlignment = ui.AlignCenter
2020-05-11 12:41:42 +00:00
titleBar.close.Icon = "control-cancel"
titleBar.close.IconHeight = 32
titleBar.close.Type = ui.ButtonTypeIcon
2020-05-17 08:56:56 +00:00
return titleBar
}
2020-05-17 08:56:56 +00:00
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)
b.close.HoverColor = ctx.Style().Palette.PrimaryDark
}
2020-05-17 08:56:56 +00:00
func (b *LargeDialogTitleBar) DesiredSize(ctx ui.Context, size geom.PointF32) geom.PointF32 {
return geom.PtF32(size.X, titleBarHeight)
}