Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions system/ui/lib/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def _close(sig, frame):
rl.set_target_fps(fps)

self._target_fps = fps
self._set_styles()
self._load_fonts()
self._patch_text_functions()
if BURN_IN_MODE and self._burn_in_shader is None:
Expand Down Expand Up @@ -523,13 +522,6 @@ def _load_fonts(self):
self._fonts[font_weight_file] = font
rl.gui_set_font(self._fonts[FontWeight.NORMAL])

def _set_styles(self):
rl.gui_set_style(rl.GuiControl.DEFAULT, rl.GuiControlProperty.BORDER_WIDTH, 0)
rl.gui_set_style(rl.GuiControl.DEFAULT, rl.GuiDefaultProperty.TEXT_SIZE, DEFAULT_TEXT_SIZE)
rl.gui_set_style(rl.GuiControl.DEFAULT, rl.GuiDefaultProperty.BACKGROUND_COLOR, rl.color_to_int(rl.BLACK))
rl.gui_set_style(rl.GuiControl.DEFAULT, rl.GuiControlProperty.TEXT_COLOR_NORMAL, rl.color_to_int(DEFAULT_TEXT_COLOR))
rl.gui_set_style(rl.GuiControl.DEFAULT, rl.GuiControlProperty.BASE_COLOR_NORMAL, rl.color_to_int(rl.Color(50, 50, 50, 255)))

def _patch_text_functions(self):
# Wrap pyray text APIs to apply a global text size scale so our px sizes match Qt
if not hasattr(rl, "_orig_draw_text_ex"):
Expand Down
18 changes: 0 additions & 18 deletions system/ui/lib/utils.py

This file was deleted.

6 changes: 4 additions & 2 deletions system/ui/mici_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.slider import SmallSlider
from openpilot.system.ui.widgets.button import SmallButton, FullRoundedButton
from openpilot.system.ui.widgets.label import gui_label, gui_text_box
from openpilot.system.ui.widgets.label import gui_label, UnifiedLabel

USERDATA = "/dev/disk/by-partlabel/userdata"
TIMEOUT = 3*60
Expand All @@ -37,6 +37,7 @@ def __init__(self, mode):
self._previous_reset_state = None
self._reset_state = ResetState.NONE

self._body_label = UnifiedLabel("", font_size=36, font_weight=FontWeight.ROMAN)
self._cancel_button = SmallButton("cancel")
self._cancel_button.set_click_callback(self._cancel_callback)

Expand Down Expand Up @@ -87,7 +88,8 @@ def _render(self, rect: rl.Rectangle):
color=rl.Color(255, 255, 255, int(255 * 0.9)))

text_rect = rl.Rectangle(rect.x + 8, rect.y + 56, rect.width - 8 * 2, rect.height - 80)
gui_text_box(text_rect, self._get_body_text(), 36, font_weight=FontWeight.ROMAN, line_scale=0.9)
self._body_label.set_text(self._get_body_text())
self._body_label.render(text_rect)

if self._reset_state != ResetState.RESETTING:
# fade out cancel button as slider is moved, set visible to prevent pressing invisible cancel
Expand Down
10 changes: 7 additions & 3 deletions system/ui/mici_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.lib.wifi_manager import WifiManager, Network
from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.label import gui_text_box, gui_label, UnifiedLabel
from openpilot.system.ui.widgets.label import gui_label, UnifiedLabel
from openpilot.system.ui.widgets.button import FullRoundedButton
from openpilot.system.ui.mici_setup import NetworkSetupPage, FailedPage, NetworkConnectivityMonitor

Expand Down Expand Up @@ -44,6 +44,8 @@ def __init__(self, updater_path, manifest_path):
self._network_monitor = NetworkConnectivityMonitor()
self._network_monitor.start()

self._progress_label = UnifiedLabel("", font_weight=FontWeight.DISPLAY, text_color=rl.Color(255, 255, 255, int(255 * 0.9)))

# Buttons
self._continue_button = FullRoundedButton("continue")
self._continue_button.set_click_callback(lambda: self.set_current_screen(Screen.WIFI))
Expand Down Expand Up @@ -147,8 +149,10 @@ def render_progress_screen(self, rect: rl.Rectangle):
font_size = 62
else:
font_size = 82
gui_text_box(title_rect, self.progress_text, font_size, font_weight=FontWeight.DISPLAY,
color=rl.Color(255, 255, 255, int(255 * 0.9)))

self._progress_label.set_font_size(font_size)
self._progress_label.set_text(self.progress_text)
self._progress_label.render(title_rect)

progress_value = f"{self.progress_value}%"
text_height = measure_text_cached(gui_app.font(FontWeight.ROMAN), progress_value, 128).y
Expand Down
6 changes: 4 additions & 2 deletions system/ui/tici_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from openpilot.system.ui.lib.application import gui_app, FontWeight, FONT_SCALE
from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.button import Button, ButtonStyle
from openpilot.system.ui.widgets.label import gui_label, gui_text_box
from openpilot.system.ui.widgets.label import gui_label, UnifiedLabel

