draft on listview

pull/35543/head
Shane Smiskol 2 months ago
parent b0353fc8a1
commit 8ea4fa2a68
  1. 3
      selfdrive/ui/layouts/settings/device.py
  2. 11
      system/ui/lib/list_view.py
  3. 4
      system/ui/lib/widget.py

@ -49,11 +49,12 @@ class DeviceLayout(Widget):
button_item("Pair Device", "PAIR", DESCRIPTIONS['pair_device'], callback=self._pair_device),
button_item("Driver Camera", "PREVIEW", DESCRIPTIONS['driver_camera'], callback=self._show_driver_camera, enabled=ui_state.is_offroad),
button_item("Reset Calibration", "RESET", DESCRIPTIONS['reset_calibration'], callback=self._reset_calibration_prompt),
button_item("Regulatory", "VIEW", callback=self._on_regulatory, visible=TICI),
regulatory := button_item("Regulatory", "VIEW", callback=self._on_regulatory),
button_item("Review Training Guide", "REVIEW", DESCRIPTIONS['review_guide'], self._on_review_training_guide),
button_item("Change Language", "CHANGE", callback=self._show_language_selection, enabled=ui_state.is_offroad),
dual_button_item("Reboot", "Power Off", left_callback=self._reboot_prompt, right_callback=self._power_off_prompt),
]
regulatory.set_visible(TICI)
return items
def _render(self, rect):

@ -203,15 +203,13 @@ class MultipleButtonAction(ItemAction):
@dataclass
class ListItem:
class ListItem(Widget):
title: str
icon: str | None = None
description: str | Callable[[], str] | None = None
description_visible: bool = False
rect: "rl.Rectangle" = rl.Rectangle(0, 0, 0, 0)
callback: Callable | None = None
action_item: ItemAction | None = None
visible: bool | Callable[[], bool] = True
# Cached properties for performance
_prev_max_width: int = 0
@ -219,6 +217,9 @@ class ListItem:
_prev_description: str | None = None
_description_height: float = 0
def _render(self, _):
"""Rendering is done by parent ListView."""
@property
def is_visible(self) -> bool:
return bool(_resolve_value(self.visible, True))
@ -321,12 +322,12 @@ class ListView(Widget):
current_y = 0.0
for item in self._items:
if not item.is_visible:
item.rect = rl.Rectangle(container_rect.x, container_rect.y + current_y, container_rect.width, 0)
item.set_rect(rl.Rectangle(container_rect.x, container_rect.y + current_y, container_rect.width, 0))
continue
content_width = item.get_content_width(int(container_rect.width - ITEM_PADDING * 2))
item_height = item.get_item_height(self._font, content_width)
item.rect = rl.Rectangle(container_rect.x, container_rect.y + current_y, container_rect.width, item_height)
item.set_rect(rl.Rectangle(container_rect.x, container_rect.y + current_y, container_rect.width, item_height))
current_y += item_height
return current_y # total height of all items

@ -16,6 +16,10 @@ class Widget(abc.ABC):
self._is_pressed = False
self._is_visible: bool | Callable[[], bool] = True
@property
def rect(self) -> rl.Rectangle:
return self._rect
@property
def is_visible(self) -> bool:
return self._is_visible() if callable(self._is_visible) else self._is_visible

Loading…
Cancel
Save