aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/confview.go
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-05-14 18:18:06 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-15 20:11:19 +0200
commitbe01929f5d00456024e203bc56955105930e248c (patch)
tree89e4461bc9aba159e91396dde0b165fda74e886b /ui/confview.go
parentui: don't closehandle on a menu (diff)
downloadwireguard-windows-be01929f5d00456024e203bc56955105930e248c.tar.xz
wireguard-windows-be01929f5d00456024e203bc56955105930e248c.zip
ui: fix dpi related code smells
Signed-off-by: Alexander Neumann <alexander.neumann@picos-software.com>
Diffstat (limited to 'ui/confview.go')
-rw-r--r--ui/confview.go30
1 files changed, 7 insertions, 23 deletions
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)