From 8c48c949e9bbd8c1666533c09e75a83a899c56f5 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 16 May 2020 10:57:14 +0200 Subject: [PATCH] Renamed Overlay callbacks & extended interface of Overlay (must be a Control as well). --- ui/overlay.go | 6 ++++-- ui/overlaybase.go | 9 +++++++++ ui/overlayproxy.go | 8 ++++---- ui/overlays.go | 16 ++++++++-------- ui/tooltip.go | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 ui/overlaybase.go diff --git a/ui/overlay.go b/ui/overlay.go index a3b73de..28921ef 100644 --- a/ui/overlay.go +++ b/ui/overlay.go @@ -1,6 +1,8 @@ package ui type Overlay interface { - OverlayShown() - OverlayHidden() + Control + + Shown() + Hidden() } diff --git a/ui/overlaybase.go b/ui/overlaybase.go new file mode 100644 index 0000000..ee93efd --- /dev/null +++ b/ui/overlaybase.go @@ -0,0 +1,9 @@ +package ui + +type OverlayBase struct { + ControlBase +} + +func (o *OverlayBase) Hidden() {} + +func (o *OverlayBase) Shown() {} diff --git a/ui/overlayproxy.go b/ui/overlayproxy.go index 2d6231f..22826f2 100644 --- a/ui/overlayproxy.go +++ b/ui/overlayproxy.go @@ -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() } } diff --git a/ui/overlays.go b/ui/overlays.go index 68a739e..fffa909 100644 --- a/ui/overlays.go +++ b/ui/overlays.go @@ -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 } diff --git a/ui/tooltip.go b/ui/tooltip.go index cb09023..88b1ff9 100644 --- a/ui/tooltip.go +++ b/ui/tooltip.go @@ -14,7 +14,7 @@ const tooltipMouseDistance = 12 const uiDefaultTooltipOverlay = "ui-default-tooltip" type Tooltip struct { - ControlBase + OverlayBase Text string }