openpilot
openpilot copied to clipboard
system/ui: add Icon widget and SVG support
Widget to draw images and SVGs
Raylib doesn't have native support for SVGs (it uses stbi which can import PNGs, JPGs...).
This adds cairosvg which renders SVGs, outputting a PNG image which we can upload to raylib
Split out from #35140
Haven't tested this on device yet...
How about managing icons directly in GuiApplication? There’s already a method, load_texture_from_image, which handles loading textures from files and releasing them on app exit. We could modify it to use a hash-based cache for textures and add support for SVG files.
For example:
def texture(self, file_name, width, height, ...):
key = f"{file_name}{width}{height}"
if key not in self._textures:
self._load_texture_from_file(...)
...
return self._textures[key]
This approach removes the need for a separate member variable in init to load textures and reference it in the render() function. Instead, we can directly call gui_app.texture(...) at render time to retrieve cached textures. It also avoids the overhead of dynamically scaling icons on every render by managing the correct dimensions during caching.
what do you think about this approach?
@deanlee That looks good, let's do that. We can figure out the SVG support afterwards.
@incognitojam submitted https://github.com/commaai/openpilot/pull/35222 for review