openpilot icon indicating copy to clipboard operation
openpilot copied to clipboard

system/ui: add Icon widget and SVG support

Open incognitojam opened this issue 6 months ago • 1 comments

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

image

Split out from #35140

incognitojam avatar May 12 '25 20:05 incognitojam

Haven't tested this on device yet...

incognitojam avatar May 12 '25 21:05 incognitojam

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 avatar May 13 '25 16:05 deanlee

@deanlee That looks good, let's do that. We can figure out the SVG support afterwards.

incognitojam avatar May 14 '25 13:05 incognitojam

@incognitojam submitted https://github.com/commaai/openpilot/pull/35222 for review

deanlee avatar May 14 '25 14:05 deanlee