Skip to content

Conversation

TheSecurityDev
Copy link
Contributor

@TheSecurityDev TheSecurityDev commented Oct 10, 2025

Refactors the HTML Renderer for the following improvements:

  1. Inline font weight styles (bold); italics and others could be implemented rather easily
  2. Replaced ugly regular expressions with proper HTML parser class
  3. Caching of wrapping/height calculations

The macOS test is failing but I don't understand why 🤔

Example:
image

Show HTML
<h2>Here is a heading</h2>
 Here is some <b>bold text</b> and some even longer text that <b>wraps around to the next line</b> and some plain text after.
This is a new line
This is a new line with line break<br>
<b>After</b> line break
<p>Paragraph <b>with bold</b></p>
<h2><b>bold</b> in heading</h2>
<ul>
<li>List item 1</li>
<li>List item <b>with bold</b></li>
<ul>
<li>Nested list item</li>
Some text in nested list
</ul>
</ul>
<p><b>Double <b>bold</b> text</b> example</p>

@Copilot Copilot AI review requested due to automatic review settings October 10, 2025 06:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors the HTML renderer for openpilot's UI system to support inline styling (bold and italics) and improves performance through caching and proper HTML parsing.

  • Replaces regex-based parsing with a proper HTMLParser class for better HTML processing
  • Adds support for italic fonts alongside existing bold support
  • Implements caching for text wrapping and height calculations to improve rendering performance

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

File Description
system/ui/widgets/html_render.py Complete refactor of HTML parsing logic and rendering with inline styling support
system/ui/lib/application.py Extended font loading system to support italic variants
selfdrive/assets/fonts/*.ttf Updated Inter font files to version 4.1 and added italic variants

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@TheSecurityDev
Copy link
Contributor Author

How do I fix the LFS errors :(

@TheSecurityDev TheSecurityDev mentioned this pull request Oct 10, 2025
47 tasks
@github-actions github-actions bot added the ui label Oct 10, 2025
@TheSecurityDev
Copy link
Contributor Author

I reverted the italic fonts since it seems I can't upload them due to LFS permissions. It will fallback to regular font until they are added.

Copy link
Contributor

github-actions bot commented Oct 10, 2025

raylib UI Preview

software_release_notes : $${\color{cyan}\text{NEW}}$$
All Screenshots

@TheSecurityDev TheSecurityDev marked this pull request as draft October 10, 2025 07:05
@sshane
Copy link
Contributor

sshane commented Oct 10, 2025

this seems very large. can we start by just supporting inline <b> first?

fyi I tried cursor + gpt5 to do this but it was terrible, I suspect you need to do it yourself to get anything mergable

@sshane
Copy link
Contributor

sshane commented Oct 10, 2025

styles all seem broken for lists now

@TheSecurityDev
Copy link
Contributor Author

TheSecurityDev commented Oct 10, 2025

styles all seem broken for lists now

Yes, it might be related to the size calculation and the cache. Because it works perfectly fine in the toggle description. It seems to break for the update notes. It was much simpler actually

I'll take a proper look today.

@TheSecurityDev
Copy link
Contributor Author

TheSecurityDev commented Oct 10, 2025

this seems very large. can we start by just supporting inline <b> first?

I can try to split it out into a separate PR. To make italics work you need the font and I couldn't add it due to lfs permission issues. Btw, it also supports bold + italics. The idea was that adding other inline styling is not that hard with this new way.

fyi I tried cursor + gpt5 to do this but it was terrible, I suspect you need to do it yourself to get anything mergable

This was like the third attempt, but the trick was to prompt it more to start from scratch instead of refactoring the old code. I wanted to get rid of the regex parsing too, which I think was a bottleneck for adding the inline styles. Previous attempts worked for bold, but I wanted a system that could scale to things like italics or underlines, and this approach looked promising. I saw your attempt, which seemed more complex that my previous ones and it inspired me to try again 😅

I did some more prompts to fix some bugs and stuff, but I did have to do a lot of manual cleanup in the end.

@TheSecurityDev TheSecurityDev marked this pull request as ready for review October 10, 2025 20:36
@TheSecurityDev
Copy link
Contributor Author

styles all seem broken for lists now

@sshane The issue was that the whitespace between tags was being rendered. Also fixed rendering new lines to support just plain text with new lines.

I don't know how to fix the macOS build; I don't think I did anything to break that. Removing italics won't make it that much smaller, but I can still do that if you want.

@TheSecurityDev TheSecurityDev changed the title raylib: better HTML renderer to handle bold and italics raylib: better HTML renderer to handle inline styles Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants