Skip to content

Commit 3959200

Browse files
authored
Scroll panel 2: use float for offset (#36705)
* use float internally * use it everywhere -- this fixes all the problemS?! * round it everywhere * this looks so much better than before * rm
1 parent f8d0f22 commit 3959200

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

selfdrive/ui/mici/layouts/settings/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _render(self, rect: rl.Rectangle):
3939
content_height += self._fcc_logo.height + 20
4040

4141
scroll_content_rect = rl.Rectangle(rect.x, rect.y, rect.width, content_height)
42-
scroll_offset = self._scroll_panel.update(rect, scroll_content_rect.height)
42+
scroll_offset = round(self._scroll_panel.update(rect, scroll_content_rect.height))
4343

4444
fcc_pos = rl.Vector2(rect.x + 20, rect.y + 20 + scroll_offset)
4545

selfdrive/ui/mici/layouts/settings/firehose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def show_event(self):
6565
def _render(self, rect: rl.Rectangle):
6666
# compute total content height for scrolling
6767
content_height = self._measure_content_height(rect)
68-
scroll_offset = self._scroll_panel.update(rect, content_height)
68+
scroll_offset = round(self._scroll_panel.update(rect, content_height))
6969

7070
# start drawing with offset
7171
x = int(rect.x + 40)

system/ui/lib/scroll_panel2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from openpilot.system.hardware import TICI
99
from collections import deque
1010

11-
MIN_VELOCITY = 2 # px/s, changes from auto scroll to steady state
11+
MIN_VELOCITY = 10 # px/s, changes from auto scroll to steady state
1212
MIN_VELOCITY_FOR_CLICKING = 2 * 60 # px/s, accepts clicks while auto scrolling below this velocity
1313
MIN_DRAG_PIXELS = 12
1414
AUTO_SCROLL_TC_SNAP = 0.025
@@ -202,8 +202,8 @@ def _handle_mouse_event(self, mouse_event: MouseEvent, bounds: rl.Rectangle, bou
202202
def _get_mouse_pos(self, mouse_event: MouseEvent) -> float:
203203
return mouse_event.pos.x if self._horizontal else mouse_event.pos.y
204204

205-
def get_offset(self) -> int:
206-
return round(self._offset.x if self._horizontal else self._offset.y)
205+
def get_offset(self) -> float:
206+
return self._offset.x if self._horizontal else self._offset.y
207207

208208
def set_offset(self, value: float) -> None:
209209
if self._horizontal:

system/ui/mici_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _render_content(self, scroll_offset):
244244
pass
245245

246246
def _render(self, _):
247-
scroll_offset = self._scroll_panel.update(self._rect, self._content_height + self._continue_button.rect.height + 16)
247+
scroll_offset = round(self._scroll_panel.update(self._rect, self._content_height + self._continue_button.rect.height + 16))
248248

249249
if scroll_offset <= self._scrolled_down_offset:
250250
# don't show back if not enabled

system/ui/widgets/scroller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _get_scroll(self, visible_items: list[Widget], content_size: float) -> float
124124
self.scroll_panel.set_enabled(scroll_enabled and self.enabled)
125125
self.scroll_panel.update(self._rect, content_size)
126126
if not self._snap_items:
127-
return self.scroll_panel.get_offset()
127+
return round(self.scroll_panel.get_offset())
128128

129129
# Snap closest item to center
130130
center_pos = self._rect.x + self._rect.width / 2 if self._horizontal else self._rect.y + self._rect.height / 2

0 commit comments

Comments
 (0)