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(widgets::table): add option to always allocate the "selection" constraint #375

Merged
merged 5 commits into from
Aug 11, 2023

Conversation

hasezoey
Copy link
Contributor

@hasezoey hasezoey commented Aug 6, 2023

This PR adds a option for Table to always allocate the "selection column", regardless of if something is selected, this way there is less "moving around" of the layout.

The default is still false (only allocated if something is selected), but it can both be enabled or disabled in a builder function.

Note: also renamed some internal variables to better reflect on what they do / track

@hasezoey
Copy link
Contributor Author

hasezoey commented Aug 6, 2023

should i do a similar thing for List?

@hasezoey hasezoey force-pushed the tableAlwaysSelect branch from 909bd26 to 95e19d2 Compare August 6, 2023 14:45
@codecov
Copy link

codecov bot commented Aug 6, 2023

Codecov Report

Merging #375 (114d2b3) into main (3293c6b) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #375      +/-   ##
==========================================
+ Coverage   85.10%   85.11%   +0.01%     
==========================================
  Files          40       40              
  Lines        8727     8736       +9     
==========================================
+ Hits         7427     7436       +9     
  Misses       1300     1300              
Files Changed Coverage Δ
src/widgets/mod.rs 64.70% <ø> (ø)
src/widgets/table.rs 92.15% <100.00%> (+0.20%) ⬆️

src/widgets/table.rs Outdated Show resolved Hide resolved
src/widgets/table.rs Outdated Show resolved Hide resolved
tests/widgets_table.rs Outdated Show resolved Hide resolved
@joshka
Copy link
Member

joshka commented Aug 7, 2023

Also +1 to implementing this idea - this is otherwise pretty jarring.

src/widgets/table.rs Outdated Show resolved Hide resolved
src/widgets/table.rs Outdated Show resolved Hide resolved
@hasezoey
Copy link
Contributor Author

hasezoey commented Aug 7, 2023

i think i addressed all requests, is the current state OK?

PS: someone with write, could the "CI / coverage (pull_request)" workflow be re-run?

@joshka
Copy link
Member

joshka commented Aug 7, 2023

I'll wait on a second review on this one.

@a-kenji
Copy link
Contributor

a-kenji commented Aug 7, 2023

Thanks for implementing this, this has been a pet peeve of mine on other ratatui apps.

I am not sure if allocating is a fitting word here, it confused me initially.
I also think that this is a breaking change, since the interface of a public struct is changing.

Otherwise LGTM.

@joshka
Copy link
Member

joshka commented Aug 7, 2023

I also think that this is a breaking change, since the interface of a public struct is changing.

All the fields on Table are private, and the change just adds a new method, so I think this is probably in the mostly ok bucket (except for people doing "Strange Things"(TM)). What do you think?

@a-kenji
Copy link
Contributor

a-kenji commented Aug 7, 2023

You are right, I somehow thought the fields were public.
LGTM.

@hasezoey
Copy link
Contributor Author

hasezoey commented Aug 7, 2023

I am not sure if allocating is a fitting word here, it confused me initially.

any suggestions what to use instead?

@joshka
Copy link
Member

joshka commented Aug 7, 2023

any suggestions what to use instead?

How about something like:

feat(table): add option to reserve space for highlight symbol

with a commit body like:

Before this option was available, selecting an item when there was no item selected
previously made the table's layout change. This enables the table width to take up the
same amount of space whether there is a selection or not.

@hasezoey
Copy link
Contributor Author

hasezoey commented Aug 8, 2023

is the change in 146d791 enough or should something else be changed?

@joshka
Copy link
Member

joshka commented Aug 8, 2023

Sorry - I miscommunicated here a little. The suggested text in my previous comment was for the git commit history rather than the doc comments.

I suggest the docs should be written about the current implementation, and they don't need to cover history unless there's a strong likelihood of users needing to transition. Because this is new code, I'd avoid this.

The git commit is where we talk in terms of what the change was "This is how things changed".

Aside from that, the other comment changes are good.

If you can rebase and squash this with a new commit message that better explains the changes (rather than 8 commits), that would be great.

@hasezoey hasezoey force-pushed the tableAlwaysSelect branch from 146d791 to 621fc2f Compare August 8, 2023 10:59
@hasezoey
Copy link
Contributor Author

hasezoey commented Aug 8, 2023

rebased onto latest master, squashing commits that could / should be squashed, i think any further squashing would reduce clarity of the commits

also changed the initial commits messaging based on the feedback

src/widgets/table.rs Outdated Show resolved Hide resolved
src/widgets/table.rs Outdated Show resolved Hide resolved
src/widgets/table.rs Outdated Show resolved Hide resolved
src/widgets/table.rs Outdated Show resolved Hide resolved
src/widgets/table.rs Outdated Show resolved Hide resolved
src/widgets/table.rs Outdated Show resolved Hide resolved
@kdheepak
Copy link
Collaborator

Thanks for the PR! This is a feature that I've wanted for a while as well!

Copy link
Collaborator

@kdheepak kdheepak left a comment

Choose a reason for hiding this comment

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

I only have minor documentation related comments. The PR LGTM otherwise.

@hasezoey
Copy link
Contributor Author

just as a note, i have explicitly mentioned "row selection symbol" instead of just "selection symbol" for things like #376

@hasezoey
Copy link
Contributor Author

force-pushed to rebase onto latest master (which added Hash on Table) and to fix cargo fmt for the suggestions commit

@hasezoey
Copy link
Contributor Author

i will ask again, just to be sure:

should i do a similar change for List?

Copy link
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

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

All good, but let's use a commit message such as feat(table): ... before merge 🐻

hasezoey and others added 5 commits August 11, 2023 14:35
Before this option was available, selecting a row in the table when no row was selected
previously made the tables layout change (the same applies to unselecting) by adding the width
of the "highlight symbol" in the front of the first column, this option allows to configure this
behavior.
…_width instead of a boolean

also refactor "render" to make use of this change
@hasezoey
Copy link
Contributor Author

@orhun are the commits correct now? i personally use that style for my projects, to quickly note which subject (file) is meant, because there could be multiple things that have the same name in different paths (example in this project table as in widgets or as in example)

@joshka
Copy link
Member

joshka commented Aug 11, 2023

@orhun are the commits correct now? i personally use that style for my projects, to quickly note which subject (file) is meant, because there could be multiple things that have the same name in different paths (example in this project table as in widgets or as in example)

Keeping it broad is fine for this - it's mostly for the Changelog

@joshka joshka added this pull request to the merge queue Aug 11, 2023
Merged via the queue into ratatui:main with commit f63ac72 Aug 11, 2023
@hasezoey hasezoey deleted the tableAlwaysSelect branch August 11, 2023 14:17
@joshka
Copy link
Member

joshka commented Aug 11, 2023

should i do a similar change for List?

Yes please. Thanks for this change.

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.

5 participants