diff --git a/selfdrive/ui/layouts/home.py b/selfdrive/ui/layouts/home.py index f255d2403c..53e1968d48 100644 --- a/selfdrive/ui/layouts/home.py +++ b/selfdrive/ui/layouts/home.py @@ -67,8 +67,6 @@ class HomeLayout(Widget): self.current_state = state def _render(self, rect: rl.Rectangle): - self._update_layout_rects(rect) - current_time = time.time() if current_time - self.last_refresh >= REFRESH_INTERVAL: self._refresh() @@ -85,16 +83,16 @@ class HomeLayout(Widget): elif self.current_state == HomeLayoutState.ALERTS: self._render_alerts_view() - def _update_layout_rects(self, rect: rl.Rectangle): + def _update_layout_rects(self): self.header_rect = rl.Rectangle( - rect.x + CONTENT_MARGIN, rect.y + CONTENT_MARGIN, rect.width - 2 * CONTENT_MARGIN, HEADER_HEIGHT + self._rect.x + CONTENT_MARGIN, self._rect.y + CONTENT_MARGIN, self._rect.width - 2 * CONTENT_MARGIN, HEADER_HEIGHT ) - content_y = rect.y + CONTENT_MARGIN + HEADER_HEIGHT + SPACING - content_height = rect.height - CONTENT_MARGIN - HEADER_HEIGHT - SPACING - CONTENT_MARGIN + content_y = self._rect.y + CONTENT_MARGIN + HEADER_HEIGHT + SPACING + content_height = self._rect.height - CONTENT_MARGIN - HEADER_HEIGHT - SPACING - CONTENT_MARGIN self.content_rect = rl.Rectangle( - rect.x + CONTENT_MARGIN, content_y, rect.width - 2 * CONTENT_MARGIN, content_height + self._rect.x + CONTENT_MARGIN, content_y, self._rect.width - 2 * CONTENT_MARGIN, content_height ) left_width = self.content_rect.width - RIGHT_COLUMN_WIDTH - SPACING diff --git a/selfdrive/ui/layouts/main.py b/selfdrive/ui/layouts/main.py index a1adf667f9..1cca86c82e 100644 --- a/selfdrive/ui/layouts/main.py +++ b/selfdrive/ui/layouts/main.py @@ -30,8 +30,7 @@ class MainLayout(Widget): # Set callbacks self._setup_callbacks() - def _render(self, rect): - self._update_layout_rects(rect) + def _render(self, _): self._handle_onroad_transition() self._render_main_content() @@ -42,11 +41,12 @@ class MainLayout(Widget): self._layouts[MainState.SETTINGS].set_callbacks(on_close=self._set_mode_for_state) self._layouts[MainState.ONROAD].set_callbacks(on_click=self._on_onroad_clicked) - def _update_layout_rects(self, rect): - self._sidebar_rect = rl.Rectangle(rect.x, rect.y, SIDEBAR_WIDTH, rect.height) + def _update_layout_rects(self): + print('hi') + self._sidebar_rect = rl.Rectangle(self._rect.x, self._rect.y, SIDEBAR_WIDTH, self._rect.height) x_offset = SIDEBAR_WIDTH if self._sidebar.is_visible else 0 - self._content_rect = rl.Rectangle(rect.y + x_offset, rect.y, rect.width - x_offset, rect.height) + self._content_rect = rl.Rectangle(self._rect.y + x_offset, self._rect.y, self._rect.width - x_offset, self._rect.height) def _handle_onroad_transition(self): if ui_state.started != self._prev_onroad: diff --git a/system/ui/lib/widget.py b/system/ui/lib/widget.py index d31f961e26..ea58f0f15e 100644 --- a/system/ui/lib/widget.py +++ b/system/ui/lib/widget.py @@ -12,6 +12,7 @@ class DialogResult(IntEnum): class Widget(abc.ABC): def __init__(self): + self._prev_rect = rl.Rectangle(0, 0, 0, 0) self._rect: rl.Rectangle = rl.Rectangle(0, 0, 0, 0) self._is_pressed = False self._is_visible: bool | Callable[[], bool] = True @@ -25,6 +26,7 @@ class Widget(abc.ABC): def set_rect(self, rect: rl.Rectangle) -> None: self._rect = rect + self._update_layout_rects() def render(self, rect: rl.Rectangle = None) -> bool | int | None: if rect is not None: @@ -55,3 +57,6 @@ class Widget(abc.ABC): def _handle_mouse_release(self, mouse_pos: rl.Vector2) -> bool: """Handle mouse release events, if applicable.""" return False + + def _update_layout_rects(self) -> None: + """Update the layout rectangles on change."""