mirror of
https://github.com/SeedSigner/seedsigner.git
synced 2026-10-05 23:18:25 +00:00
Use checkmark to indicate selected language, ensure initial scroll displays it
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import math
|
||||
import logging
|
||||
import time
|
||||
|
||||
@@ -296,7 +297,8 @@ class ButtonListScreen(BaseTopNavScreen):
|
||||
Button_cls = Button
|
||||
checked_buttons: List[int] = None
|
||||
|
||||
# Enables returning w/buttons rendered at the same place
|
||||
# Enables returning w/buttons rendered at the same place; default behavior will
|
||||
# ensure the screen is at least scrolled to reveal the `selected_button`.
|
||||
scroll_y_initial_offset: int = None
|
||||
|
||||
|
||||
@@ -324,6 +326,15 @@ class ButtonListScreen(BaseTopNavScreen):
|
||||
button_list_y = self.top_nav.height
|
||||
self.has_scroll_arrows = True
|
||||
|
||||
# How many buttons fit on the screen before we need to start scrolling?
|
||||
num_buttons_pre_scroll = math.floor((self.canvas_height - button_list_y - GUIConstants.EDGE_PADDING) / (button_height + GUIConstants.LIST_ITEM_PADDING))
|
||||
|
||||
# Force a scroll offset when necessary if none was provided
|
||||
if self.selected_button + 1 > num_buttons_pre_scroll and not self.scroll_y_initial_offset:
|
||||
# Scroll far enough to expose the selected button; +1 to account for the
|
||||
# height of the target button itself!
|
||||
self.scroll_y_initial_offset = (button_height + GUIConstants.LIST_ITEM_PADDING) * (self.selected_button - num_buttons_pre_scroll + 1)
|
||||
|
||||
self.buttons: List[Button] = []
|
||||
for i, button_option in enumerate(self.button_data):
|
||||
if type(button_option) != ButtonOption:
|
||||
|
||||
@@ -21,7 +21,6 @@ class SettingsEntryUpdateSelectionScreen(ButtonListScreen):
|
||||
help_text: str = None
|
||||
checked_buttons: List[int] = None
|
||||
settings_entry_type: str = SettingsConstants.TYPE__ENABLED_DISABLED
|
||||
selected_button: int = 0
|
||||
|
||||
def __post_init__(self):
|
||||
self.title = _("Settings")
|
||||
|
||||
@@ -99,8 +99,11 @@ class SettingsMenuView(View):
|
||||
|
||||
class LocaleSelectionView(View):
|
||||
def run(self):
|
||||
cur_language_code = self.settings.get_value(SettingsConstants.SETTING__LOCALE)
|
||||
|
||||
selected_button = 0
|
||||
button_data: list[ButtonOption] = []
|
||||
for language_code, display_name in SettingsConstants.get_detected_languages():
|
||||
for i, (language_code, display_name) in enumerate(SettingsConstants.get_detected_languages()):
|
||||
button_data.append(
|
||||
# Unique to this View: override each button's font so we can display each
|
||||
# language name in its native script.
|
||||
@@ -112,11 +115,16 @@ class LocaleSelectionView(View):
|
||||
)
|
||||
)
|
||||
|
||||
if language_code == cur_language_code:
|
||||
# Highlight the current selection
|
||||
selected_button = i
|
||||
|
||||
selected_menu_num = self.run_screen(
|
||||
ButtonListScreen,
|
||||
settings_screens.SettingsEntryUpdateSelectionScreen,
|
||||
display_name=_(SettingsDefinition.get_settings_entry(attr_name=SettingsConstants.SETTING__LOCALE).display_name),
|
||||
button_data=button_data,
|
||||
title=_(SettingsDefinition.get_settings_entry(attr_name=SettingsConstants.SETTING__LOCALE).display_name),
|
||||
is_button_text_centered=False,
|
||||
selected_button=selected_button,
|
||||
checked_buttons=[selected_button],
|
||||
)
|
||||
|
||||
if selected_menu_num == RET_CODE__BACK_BUTTON:
|
||||
|
||||
Reference in New Issue
Block a user