Renamed Overlay callbacks & extended interface of Overlay (must be a Control as well).

This commit is contained in:
Sander Schobers 2020-05-16 10:57:14 +02:00
parent 9af85d79a6
commit 8c48c949e9
5 changed files with 26 additions and 15 deletions

View File

@ -1,6 +1,8 @@
package ui
type Overlay interface {
OverlayShown()
OverlayHidden()
Control
Shown()
Hidden()
}

9
ui/overlaybase.go Normal file
View File

@ -0,0 +1,9 @@
package ui
type OverlayBase struct {
ControlBase
}
func (o *OverlayBase) Hidden() {}
func (o *OverlayBase) Shown() {}

View File

@ -4,16 +4,16 @@ type OverlayProxy struct {
Proxy
}
func (p *OverlayProxy) OverlayShown() {
func (p *OverlayProxy) Shown() {
overlay, ok := p.Content.(Overlay)
if ok {
overlay.OverlayShown()
overlay.Shown()
}
}
func (p *OverlayProxy) OverlayHidden() {
func (p *OverlayProxy) Hidden() {
overlay, ok := p.Content.(Overlay)
if ok {
overlay.OverlayHidden()
overlay.Hidden()
}
}

View File

@ -15,7 +15,7 @@ type OverlayVisibilityChangedArgs struct {
type Overlays struct {
Proxy
overlays map[string]Control
overlays map[string]Overlay
order []string
visible map[string]bool
@ -28,7 +28,7 @@ func NewOverlays(over Control) *Overlays {
return &Overlays{
Proxy: Proxy{Content: over},
overlays: map[string]Control{},
overlays: map[string]Overlay{},
visible: map[string]bool{},
}
}
@ -41,9 +41,9 @@ func (o *Overlays) setVisibility(name string, visible bool) {
overlay, ok := o.overlays[name].(Overlay)
if ok {
if visible {
overlay.OverlayShown()
overlay.Shown()
} else {
overlay.OverlayHidden()
overlay.Hidden()
}
}
o.visibilityChanged.Notify(OverlayVisibilityChangedArgs{Name: name, Visible: visible})
@ -54,15 +54,15 @@ func (o *Overlays) setVisibility(name string, visible bool) {
}
}
func (o *Overlays) AddOnTop(name string, control Control, visible bool) {
func (o *Overlays) AddOnTop(name string, overlay Overlay, visible bool) {
o.order = append(o.order, name)
o.overlays[name] = control
o.overlays[name] = overlay
o.visible[name] = visible
}
func (o *Overlays) AddOnBottom(name string, control Control, visible bool) {
func (o *Overlays) AddOnBottom(name string, overlay Overlay, visible bool) {
o.order = append([]string{name}, o.order...)
o.overlays[name] = control
o.overlays[name] = overlay
o.visible[name] = visible
}

View File

@ -14,7 +14,7 @@ const tooltipMouseDistance = 12
const uiDefaultTooltipOverlay = "ui-default-tooltip"
type Tooltip struct {
ControlBase
OverlayBase
Text string
}