ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀
https://ratatui.rs
MIT License
8.82k stars 263 forks source link

feat(widgets): Rename `StatefulWidget::render` to `render_stateful` #1183

Open joshka opened 2 weeks ago

joshka commented 2 weeks ago

This change renames the StatefulWidget::render method to render_stateful to avoid conflicts with the Widget::render method.

Often both the Widget and StatefulWidget traits are in scope, and when calling the render method on a StatefulWidget the compiler cannot determine which trait to use. This change resolves that issue by renaming the StatefulWidget::render method to render_stateful.

The StatefulWidget::render method is still available, but it is deprecated. A default implementation of render_stateful is provided that calls the deprecated render method.

Callers should update their code to use render_stateful instead of render. implementors of the StatefulWidget trait should update their implementations to implement render_stateful instead of render, and provide an implementation of render that calls render_stateful.

This change is non-breaking. The deprecated render method will be removed in a future release of Ratatui (likely 0.29.0).

Addresses part of a problem raised in https://github.com/ratatui-org/ratatui/issues/996

codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 78.94737% with 8 lines in your changes missing coverage. Please review.

Project coverage is 94.2%. Comparing base (4bfdc15) to head (5c66a94). Report is 7 commits behind head on main.

Files Patch % Lines
src/widgets/list.rs 71.4% 4 Missing :warning:
src/widgets/table/table.rs 75.0% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1183 +/- ## ======================================= - Coverage 94.3% 94.2% -0.1% ======================================= Files 60 60 Lines 14679 14710 +31 ======================================= + Hits 13843 13862 +19 - Misses 836 848 +12 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

joshka commented 2 weeks ago

Similar to the other PR, I think we could do render_with_state() instead, but I'm fine with render_stateful(). Again, worth checking in with other maintainers for a second opinion.

likewise - I'm 55/45 on stateful vs with_state here too.

joshka commented 2 weeks ago

Holding for resolution of discussion at https://forum.ratatui.rs/t/naming-render-traits-methods/68