From 1755ab4c3f71cbbbf8d55998738701ec5f9eb5d8 Mon Sep 17 00:00:00 2001 From: Yaar Podshipnik Date: Wed, 26 Aug 2020 17:01:20 +0100 Subject: [PATCH] Fix HiDPI scaling issues in VectorPicker VectorPicker was DPI unware, so when asking GetClientSize() it would get the actual size multiplied by the scaling factor of GetContentScaleFactor(). This made the widget seem to be cut off and display only the upper left quarter of the circle. Similarly, when choosing the font size for the percentages, it wouldn't scale the maximum size, resulting in very large text. --- graphs/gui/vector.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/graphs/gui/vector.py b/graphs/gui/vector.py index c3566bc35..393bd8e6f 100644 --- a/graphs/gui/vector.py +++ b/graphs/gui/vector.py @@ -36,9 +36,9 @@ class VectorPicker(wx.Window): self._labelpos = int(kwargs.pop('labelpos', 0)) self._offset = float(kwargs.pop('offset', 0)) self._size = max(0, float(kwargs.pop('size', 50))) - self._fontsize = max(1, float(kwargs.pop('fontsize', 8))) self._directionOnly = kwargs.pop('directionOnly', False) super().__init__(*args, **kwargs) + self._fontsize = max(1, float(kwargs.pop('fontsize', 8 / self.GetContentScaleFactor()))) self._font = wx.Font(self._fontsize, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False) self._angle = 0 self.__length = 1 @@ -107,8 +107,11 @@ class VectorPicker(wx.Window): dc = wx.BufferedPaintDC(self) self.Draw(dc) + def GetScaledClientSize(self): + return tuple([dim / self.GetContentScaleFactor() for dim in self.GetClientSize()]) + def Draw(self, dc): - width, height = self.GetClientSize() + width, height = self.GetScaledClientSize() if not width or not height: return dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.BRUSHSTYLE_SOLID))