Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #143 from enthought/programmatic-scrolling

Add programmatic scrolling to ScrollArea components.
  • Loading branch information...
commit 9abd4696e6f0fcaa185a4a973ba50ed986a290c5 2 parents c15f00c + 2b9a5ab
@sccolbert sccolbert authored
View
12 enaml/backends/qt/qt_scroll_area.py
@@ -75,6 +75,18 @@ def horizontal_scrollbar_thickness(self):
"""
return self._scrollbar_thickness(QtCore.Qt.Vertical)
+ def scroll_to_position(self, position, margin):
+ """ Scrolls the area such that position is visible with a
+ minimum of margin points surrounding position.
+
+ """
+ widget = self.widget
+
+ pos_x, pos_y = position
+ margin_x, margin_y = margin
+
+ widget.ensureVisible(pos_x, pos_y, margin_x, margin_y)
+
#--------------------------------------------------------------------------
# Widget Update Methods
#--------------------------------------------------------------------------
View
16 enaml/backends/wx/wx_scroll_area.py
@@ -151,6 +151,22 @@ def horizontal_scrollbar_thickness(self):
"""
return wx.SystemSettings.GetMetric(wx.SYS_HSCROLL_Y)
+ def scroll_to_position(self, position, margin):
+ """ Scrolls the area such that position is visible with a
+ minimum of margin points surrounding position.
+
+ """
+ widget = self.widget
+
+ pos_x, pos_y = position
+ margin_x, margin_y = margin
+ scroll_unit_x, scroll_unit_y = widget.GetScrollPixelsPerUnit()
+ scroll_unit_x = 1.0 if scroll_unit_x == 0.0 else scroll_unit_x
+ scroll_unit_y = 1.0 if scroll_unit_y == 0.0 else scroll_unit_y
+
+ widget.Scroll(max(0.0, (pos_x - margin_x) / float(scroll_unit_x)),
+ max(0.0, (pos_y - margin_y) / float(scroll_unit_y)))
+
def size_hint(self):
""" Returns a (width, height) tuple of integers for the size hint
of the scroll area. Overridden from the parent class to return
View
20 enaml/components/scroll_area.py
@@ -50,6 +50,9 @@ def horizontal_scrollbar_thickness(self):
def vertical_scrollbar_thickness(self):
raise NotImplementedError
+ @abstractmethod
+ def scroll_to_position(self, position, margin):
+ raise NotImplementedError
class ScrollArea(LayoutTaskHandler, ConstraintsWidget):
""" A LayoutComponent subclass that displays just a single child in
@@ -87,7 +90,22 @@ class ScrollArea(LayoutTaskHandler, ConstraintsWidget):
#: Overridden parent class trait
abstract_obj = Instance(AbstractTkScrollArea)
-
+
+ def scroll_to_position(self, position, margin):
+ """ Scrolls the area such that position is visible with a
+ minimum of margin_size points surrounding position.
+
+ Parameters
+ ----------
+ position : (x, y)
+ The x,y tuple of the position to be made visible.
+
+ margin : (x-margin, y-margin)
+ The x,y size tuple of the margins to keep around position.
+
+ """
+ self.abstract_obj.scroll_to_position(position, margin)
+
#--------------------------------------------------------------------------
# Property Getters
#--------------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.