Merge branch 'rl-display-panel' into screensaver

This commit is contained in:
nayan
2025-12-04 15:08:28 -05:00
@@ -5,9 +5,25 @@ This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
from openpilot.common.params import Params
from openpilot.system.ui.widgets.scroller_tici import Scroller
from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.lib.multilang import tr
from openpilot.system.ui.widgets.scroller_tici import Scroller
from openpilot.system.ui.sunnypilot.widgets.list_view import toggle_item_sp, option_item_sp
onroad_brightness_timer_values = {
0: 15,
1: 30,
2: 60,
3: 120,
4: 180,
5: 240,
6: 300,
7: 360,
8: 420,
9: 480,
10: 540,
11: 600
}
class DisplayLayout(Widget):
def __init__(self):
@@ -18,11 +34,66 @@ class DisplayLayout(Widget):
self._scroller = Scroller(items, line_separator=True, spacing=0)
def _initialize_items(self):
self._onroad_brightness_toggle = toggle_item_sp(
param="OnroadScreenOffControl",
title=lambda: tr("Onroad Screen: Reduced Brightness"),
description=lambda: tr("Turn off device screen or reduce brightness after driving starts. " +
"It automatically brightens again when screen is touched or a visible alert is displayed."),
)
self._onroad_brightness_timer = option_item_sp(
param="OnroadScreenOffTimer",
title=lambda: tr("Onroad Brightness Delay"),
description="",
min_value=0,
max_value=11,
value_change_step=1,
value_map=onroad_brightness_timer_values,
label_callback=lambda value: f"{value} s" if value < 60 else f"{int(value/60)} m",
)
self._onroad_brightness = option_item_sp(
param="OnroadScreenOffBrightness",
title=lambda: tr("Onroad Brightness"),
description="",
min_value=0,
max_value=90,
value_change_step=5,
label_callback=lambda value: f"{value} %" if value > 0 else tr("Screen Off"),
)
self._global_brightness = option_item_sp(
param="Brightness",
title=tr("Global Brightness"),
description=lambda: tr("Overrides the brightness of the device. This applies to both onroad and offroad screens."),
min_value=-5,
max_value=100,
value_change_step=5,
label_callback=lambda value: f"{value}" if value > 0 else tr("Auto") if value == 0 else tr("Auto(Dark)")
)
self._interactivity_timeout = option_item_sp(
param="InteractivityTimeout",
title=lambda: tr("Interactivity Timeout"),
description=lambda: tr("Apply a custom timeout for settings UI." +
"<br>This is the time after which settings UI closes automatically " +
"if user is not interacting with the screen."),
min_value=0,
max_value=120,
value_change_step=10,
label_callback=lambda value: (tr("Default") if not value or value == 0 else
f"{value} s" if value < 60 else f"{int(value/60)} m")
)
items = [
self._onroad_brightness_toggle,
self._onroad_brightness_timer,
self._onroad_brightness,
self._global_brightness,
self._interactivity_timeout,
]
return items
def _update_state(self):
super()._update_state()
self._onroad_brightness_timer.set_visible(self._onroad_brightness_toggle.action_item.get_state())
self._onroad_brightness.set_visible(self._onroad_brightness_toggle.action_item.get_state())
def _render(self, rect):
self._scroller.render(rect)