pull/36244/head
Shane Smiskol 6 days ago
parent 21273c921e
commit 70b9ec889c
  1. 10
      selfdrive/ui/widgets/offroad_alerts.py
  2. 7
      system/ui/widgets/html_render.py

@ -10,6 +10,7 @@ from openpilot.system.ui.lib.scroll_panel import GuiScrollPanel
from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.lib.text_measure import measure_text_cached
from openpilot.system.ui.lib.wrap_text import wrap_text from openpilot.system.ui.lib.wrap_text import wrap_text
from openpilot.system.ui.widgets import Widget from openpilot.system.ui.widgets import Widget
from openpilot.system.ui.widgets.html_render import HtmlRenderer
from openpilot.selfdrive.selfdrived.alertmanager import OFFROAD_ALERTS from openpilot.selfdrive.selfdrived.alertmanager import OFFROAD_ALERTS
@ -306,6 +307,7 @@ class UpdateAlert(AbstractAlert):
self.release_notes = "" self.release_notes = ""
self._wrapped_release_notes = "" self._wrapped_release_notes = ""
self._cached_content_height: float = 0.0 self._cached_content_height: float = 0.0
self._html_renderer: HtmlRenderer | None = None
def refresh(self) -> bool: def refresh(self) -> bool:
update_available: bool = self.params.get_bool("UpdateAvailable") update_available: bool = self.params.get_bool("UpdateAvailable")
@ -327,6 +329,14 @@ class UpdateAlert(AbstractAlert):
return self._cached_content_height return self._cached_content_height
def _render_content(self, content_rect: rl.Rectangle): def _render_content(self, content_rect: rl.Rectangle):
self.release_notes = "<h1>These are epic release notes</h1>\n\n- Feature 1\n- Feature 2\n- Bug fixes and improvements\n- Make epic"
html = HtmlRenderer(text=self.release_notes)
html.render(rl.Rectangle(content_rect.x + 30, content_rect.y + 30, content_rect.width - 60, content_rect.height - 60))
return
if self.release_notes: if self.release_notes:
rl.draw_text_ex( rl.draw_text_ex(
gui_app.font(FontWeight.NORMAL), gui_app.font(FontWeight.NORMAL),

@ -34,7 +34,7 @@ class HtmlElement:
class HtmlRenderer(Widget): class HtmlRenderer(Widget):
def __init__(self, file_path: str): def __init__(self, file_path: str | None = None, text: str | None = None):
super().__init__() super().__init__()
self.elements: list[HtmlElement] = [] self.elements: list[HtmlElement] = []
self._normal_font = gui_app.font(FontWeight.NORMAL) self._normal_font = gui_app.font(FontWeight.NORMAL)
@ -53,7 +53,12 @@ class HtmlRenderer(Widget):
ElementType.BR: {"size": 0, "weight": FontWeight.NORMAL, "color": rl.BLACK, "margin_top": 0, "margin_bottom": 12}, ElementType.BR: {"size": 0, "weight": FontWeight.NORMAL, "color": rl.BLACK, "margin_top": 0, "margin_bottom": 12},
} }
if file_path is not None:
self.parse_html_file(file_path) self.parse_html_file(file_path)
elif text is not None:
self.parse_html_content(text)
else:
raise ValueError("Either file_path or text must be provided")
def parse_html_file(self, file_path: str) -> None: def parse_html_file(self, file_path: str) -> None:
with open(file_path, encoding='utf-8') as file: with open(file_path, encoding='utf-8') as file:

Loading…
Cancel
Save