Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive Rendering #2662

Merged
merged 28 commits into from
Nov 13, 2024
Merged

Reactive Rendering #2662

merged 28 commits into from
Nov 13, 2024

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Nov 4, 2024

This PR changes the runtime to only perform a redraw of the user interface when either an update occurs, or a widget explicitly requests it.

Currently, iced renders all the time unconditionally on every runtime event. Effectively, this means that when you move your mouse around in an iced application, the runtime can easily draw hundreds of identical frames—wasting plenty of resources.

The changes here make both the runtime and the built-in widgets aware of their last status when drawn, and only request a redraw when needed. This should normally translate to a lower CPU and (specially) GPU usage when interacting with most applications.

As a consequence, the Widget and Overlay contract now require implementors to explicitly request redraws when necessary. Most of the time, this entails some kind of "diffing" during event processing to figure out if the widget state has changed.

This new feature is enabled by default but, since it makes widget implementation more difficult and may not make sense for highly dynamic applications, a user can opt out by enabling the unconditional-rendering feature; which restores the old behavior.

Related important breaking changes include:

  • Widget::on_event does not return an event::Status anymore. Instead, a widget can capture an event by calling Shell::capture_event. Since widget logic is generally quite imperative, this paradigm fits better and is also more consistent with other shell-related logic.
  • Widget::on_event has been renamed to update.
  • Program both for canvas and shader now return a widget::Action, which can be leveraged to either publish a message or request a redraw, and also event capturing.
  • Custom Event types for canvas and shader have been removed. They now simply use the foundational core::Event type.

... and fix the redraw queue logic in `iced_winit`.
If we do not request it, macOS does not get any
`RedrawRequested` events. Shouldn't `winit`
[take care of this]? Probably a bug.

[take care of this]: https://docs.rs/winit/0.30.5/winit/event/enum.WindowEvent.html#variant.RedrawRequested
@hecrj hecrj merged commit a11fcf8 into master Nov 13, 2024
30 checks passed
@hecrj hecrj deleted the reactive-rendering branch November 13, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant