Skip to content

Commit

Permalink
Don't mess up the component bounds in HiDPI mode (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins committed Feb 26, 2021
1 parent facc39f commit c39183f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 6 additions & 3 deletions enable/abstract_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,19 @@ def _component_changed(self, old, new):
size = self._get_control_size()
if (size is not None) and hasattr(self.component, "bounds"):
new.on_trait_change(self.component_bounds_changed, "bounds")
pix_scale = self.base_pixel_scale
if getattr(self.component, "fit_window", False):
self.component.outer_position = [0, 0]
self.component.outer_bounds = list(size)
self.component.outer_bounds = [
size[0] / pix_scale, size[1] / pix_scale
]
elif hasattr(self.component, "resizable"):
if "h" in self.component.resizable:
self.component.outer_x = 0
self.component.outer_width = size[0]
self.component.outer_width = size[0] / pix_scale
if "v" in self.component.resizable:
self.component.outer_y = 0
self.component.outer_height = size[1]
self.component.outer_height = size[1] / pix_scale
self._update_region = None
self.redraw()

Expand Down
19 changes: 18 additions & 1 deletion enable/tests/test_component_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"""
import unittest

from enable.component_editor import ComponentEditor
from traits.api import Any, HasTraits
from traitsui.api import Item, View

from enable.component import Component
from enable.component_editor import ComponentEditor
from enable.tests._testing import get_dialog_size, skip_if_null

ITEM_WIDTH, ITEM_HEIGHT = 700, 200
Expand Down Expand Up @@ -72,3 +73,19 @@ def test_initial_component_with_item_size(self):

self.assertGreater(size[0], ITEM_WIDTH - 1)
self.assertGreater(size[1], ITEM_HEIGHT - 1)

@skip_if_null
def test_component_hidpi_size_stability(self):
# Issue #634: HiDPI doubles size of components when a component is
# replaced
dialog = _ComponentDialogWithSize(thing=Component())
dialog.edit_traits()

initial_bounds = dialog.thing.bounds
# Force the window into HiDPI mode
dialog.thing.window.base_pixel_scale = 2.0

dialog.thing = Component()
new_bounds = dialog.thing.bounds

self.assertListEqual(initial_bounds, new_bounds)

0 comments on commit c39183f

Please sign in to comment.