-
Notifications
You must be signed in to change notification settings - Fork 321
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
docs(examples): refactor demo2 #836
Conversation
Includes #833 |
7ad8482
to
3ac6d52
Compare
Changed this to the |
Many widgets can be rendered without changing their state. This commit implements The `Widget` trait for various references to widgets and changes their implementations to be immutable. This allows us to render widgets without consuming them by passing a ref to the widget when calling `Frame::render_widget()`. ```rust // this might be stored in a struct let paragraph = Paragraph::new("Hello world!"); let [left, right] = area.split(&Layout::horizontal([20, 20])); frame.render_widget(¶graph, left); frame.render_widget(¶graph, right); // we can reuse the widget ``` - Clear - Block - Tabs - Sparkline - Paragraph - Gauge - Calendar Other widgets will be implemented in follow up commits. Fixes: #164 Replaces PRs: #122 and #16 Enables: #132 Validated as a viable working solution by: #836
09c2846
to
d750b02
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments, otherwise looks good
Many widgets can be rendered without changing their state. This commit implements The `Widget` trait for various references to widgets and changes their implementations to be immutable. This allows us to render widgets without consuming them by passing a ref to the widget when calling `Frame::render_widget()`. ```rust // this might be stored in a struct let paragraph = Paragraph::new("Hello world!"); let [left, right] = area.split(&Layout::horizontal([20, 20])); frame.render_widget(¶graph, left); frame.render_widget(¶graph, right); // we can reuse the widget ``` - Clear - Block - Tabs - Sparkline - Paragraph - Gauge - Calendar Other widgets will be implemented in follow up commits. Fixes: #164 Replaces PRs: #122 and #16 Enables: #132 Validated as a viable working solution by: #836
Many widgets can be rendered without changing their state. This commit implements The `Widget` trait for references to widgets and changes their implementations to be immutable. This allows us to render widgets without consuming them by passing a ref to the widget when calling `Frame::render_widget()`. ```rust // this might be stored in a struct let paragraph = Paragraph::new("Hello world!"); let [left, right] = area.split(&Layout::horizontal([20, 20])); frame.render_widget(¶graph, left); frame.render_widget(¶graph, right); // we can reuse the widget ``` Implemented for all widgets except BarChart (which has an implementation that modifies the internal state and requires a rewrite to fix. Other widgets will be implemented in follow up commits. Fixes: #164 Replaces PRs: #122 and #16 Enables: #132 Validated as a viable working solution by: #836
Simplified a bunch of the logic in the demo2 example - Moved destroy mode to its own file. - Moved error handling to its own file. - Removed AppContext - Implemented Widget for &App. The app state is small enough that it doesn't matter here and we could just copy or clone the app state on every frame, but for larger apps this can be a significant performance improvement. - Made the tabs stateful - Made the term module just a collection of functions rather than a struct. - Changed to use color_eyre for error handling. - Changed keyboard shortcuts and rearranged the bottom bar. - Use strum for the tabs enum.
d750b02
to
077492a
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #836 +/- ##
=====================================
Coverage 92.3% 92.3%
=====================================
Files 61 61
Lines 16141 16096 -45
=====================================
- Hits 14903 14872 -31
+ Misses 1238 1224 -14 ☔ View full report in Codecov by Sentry. |
Simplified a bunch of the logic in the demo2 example
doesn't matter here and we could just copy or clone the app state on
every frame, but for larger apps this can be a significant performance
improvement.
struct.