preiter93 / tui-widget-list

A widget list implementation for the ratatui ecosystem
MIT License
18 stars 5 forks source link

Feature request: Implementing ratatui::style::Styled for List. #17

Closed airblast-dev closed 2 months ago

airblast-dev commented 2 months ago

Currently the List widget provides a style method that takes in a style. This can often result in boiler plate code when a user wants to only set a single field since they would have to use the From<_> to construct Style on every List::style call.

Simplest approach is to make List::style take a generic such as Into<Style> and just call Into::into when assigning. This would move any from/into calls in the method.

However even better, we could implement Styled which provides various ease of use methods related to styling, and would allow a user to make a styling function that takes in a Styled that can be used on List. Since there is an existing style method this causes conflicts, and the user has to call the method via their fully qualified syntax (Self::style or Styled::style ). Which makes this a breaking change. Maybe List::style could be removed and replaced with Styled::set_style, along-side a major version change?

preiter93 commented 2 months ago

Thats a good point, thx. I am with you, implementing Styled sounds better, it stays closer to the ratatui std lib.

Feel free to open a PR! Otherwise I will do so in the next days

airblast-dev commented 2 months ago

Will do!

joshka commented 2 months ago

Hey, once you've implemented this, if you're keen to contribute back to Ratatui, this might make a good recipe for the Ratatui website. https://ratatui.rs/recipes/

preiter93 commented 2 months ago

@airblast-dev you mentioned in your PR Didn't need to remove List::style as ratatui seperates Styled, and Stylize traits which means only people who are implementing Styled and using the List::style method in the same module may be affected.

What exactly did you mean with that? Cause I dont see any breaking change from you changes. The orphan rule prevents that people implement Styled for List

airblast-dev commented 2 months ago

Yes you are correct. There shouldn't any breaking changes.

Didn't need to remove List::style as ratatui seperates Styled, and Stylize traits which means only people who are implementing Styled and using the List::style method in the same module may be affected.

If I remember correctly, I meant a conflict between Styled::style, and List::style if Styled was in scope. Though I just checked, and it isn't an issue so there shouldn't be any breaking changes.

preiter93 commented 2 months ago

published it as v0.10.1