Added callbacks & events when visibility of an overlay changes.
Added proxy that proxies overlay callbacks as well (on top of control callbacks).
This commit is contained in:
parent
7f3d836254
commit
9af85d79a6
6
ui/overlay.go
Normal file
6
ui/overlay.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
type Overlay interface {
|
||||||
|
OverlayShown()
|
||||||
|
OverlayHidden()
|
||||||
|
}
|
19
ui/overlayproxy.go
Normal file
19
ui/overlayproxy.go
Normal file
@ -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()
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,27 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import "opslag.de/schobers/geom"
|
import (
|
||||||
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg"
|
||||||
|
)
|
||||||
|
|
||||||
var _ Control = &Overlays{}
|
var _ Control = &Overlays{}
|
||||||
|
|
||||||
|
type OverlayVisibilityChangedArgs struct {
|
||||||
|
Name string
|
||||||
|
Visible bool
|
||||||
|
}
|
||||||
|
|
||||||
type Overlays struct {
|
type Overlays struct {
|
||||||
Proxy
|
Proxy
|
||||||
|
|
||||||
overlays map[string]Control
|
overlays map[string]Control
|
||||||
order []string
|
order []string
|
||||||
visible map[string]bool
|
visible map[string]bool
|
||||||
|
|
||||||
|
overlayHidden zntg.Events
|
||||||
|
overlayShown zntg.Events
|
||||||
|
visibilityChanged zntg.Events
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOverlays(over Control) *Overlays {
|
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) {
|
func (o *Overlays) AddOnTop(name string, control Control, visible bool) {
|
||||||
o.order = append(o.order, name)
|
o.order = append(o.order, name)
|
||||||
o.overlays[name] = control
|
o.overlays[name] = control
|
||||||
|
Loading…
Reference in New Issue
Block a user