From be01929f5d00456024e203bc56955105930e248c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 14 May 2019 18:18:06 +0200 Subject: ui: fix dpi related code smells Signed-off-by: Alexander Neumann --- ui/confview.go | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'ui/confview.go') diff --git a/ui/confview.go b/ui/confview.go index 869ba229..1024befa 100644 --- a/ui/confview.go +++ b/ui/confview.go @@ -36,7 +36,6 @@ type labelStatusLine struct { statusComposite *walk.Composite statusImage *walk.ImageView statusLabel *walk.LineEdit - cachedImages map[rectAndSizeAndState]walk.Image } type labelTextLine struct { @@ -86,27 +85,13 @@ func (lsl *labelStatusLine) widgets() (walk.Widget, walk.Widget) { } func (lsl *labelStatusLine) update(state service.TunnelState) { - margin := lsl.label.DPI() / 48 //TODO: Do some sort of dynamic DPI calculation here - imageSize := lsl.label.SizeHint() - imageSize.Width = imageSize.Height - //TODO: the *2 in the Y coordinate fixes weird alignment bugs. Why? - imageRect := walk.Rectangle{margin, margin * 2, imageSize.Width - margin*2, imageSize.Height - margin*2} - img := lsl.cachedImages[rectAndSizeAndState{imageRect, imageSize, state}] - if img == nil { - img, _ = walk.NewBitmapWithTransparentPixels(imageSize) - canvas, _ := walk.NewCanvasFromImage(img) - icon, err := iconForState(state, imageRect.Size().Width) - if err == nil { - canvas.DrawImageStretched(icon, imageRect) - canvas.Dispose() - lsl.cachedImages[rectAndSizeAndState{imageRect, imageSize, state}] = img - } else { - canvas.Dispose() - img.Dispose() - img = nil - } + icon, err := iconForState(state, 14) + if err == nil { + lsl.statusImage.SetImage(icon) + } else { + lsl.statusImage.SetImage(nil) } - lsl.statusImage.SetImage(img) + s, e := lsl.statusLabel.TextSelection() lsl.statusLabel.SetText(textForState(state, false)) lsl.statusLabel.SetTextSelection(s, e) @@ -115,8 +100,6 @@ func (lsl *labelStatusLine) update(state service.TunnelState) { func newLabelStatusLine(parent walk.Container) *labelStatusLine { lsl := new(labelStatusLine) - lsl.cachedImages = make(map[rectAndSizeAndState]walk.Image) - lsl.label, _ = walk.NewTextLabel(parent) lsl.label.SetText("Status:") lsl.label.SetTextAlignment(walk.AlignHFarVNear) @@ -129,6 +112,7 @@ func newLabelStatusLine(parent walk.Container) *labelStatusLine { lsl.statusComposite.SetLayout(layout) lsl.statusImage, _ = walk.NewImageView(lsl.statusComposite) + lsl.statusImage.SetMargin(2) lsl.statusImage.SetMode(walk.ImageViewModeIdeal) lsl.statusLabel, _ = walk.NewLineEdit(lsl.statusComposite) -- cgit v1.2.3-59-g8ed1b