From f42d2bf7c8c2491da89dd84bbeff6d98da908460 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 25 Jun 2025 15:06:15 -0700 Subject: [PATCH] use a deque --- system/ui/lib/scroll_panel.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/system/ui/lib/scroll_panel.py b/system/ui/lib/scroll_panel.py index dd84ba7fef..df20034a48 100644 --- a/system/ui/lib/scroll_panel.py +++ b/system/ui/lib/scroll_panel.py @@ -1,4 +1,5 @@ import pyray as rl +from collections import deque from enum import IntEnum # Scroll constants for smooth scrolling behavior @@ -31,7 +32,7 @@ class GuiScrollPanel: self._velocity_y = 0.0 # Velocity for inertia self._is_dragging: bool = False self._bounce_offset: float = 0.0 - self._velocity_history: list[float] = [] + self._velocity_history: deque[float] = deque(maxlen=VELOCITY_HISTORY_SIZE) self._last_drag_time: float = 0.0 self._content_rect: rl.Rectangle | None = None self._bounds_rect: rl.Rectangle | None = None @@ -60,7 +61,7 @@ class GuiScrollPanel: self._last_mouse_y = mouse_pos.y self._start_mouse_y = mouse_pos.y self._last_drag_time = current_time - self._velocity_history = [] + self._velocity_history.clear() self._velocity_y = 0.0 self._bounce_offset = 0.0 self._is_dragging = False @@ -76,9 +77,6 @@ class GuiScrollPanel: drag_velocity = delta_y / time_since_last_drag / 60.0 self._velocity_history.append(drag_velocity) - if len(self._velocity_history) > VELOCITY_HISTORY_SIZE: - self._velocity_history.pop(0) - self._last_drag_time = current_time # Detect actual dragging