diff options
author | 2019-04-04 10:16:23 +0200 | |
---|---|---|
committer | 2019-04-23 11:04:59 +0200 | |
commit | abe6eb03d817b6d88ef4acc872ba794bc3d44191 (patch) | |
tree | 3272f76a287a1fb225e868cbdb9638928553b3b0 /ui/tunnelsview.go | |
parent | ui: implement a reusable helper for status image painting (diff) | |
download | wireguard-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 'ui/tunnelsview.go')
-rw-r--r-- | ui/tunnelsview.go | 47 |
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 { |