mirror of https://github.com/kivy/kivy.git
Step property to use slider with fixed intervals
This commit is contained in:
parent
094d9f97ea
commit
4c9c1a5aac
|
@ -86,6 +86,15 @@ class Slider(Widget):
|
|||
(:data:`min`, :data:`max`)
|
||||
'''
|
||||
|
||||
step = NumericProperty(1)
|
||||
'''Step size of the slider
|
||||
Determines the size of each interval or step the slider takes between
|
||||
min and max. If the value range can't be evenly divisible by step the
|
||||
last step will be capped by slider.max
|
||||
:data:`step` is a :class:`~kivy.properties.NumericProperty`, default to
|
||||
1.
|
||||
'''
|
||||
|
||||
def get_norm_value(self):
|
||||
vmin = self.min
|
||||
d = self.max - vmin
|
||||
|
@ -95,7 +104,11 @@ class Slider(Widget):
|
|||
|
||||
def set_norm_value(self, value):
|
||||
vmin = self.min
|
||||
self.value = value * (self.max - vmin) + vmin
|
||||
val = value * (self.max - vmin) + vmin
|
||||
if self.step == 1:
|
||||
self.value = val
|
||||
else:
|
||||
self.value = min(round((val-vmin)/self.step)*self.step,self.max)
|
||||
value_normalized = AliasProperty(get_norm_value, set_norm_value,
|
||||
bind=('value', 'min', 'max'))
|
||||
'''Normalized value inside the :data:`range` (min/max) to 0-1 range::
|
||||
|
|
Loading…
Reference in New Issue