From 7cabab69a176b01e0bdd8898d8ea94083b273c94 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Sat, 13 Dec 2025 06:15:31 -0800 Subject: [PATCH] comma four: follow current network (#36862) * stay * whoops * whoops * fix * fix div by z * we can implement layout to fix flashing * Revert "we can implement layout to fix flashing" This reverts commit 7278a1e2a6117aec775ef4fabee2fd68b3d064f3. * random * clean up * wtf * rev * smooth * we can implement layout to fix flashing * snap looks so much better * fix * rev * better name * cmt * less random * even less random * simpler * cmt * clean up * clean up * clean up --- .../ui/mici/layouts/settings/network/wifi_ui.py | 16 ++++++++++++++-- selfdrive/ui/mici/widgets/dialog.py | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py b/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py index 7137169784..ed5454d8e0 100644 --- a/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py +++ b/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py @@ -334,7 +334,9 @@ class WifiUIMici(BigMultiOptionDialog): self._connecting: str | None = None self._networks: dict[str, Network] = {} + # widget state self._last_interaction_time = rl.get_time() + self._restore_selection = False self._wifi_manager.add_callbacks( need_auth=self._on_need_auth, @@ -390,14 +392,17 @@ class WifiUIMici(BigMultiOptionDialog): # remove networks no longer present self._scroller._items[:] = [btn for btn in self._scroller._items if btn.option in self._networks] + # try to restore previous selection to prevent jumping from adding/removing/reordering buttons + self._restore_selection = True + def _connect_with_password(self, ssid: str, password: str): if password: self._connecting = ssid self._wifi_manager.connect_to_network(ssid, password) self._update_buttons() - def _on_option_selected(self, option: str): - super()._on_option_selected(option) + def _on_option_selected(self, option: str, smooth_scroll: bool = True): + super()._on_option_selected(option, smooth_scroll) # only open if button is already selected if option in self._networks and option == self._selected_option: @@ -443,6 +448,13 @@ class WifiUIMici(BigMultiOptionDialog): self._last_interaction_time = rl.get_time() def _render(self, _): + # Update Scroller layout and restore current selection whenever buttons are updated, before first render + current_selection = self.get_selected_option() + if self._restore_selection and current_selection in self._networks: + self._scroller._layout() + BigMultiOptionDialog._on_option_selected(self, current_selection, smooth_scroll=False) + self._restore_selection = None + super()._render(_) if not self._networks: diff --git a/selfdrive/ui/mici/widgets/dialog.py b/selfdrive/ui/mici/widgets/dialog.py index b5374791e8..4021a11c23 100644 --- a/selfdrive/ui/mici/widgets/dialog.py +++ b/selfdrive/ui/mici/widgets/dialog.py @@ -349,7 +349,7 @@ class BigMultiOptionDialog(BigDialogBase): def get_selected_option(self) -> str: return self._selected_option - def _on_option_selected(self, option: str): + def _on_option_selected(self, option: str, smooth_scroll: bool = True): y_pos = 0.0 for btn in self._scroller._items: btn = cast(BigDialogOptionButton, btn) @@ -365,7 +365,7 @@ class BigMultiOptionDialog(BigDialogBase): y_pos = rect_center_y - (btn.rect.y + height / 2) break - self._scroller.scroll_to(-y_pos, smooth=True) + self._scroller.scroll_to(-y_pos, smooth=smooth_scroll) def _selected_option_changed(self): pass