aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/tunnelsview.go
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-04-04 10:16:23 +0200
committerAlexander Neumann <alexander.neumann@picos-software.com>2019-04-23 11:04:59 +0200
commitabe6eb03d817b6d88ef4acc872ba794bc3d44191 (patch)
tree3272f76a287a1fb225e868cbdb9638928553b3b0 /ui/tunnelsview.go
parentui: implement a reusable helper for status image painting (diff)
downloadwireguard-windows-abe6eb03d817b6d88ef4acc872ba794bc3d44191.tar.xz
wireguard-windows-abe6eb03d817b6d88ef4acc872ba794bc3d44191.zip
ui: refactor TunnelsView to use the new status image painter
Signed-off-by: Alexander Neumann <alexander.neumann@picos-software.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--ui/tunnelsview.go47
1 files changed, 13 insertions, 34 deletions
diff --git a/ui/tunnelsview.go b/ui/tunnelsview.go
index 6f1deed0..08bc1f21 100644
--- a/ui/tunnelsview.go
+++ b/ui/tunnelsview.go
@@ -58,17 +58,18 @@ type TunnelsView struct {
*walk.TableView
model *TunnelModel
- stoppedBrush *walk.SolidColorBrush
- startingBrush *walk.SolidColorBrush
- startedBrush *walk.SolidColorBrush
- statusPen *walk.CosmeticPen
+ imageProvider *TunnelStatusImageProvider
}
func NewTunnelsView(parent walk.Container) (*TunnelsView, error) {
+ var disposables walk.Disposables
+ defer disposables.Treat()
+
tv, err := walk.NewTableView(parent)
if err != nil {
return nil, err
}
+ disposables.Add(tv)
model := &TunnelModel{}
@@ -82,20 +83,15 @@ func NewTunnelsView(parent walk.Container) (*TunnelsView, error) {
model: model,
}
- tunnelsView.stoppedBrush, _ = walk.NewSolidColorBrush(walk.RGB(239, 239, 239))
- tunnelsView.AddDisposable(tunnelsView.stoppedBrush)
-
- tunnelsView.startingBrush, _ = walk.NewSolidColorBrush(walk.RGB(255, 211, 31))
- tunnelsView.AddDisposable(tunnelsView.startingBrush)
-
- tunnelsView.startedBrush, _ = walk.NewSolidColorBrush(walk.RGB(0, 255, 0))
- tunnelsView.AddDisposable(tunnelsView.startedBrush)
-
- tunnelsView.statusPen, _ = walk.NewCosmeticPen(walk.PenSolid, walk.RGB(191, 191, 191))
- tunnelsView.AddDisposable(tunnelsView.statusPen)
+ if tunnelsView.imageProvider, err = NewTunnelStatusImageProvider(); err != nil {
+ return nil, err
+ }
+ tunnelsView.AddDisposable(tunnelsView.imageProvider)
tv.SetCellStyler(tunnelsView)
+ disposables.Spare()
+
return tunnelsView, nil
}
@@ -105,20 +101,7 @@ func (tv *TunnelsView) StyleCell(style *walk.CellStyle) {
return
}
- tunnel := tv.model.tunnels[style.Row()]
-
- var brush *walk.SolidColorBrush
- state, _ := tunnel.State()
- switch state {
- case service.TunnelStarted:
- brush = tv.startedBrush
-
- case service.TunnelStarting:
- brush = tv.startingBrush
-
- default:
- brush = tv.stoppedBrush
- }
+ tunnel := &tv.model.tunnels[style.Row()]
b := style.Bounds()
@@ -126,13 +109,9 @@ func (tv *TunnelsView) StyleCell(style *walk.CellStyle) {
b.Width -= b.Height
canvas.DrawText(tunnel.Name, tv.Font(), 0, b, walk.TextVCenter)
- b.X = 4
- b.Y += 4
- b.Height -= 8
b.Width = b.Height
- canvas.FillEllipse(brush, b)
- canvas.DrawEllipse(tv.statusPen, b)
+ tv.imageProvider.PaintForTunnel(tunnel, canvas, b)
}
func (tv *TunnelsView) CurrentTunnel() *service.Tunnel {