mirror of https://github.com/kivy/kivy.git
Merge pull request #2296 from dessant/patch-12
Add bar_inactive_color property for ScrollView
This commit is contained in:
commit
b3952e97f2
|
@ -914,12 +914,12 @@
|
||||||
<ScrollView>:
|
<ScrollView>:
|
||||||
canvas.after:
|
canvas.after:
|
||||||
Color:
|
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:
|
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]
|
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]
|
size: min(self.bar_width, self.width), self.height * self.vbar[1]
|
||||||
Color:
|
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:
|
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)
|
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)
|
size: self.width * self.hbar[1], min(self.bar_width, self.height)
|
||||||
|
|
|
@ -294,6 +294,16 @@ class ScrollView(StencilView):
|
||||||
to [.7, .7, .7, .9].
|
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')
|
bar_width = NumericProperty('2dp')
|
||||||
'''Width of the horizontal / vertical scroll bar. The width is interpreted
|
'''Width of the horizontal / vertical scroll bar. The width is interpreted
|
||||||
as a height for the horizontal bar.
|
as a height for the horizontal bar.
|
||||||
|
@ -396,7 +406,7 @@ class ScrollView(StencilView):
|
||||||
# private, for internal use only
|
# private, for internal use only
|
||||||
|
|
||||||
_viewport = ObjectProperty(None, allownone=True)
|
_viewport = ObjectProperty(None, allownone=True)
|
||||||
bar_alpha = NumericProperty(1.)
|
_bar_color = ListProperty([0, 0, 0, 0])
|
||||||
|
|
||||||
def _set_viewport_size(self, instance, value):
|
def _set_viewport_size(self, instance, value):
|
||||||
self.viewport_size = value
|
self.viewport_size = value
|
||||||
|
@ -793,18 +803,23 @@ class ScrollView(StencilView):
|
||||||
vp.pos = 0, 0
|
vp.pos = 0, 0
|
||||||
self.g_translate.xy = x, y
|
self.g_translate.xy = x, y
|
||||||
|
|
||||||
# new in 1.2.0, show bar when scrolling happen
|
# New in 1.2.0, show bar when scrolling happens and (changed in 1.8.1)
|
||||||
# and slowly remove them when no scroll is happening.
|
# fade to bar_inactive_color when no scroll is happening.
|
||||||
self.bar_alpha = 1.
|
Clock.unschedule(self._bind_inactive_bar_color)
|
||||||
Animation.stop_all(self, 'bar_alpha')
|
self.unbind(bar_inactive_color=self._change_bar_color)
|
||||||
Clock.unschedule(self._start_decrease_alpha)
|
Animation.stop_all(self, '_bar_color')
|
||||||
Clock.schedule_once(self._start_decrease_alpha, .5)
|
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):
|
def _bind_inactive_bar_color(self, *l):
|
||||||
self.bar_alpha = 1.
|
self.unbind(bar_color=self._change_bar_color)
|
||||||
# show bars if scroll_type != content
|
self.bind(bar_inactive_color=self._change_bar_color)
|
||||||
bar_alpha = .2 if self.scroll_type != ['content'] else 0
|
Animation(
|
||||||
Animation(bar_alpha=bar_alpha, d=.5, t='out_quart').start(self)
|
_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
|
# Private
|
||||||
|
|
Loading…
Reference in New Issue