slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.53k stars 600 forks source link

Renderer still visit elements with zero opacity #6056

Open mgejke opened 2 months ago

mgejke commented 2 months ago

Rust on Windows 11.

Using the code below to be able to fade Spinner in and out based on busy, CPU usage is high when busy is false.

Spinner {
        indeterminate: true;
        opacity: busy ? 1.0 : 0.0;
        animate opacity { duration: 0.25s; }
    }

The following doesnt affect CPU usage when busy is false.

Spinner {
        indeterminate: true;
        visible: busy;
    }

I would expect Widgets that have opacity = 0 to not be drawn and not affect performance. Also, maxing out a CPU core to display a Spinner seems a bit overkill.

ogoffart commented 2 months ago

Thanks for filling an issue.

The workaround here is to do visible: opacity > 0; I wonder if there should be an optimization in the renderer for this to not visit elements that have a 0 opacity.

mgejke commented 2 months ago

Why didn't I think of that. 🤦‍♂️ Thanks!

NigelBreslaw commented 2 months ago

Items that are zero opacity will still have a width and height though? So say it's a grid, setting visible false will free up a space. While opacity zero correctly keeps that grid space full. But showing nothing.

ogoffart commented 2 months ago

@NigelBreslaw Yes. but we shouldn't query so much the children elements properties that are only used for rendering.