USERDATA = "/dev/disk/by-partlabel/userdata"
TIMEOUT = 3*60
Expand All @@ -36,6 +36,7 @@ def __init__(self, mode):
self._mode = mode
self._previous_reset_state = None
self._reset_state = ResetState.NONE
self._content_label = UnifiedLabel("", font_size=90)
self._cancel_button = Button("Cancel", self._cancel_callback)
self._confirm_button = Button("Confirm", self._confirm, button_style=ButtonStyle.PRIMARY)
self._reboot_button = Button("Reboot", lambda: os.system("sudo reboot"))
Expand Down Expand Up @@ -74,7 +75,8 @@ def _render(self, rect: rl.Rectangle):
gui_label(label_rect, "System Reset", 100, font_weight=FontWeight.BOLD)

text_rect = rl.Rectangle(rect.x + 140, rect.y + 140, rect.width - 280, rect.height - 90 - 100 * FONT_SCALE)
gui_text_box(text_rect, self._get_body_text(), 90)
self._content_label.set_text(self._get_body_text())
self._content_label.render(text_rect)

button_height = 160
button_spacing = 50
Expand Down
7 changes: 5 additions & 2 deletions system/ui/tici_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from openpilot.system.ui.lib.wifi_manager import WifiManager
from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.button import Button, ButtonStyle
from openpilot.system.ui.widgets.label import gui_text_box, gui_label
from openpilot.system.ui.widgets.label import gui_label, UnifiedLabel
from openpilot.system.ui.widgets.network import WifiManagerUI

# Constants
Expand Down Expand Up @@ -45,6 +45,8 @@ def __init__(self, updater_path, manifest_path):
self.update_thread = None
self.wifi_manager_ui = WifiManagerUI(WifiManager())

self._desc_label = UnifiedLabel("", font_size=BODY_FONT_SIZE)

# Buttons
self._wifi_button = Button("Connect to Wi-Fi", click_callback=lambda: self.set_current_screen(Screen.WIFI))
self._install_button = Button("Install", click_callback=self.install_update, button_style=ButtonStyle.PRIMARY)
Expand Down Expand Up @@ -97,7 +99,8 @@ def render_prompt_screen(self, rect: rl.Rectangle):
"The download size is approximately 1GB.")

desc_rect = rl.Rectangle(MARGIN + 50, 250 + TITLE_FONT_SIZE * FONT_SCALE + 75, rect.width - MARGIN * 2 - 100, BODY_FONT_SIZE * FONT_SCALE * 4)
gui_text_box(desc_rect, desc_text, BODY_FONT_SIZE)
self._desc_label.set_text(desc_text)
self._desc_label.render(desc_rect)

# Buttons at the bottom
button_y = rect.height - MARGIN - BUTTON_HEIGHT
Expand Down
31 changes: 1 addition & 30 deletions system/ui/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from openpilot.system.ui.lib.application import gui_app, FontWeight, DEFAULT_TEXT_SIZE, DEFAULT_TEXT_COLOR, FONT_SCALE
from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.lib.utils import GuiStyleContext
from openpilot.system.ui.lib.emoji import find_emoji, emoji_tex
from openpilot.system.ui.lib.wrap_text import wrap_text

Expand Down Expand Up @@ -235,34 +234,6 @@ def gui_label(
rl.draw_text_ex(font, display_text, rl.Vector2(text_x, text_y), font_size, 0, color)


def gui_text_box(
rect: rl.Rectangle,
text: str,
font_size: int = DEFAULT_TEXT_SIZE,
color: rl.Color = DEFAULT_TEXT_COLOR,
alignment: int = rl.GuiTextAlignment.TEXT_ALIGN_LEFT,
alignment_vertical: int = rl.GuiTextAlignmentVertical.TEXT_ALIGN_TOP,
font_weight: FontWeight = FontWeight.NORMAL,
line_scale: float = 1.0,
):
styles = [
(rl.GuiControl.DEFAULT, rl.GuiControlProperty.TEXT_COLOR_NORMAL, rl.color_to_int(color)),
(rl.GuiControl.DEFAULT, rl.GuiDefaultProperty.TEXT_SIZE, round(font_size * FONT_SCALE)),
(rl.GuiControl.DEFAULT, rl.GuiDefaultProperty.TEXT_LINE_SPACING, round(font_size * FONT_SCALE * line_scale)),
(rl.GuiControl.DEFAULT, rl.GuiControlProperty.TEXT_ALIGNMENT, alignment),
(rl.GuiControl.DEFAULT, rl.GuiDefaultProperty.TEXT_ALIGNMENT_VERTICAL, alignment_vertical),
(rl.GuiControl.DEFAULT, rl.GuiDefaultProperty.TEXT_WRAP_MODE, rl.GuiTextWrapMode.TEXT_WRAP_WORD)
]
if font_weight != FontWeight.NORMAL:
rl.gui_set_font(gui_app.font(font_weight))

with GuiStyleContext(styles):
rl.gui_label(rect, text)

if font_weight != FontWeight.NORMAL:
rl.gui_set_font(gui_app.font(FontWeight.NORMAL))


# Non-interactive text area. Can render emojis and an optional specified icon.
class Label(Widget):
def __init__(self,
Expand Down Expand Up @@ -392,7 +363,7 @@ def _render(self, _):

class UnifiedLabel(Widget):
"""
Unified label widget that combines functionality from gui_label, gui_text_box, Label, and MiciLabel.
Unified label widget that combines functionality from gui_label, Label, and MiciLabel.

Supports:
- Emoji rendering
Expand Down
Loading