-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(widget)!: render functions now accept references
In some situations, ratatui's render functions can make it difficult to implement specific behavior or can make it difficult and inefficient to reuse widgets. E.g. for a list, you have to clone either the vec or it's items again each frame to make the new list object. Another example is rendering a widget in a loop, where you have to clone the widget each time. This commit makes it so the `Widget`/`StatefulWidget``::render` functions only take `self` by immutable reference, meaning they're not consumed and can be reused. The `Frame::render_{,stateful_}widget` functions take `widget` by value though. To allow these functions to be called with references or values, we added a new trait `AsWidgetRef` which is implemented for `&W` and `W` where `W: Widget`/`StatefulWidget. This trait is then used to call the `render` functions. Thus backwards compatibility is maintained for the `Frame` API. This also removes any calls to `take()` in the `render` functions since this cannot happen when the widget is passed by reference. BREAKING CHANGE: `Widget`/`StatefulWidget`'s `render` functions now take `self` by immutable reference instead of by value. To update your custom widgets simply add `&` before the `self` parameter in the `render` function. src/widgets/block.rs # modified: src/widgets/canvas/mod.rs # modified: src/widgets/chart.rs # modified: src/widgets/clear.rs # modified: src/widgets/gauge.rs # modified: src/widgets/list.rs # modified: src/widgets/mod.rs # modified: src/widgets/paragraph.rs src/widgets/table.rs # modified: src/widgets/tabs.rs #
- Loading branch information
1 parent
358b50b
commit 907bf3e
Showing
15 changed files
with
267 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.