Skip to content

Commit

Permalink
Fixed slider with vertical orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
HeaTTheatR committed May 17, 2024
1 parent cfe5aac commit 0c6e79e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
20 changes: 11 additions & 9 deletions kivymd/uix/slider/slider.kv
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@
points: self._active_points
pointsize: self.step_point_size

size_hint_y: None
height:
handle_container.children[0].height \
if handle_container.children else 0

# Label container.
BoxLayout:
id: value_container
Expand Down Expand Up @@ -185,13 +180,21 @@
pos:
( \
( \
self._slider.value_pos[0] - (self._slider._value_label.texture_size[0] / 2) + dp(10), \
# X.
self._slider.value_pos[0] \
- (self._slider._value_label.texture_size[0] / 2) + dp(10), \
# Y.
self._slider.center_y + dp(28) \
) \
if self._slider.orientation == "horizontal" else \
( \
self._slider.center_x - self.width / 2, \
self._slider.value_pos[1] - dp(0) \
# X.
self._slider.center_x \
- (self._slider._value_label.texture_size[0] / 2) - dp(2), \
# Y.
self._slider.value_pos[1] + \
self._slider._value_label.texture_size[1] \
+ self._slider._handle.state_layer_size[1] / 2, \
) \
) \
if self._slider and self._slider._value_label else (0, 0)
Expand All @@ -200,7 +203,6 @@
if self._slider and self._slider._value_label else (0, 0)

size_hint: None, None
# opacity: 0
size:
self._slider._value_label.size \
if self._slider and self._slider._value_label else \
Expand Down
26 changes: 20 additions & 6 deletions kivymd/uix/slider/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,23 @@ def update_points(self, instance, step) -> None:
"""Draws the step points on the slider."""

def update_points(*args):
y = self.center_y - self.track_active_width / 2
slider_length = self.width - (self.padding * 2)
y = (
self.center_y
if self.orientation == "horizontal"
else self.center_x
) - self.track_active_width / 2
slider_length = (
self.width if self.orientation == "horizontal" else self.height
) - (self.padding * 2)
slider_max_value = int(self.max)
multiplier = slider_length / slider_max_value
active_track_width = (
self.width - self.padding * 2
(
self.width
if self.orientation == "horizontal"
else self.height
)
- self.padding * 2
) * self.value_normalized

for i in range(0, slider_max_value + 1, step):
Expand All @@ -288,8 +299,11 @@ def update_points(*args):
else:
points = self._active_points

if self.orientation == "vertical":
points.append(y)

points.append(
self.x
(self.x if self.orientation == "horizontal" else self.y)
+ x
+ self.padding
+ (
Expand All @@ -298,7 +312,8 @@ def update_points(*args):
else 0
)
)
points.append(y)
if self.orientation == "horizontal":
points.append(y)

Clock.schedule_once(update_points)

Expand Down Expand Up @@ -392,7 +407,6 @@ def on_handle_leave(self) -> None:
Animation(
scale_value_x=0,
scale_value_y=0,
# opacity=1,
d=self.value_container_hide_anim_duration,
t=self.value_container_hide_anim_transition,
).start(self._value_container)
Expand Down

0 comments on commit 0c6e79e

Please sign in to comment.