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

feat: accept Color and Modifier for all Styles #720

Merged
merged 3 commits into from
Dec 31, 2023
Merged

feat: accept Color and Modifier for all Styles #720

merged 3 commits into from
Dec 31, 2023

Conversation

joshka
Copy link
Member

@joshka joshka commented Dec 29, 2023

All style related methods now accept S: Into<Style> instead of
Style.
Color and Modifier implement Into<Style> so this is allows for
more ergonomic usage. E.g.:

Line::styled("hello", Style::new().red());
Line::styled("world", Style::new().bold());

// can now be simplified to

Line::styled("hello", Color::Red);
Line::styled("world", Modifier::BOLD);

Fixes #694

BREAKING CHANGE: All style related methods now accept S: Into<Style>
instead of Style. This means that if you are already passing an
ambiguous type that implements Into<Style> you will need to remove
the .into() call.

Blocks with styles can no longer be created in a const context as
traits do not yet support const functions.

Copy link

codecov bot commented Dec 29, 2023

Codecov Report

Attention: 19 lines in your changes are missing coverage. Please review.

Comparison is base (a62632a) 92.1% compared to head (cf22ae8) 92.1%.

Files Patch % Lines
src/widgets/scrollbar.rs 0.0% 10 Missing ⚠️
src/widgets/calendar.rs 60.0% 6 Missing ⚠️
src/style.rs 97.0% 3 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main    #720    +/-   ##
======================================
  Coverage   92.1%   92.1%            
======================================
  Files         48      48            
  Lines      14367   14511   +144     
======================================
+ Hits       13238   13378   +140     
- Misses      1129    1133     +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joshka joshka marked this pull request as ready for review December 29, 2023 10:14
@joshka
Copy link
Member Author

joshka commented Dec 29, 2023

PR Notes: this is a large-ish PR, but it's repetitive.

It does have me wishing that we could macro up the setters though to remove the duplication.

All style related methods now accept `S: Into<Style>` instead of
`Style`.
`Color` and `Modifier` implement `Into<Style>` so this is allows for
more ergonomic usage. E.g.:

```rust
Line::styled("hello", Style::new().red());
Line::styled("world", Style::new().bold());

// can now be simplified to

Line::styled("hello", Color::Red);
Line::styled("world", Modifier::BOLD);
```

Fixes #694

BREAKING CHANGE: All style related methods now accept `S: Into<Style>`
instead of `Style`. This means that if you are already passing an
ambiguous type that implements `Into<Style>` you will need to remove
the `.into()` call.

`Block` style methods can no longer be called from a const context as
trait functions cannot (yet) be const.
Adds conversions for various Color and Modifier combinations
@joshka
Copy link
Member Author

joshka commented Dec 30, 2023

Rebased on #721 to fix conflicts with the buffer module refactor.

@joshka
Copy link
Member Author

joshka commented Dec 30, 2023

Fixed PR lint

Copy link
Member

@Valentin271 Valentin271 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a few interrogations. From impl should simplify common usage imo, I'm wondering if some of them here are not too ambiguous.

src/style.rs Show resolved Hide resolved
src/style.rs Show resolved Hide resolved
src/widgets/block.rs Show resolved Hide resolved
@joshka joshka merged commit 8f56fab into main Dec 31, 2023
33 checks passed
@joshka joshka deleted the into-style branch December 31, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

impl From Modifier and Color for Style
2 participants