pull/35599/head
Shane Smiskol 1 day ago
parent f42d2bf7c8
commit 0203bf7214
  1. 2
      system/ui/lib/application.py
  2. 11
      system/ui/lib/scroll_panel.py

@ -9,7 +9,7 @@ from importlib.resources import as_file, files
from openpilot.common.swaglog import cloudlog from openpilot.common.swaglog import cloudlog
from openpilot.system.hardware import HARDWARE from openpilot.system.hardware import HARDWARE
DEFAULT_FPS = 60 DEFAULT_FPS = 240
FPS_LOG_INTERVAL = 5 # Seconds between logging FPS drops FPS_LOG_INTERVAL = 5 # Seconds between logging FPS drops
FPS_DROP_THRESHOLD = 0.9 # FPS drop threshold for triggering a warning FPS_DROP_THRESHOLD = 0.9 # FPS drop threshold for triggering a warning
FPS_CRITICAL_THRESHOLD = 0.5 # Critical threshold for triggering strict actions FPS_CRITICAL_THRESHOLD = 0.5 # Critical threshold for triggering strict actions

@ -5,7 +5,7 @@ from enum import IntEnum
# Scroll constants for smooth scrolling behavior # Scroll constants for smooth scrolling behavior
MOUSE_WHEEL_SCROLL_SPEED = 30 MOUSE_WHEEL_SCROLL_SPEED = 30
INERTIA_FRICTION = 0.92 # The rate at which the inertia slows down INERTIA_FRICTION = 0.92 # The rate at which the inertia slows down
MIN_VELOCITY = 0.5 # Minimum velocity before stopping the inertia MIN_VELOCITY = 0.5 * 60 # Minimum velocity before stopping the inertia
DRAG_THRESHOLD = 12 # Pixels of movement to consider it a drag, not a click DRAG_THRESHOLD = 12 # Pixels of movement to consider it a drag, not a click
BOUNCE_FACTOR = 0.2 # Elastic bounce when scrolling past boundaries BOUNCE_FACTOR = 0.2 # Elastic bounce when scrolling past boundaries
BOUNCE_RETURN_SPEED = 0.15 # How quickly it returns from the bounce BOUNCE_RETURN_SPEED = 0.15 # How quickly it returns from the bounce
@ -44,6 +44,7 @@ class GuiScrollPanel:
# Calculate time delta # Calculate time delta
current_time = rl.get_time() current_time = rl.get_time()
fps_scale = 60.0 / rl.get_fps()
mouse_pos = rl.get_mouse_position() mouse_pos = rl.get_mouse_position()
max_scroll_y = max(content.height - bounds.height, 0) max_scroll_y = max(content.height - bounds.height, 0)
@ -74,7 +75,7 @@ class GuiScrollPanel:
# Track velocity for inertia # Track velocity for inertia
time_since_last_drag = current_time - self._last_drag_time time_since_last_drag = current_time - self._last_drag_time
if time_since_last_drag > 0: if time_since_last_drag > 0:
drag_velocity = delta_y / time_since_last_drag / 60.0 drag_velocity = delta_y / time_since_last_drag # / 60.0 * fps_scale
self._velocity_history.append(drag_velocity) self._velocity_history.append(drag_velocity)
self._last_drag_time = current_time self._last_drag_time = current_time
@ -134,7 +135,7 @@ class GuiScrollPanel:
# Apply inertia (continue scrolling after mouse release) # Apply inertia (continue scrolling after mouse release)
if self._scroll_state == ScrollState.IDLE: if self._scroll_state == ScrollState.IDLE:
if abs(self._velocity_y) > MIN_VELOCITY: if abs(self._velocity_y) > MIN_VELOCITY:
self._offset.y += self._velocity_y self._offset.y += self._velocity_y * rl.get_frame_time()
self._velocity_y *= INERTIA_FRICTION self._velocity_y *= INERTIA_FRICTION
if self._offset.y > 0 or self._offset.y < -max_scroll_y: if self._offset.y > 0 or self._offset.y < -max_scroll_y:
@ -149,9 +150,9 @@ class GuiScrollPanel:
target_y = -max_scroll_y target_y = -max_scroll_y
distance = target_y - self._offset.y distance = target_y - self._offset.y
bounce_step = distance * BOUNCE_RETURN_SPEED bounce_step = distance * BOUNCE_RETURN_SPEED * fps_scale
self._offset.y += bounce_step self._offset.y += bounce_step
self._velocity_y *= INERTIA_FRICTION * 0.8 self._velocity_y *= pow(INERTIA_FRICTION, fps_scale) * 0.8
if abs(distance) < 0.5 and abs(self._velocity_y) < MIN_VELOCITY: if abs(distance) < 0.5 and abs(self._velocity_y) < MIN_VELOCITY:
self._offset.y = target_y self._offset.y = target_y

Loading…
Cancel
Save