Merge pull request #2296 from dessant/patch-12

Add bar_inactive_color property for ScrollView
This commit is contained in:
Akshay Arora 2014-07-05 18:15:34 +05:30
commit b3952e97f2
2 changed files with 29 additions and 14 deletions

View File

@ -914,12 +914,12 @@
<ScrollView>:
canvas.after:
Color:
rgba: self.bar_color[:3] + [self.bar_color[3] * self.bar_alpha if (self.do_scroll_y and self.viewport_size[1]>self.height) else 0]
rgba: self._bar_color if (self.do_scroll_y and self.viewport_size[1] > self.height) else [0, 0, 0, 0]
Rectangle:
pos: (self.right - self.bar_width - self.bar_margin) if self.bar_pos_y == 'right' else (self.x + self.bar_margin), self.y + self.height * self.vbar[0]
size: min(self.bar_width, self.width), self.height * self.vbar[1]
Color:
rgba: self.bar_color[:3] + [self.bar_color[3] * self.bar_alpha if (self.do_scroll_x and self.viewport_size[0] > self.width) else 0]
rgba: self._bar_color if (self.do_scroll_x and self.viewport_size[0] > self.width) else [0, 0, 0, 0]
Rectangle:
pos: self.x + self.width * self.hbar[0], (self.y + self.bar_margin) if self.bar_pos_x == 'bottom' else (self.top - self.bar_margin - self.bar_width)
size: self.width * self.hbar[1], min(self.bar_width, self.height)

View File

@ -294,6 +294,16 @@ class ScrollView(StencilView):
to [.7, .7, .7, .9].
'''
bar_inactive_color = ListProperty([.7, .7, .7, .2])
'''Color of horizontal / vertical scroll bar (in RGBA format), when no
scroll is happening.
.. versionadded:: 1.8.1
:attr:`bar_inactive_color` is a
:class:`~kivy.properties.ListProperty` and defaults to [.7, .7, .7, .2].
'''
bar_width = NumericProperty('2dp')
'''Width of the horizontal / vertical scroll bar. The width is interpreted
as a height for the horizontal bar.
@ -396,7 +406,7 @@ class ScrollView(StencilView):
# private, for internal use only
_viewport = ObjectProperty(None, allownone=True)
bar_alpha = NumericProperty(1.)
_bar_color = ListProperty([0, 0, 0, 0])
def _set_viewport_size(self, instance, value):
self.viewport_size = value
@ -793,18 +803,23 @@ class ScrollView(StencilView):
vp.pos = 0, 0
self.g_translate.xy = x, y
# new in 1.2.0, show bar when scrolling happen
# and slowly remove them when no scroll is happening.
self.bar_alpha = 1.
Animation.stop_all(self, 'bar_alpha')
Clock.unschedule(self._start_decrease_alpha)
Clock.schedule_once(self._start_decrease_alpha, .5)
# New in 1.2.0, show bar when scrolling happens and (changed in 1.8.1)
# fade to bar_inactive_color when no scroll is happening.
Clock.unschedule(self._bind_inactive_bar_color)
self.unbind(bar_inactive_color=self._change_bar_color)
Animation.stop_all(self, '_bar_color')
self.bind(bar_color=self._change_bar_color)
self._bar_color = self.bar_color
Clock.schedule_once(self._bind_inactive_bar_color, .5)
def _start_decrease_alpha(self, *l):
self.bar_alpha = 1.
# show bars if scroll_type != content
bar_alpha = .2 if self.scroll_type != ['content'] else 0
Animation(bar_alpha=bar_alpha, d=.5, t='out_quart').start(self)
def _bind_inactive_bar_color(self, *l):
self.unbind(bar_color=self._change_bar_color)
self.bind(bar_inactive_color=self._change_bar_color)
Animation(
_bar_color=self.bar_inactive_color, d=.5, t='out_quart').start(self)
def _change_bar_color(self, inst, value):
self._bar_color = value
#
# Private