mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 20:03:53 +08:00
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
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user