ui: update layout rects on change (#35545)

* update_layout_rects

* check prev

* about it

* need this since touch can change :(

* looks nicer

* Revert "looks nicer"

This reverts commit 8f36c92675db66695f22f93a01682426db9c05e8.
This commit is contained in:
Shane Smiskol
2025-06-12 16:53:09 -07:00
committed by GitHub
parent 98c34c4b7d
commit cd657f35f0
4 changed files with 25 additions and 20 deletions
+5 -7
View File
@@ -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
+4 -5
View File
@@ -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,11 @@ 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):
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: