diff --git a/ui/overlay.go b/ui/overlay.go new file mode 100644 index 0000000..a3b73de --- /dev/null +++ b/ui/overlay.go @@ -0,0 +1,6 @@ +package ui + +type Overlay interface { + OverlayShown() + OverlayHidden() +} diff --git a/ui/overlayproxy.go b/ui/overlayproxy.go new file mode 100644 index 0000000..2d6231f --- /dev/null +++ b/ui/overlayproxy.go @@ -0,0 +1,19 @@ +package ui + +type OverlayProxy struct { + Proxy +} + +func (p *OverlayProxy) OverlayShown() { + overlay, ok := p.Content.(Overlay) + if ok { + overlay.OverlayShown() + } +} + +func (p *OverlayProxy) OverlayHidden() { + overlay, ok := p.Content.(Overlay) + if ok { + overlay.OverlayHidden() + } +} diff --git a/ui/overlays.go b/ui/overlays.go index 49a9b0e..68a739e 100644 --- a/ui/overlays.go +++ b/ui/overlays.go @@ -1,15 +1,27 @@ package ui -import "opslag.de/schobers/geom" +import ( + "opslag.de/schobers/geom" + "opslag.de/schobers/zntg" +) var _ Control = &Overlays{} +type OverlayVisibilityChangedArgs struct { + Name string + Visible bool +} + type Overlays struct { Proxy overlays map[string]Control order []string visible map[string]bool + + overlayHidden zntg.Events + overlayShown zntg.Events + visibilityChanged zntg.Events } func NewOverlays(over Control) *Overlays { @@ -21,6 +33,27 @@ func NewOverlays(over Control) *Overlays { } } +func (o *Overlays) setVisibility(name string, visible bool) { + if o.visible[name] == visible { + return + } + o.visible[name] = visible + overlay, ok := o.overlays[name].(Overlay) + if ok { + if visible { + overlay.OverlayShown() + } else { + overlay.OverlayHidden() + } + } + o.visibilityChanged.Notify(OverlayVisibilityChangedArgs{Name: name, Visible: visible}) + if visible { + o.overlayShown.Notify(name) + } else { + o.overlayHidden.Notify(name) + } +} + func (o *Overlays) AddOnTop(name string, control Control, visible bool) { o.order = append(o.order, name) o.overlays[name] = control