-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement table row selection and hover highlighting (#3347)
* Based on #3105 by @vvv. ## Additions and Changes - Add `TableBuilder::sense()` and `StripBuilder::sense()` to enable detecting clicks or drags on table and strip cells. - Add `TableRow::select()` which takes a boolean that sets the highlight state for all cells added after a call to it. This allows highlighting an entire row or specific cells. - Add `TableRow::response()` which returns the union of the `Response` of all cells added to the row up to that point. This makes it easy to detect interactions with an entire row. See below for an alternative design. - Add `TableRow::index()` and `TableRow::col_index()` helpers. - Remove explicit `row_index` from callback passed to `TableBody::rows()` and `TableBody::heterogeneous_rows()`, possible due to the above. This is a breaking change but makes the callback compatible with `TableBody::row()`. - Update Table example to demonstrate all of the above. ## Design Decisions An alternative design to `TableRow::response()` would be to return the row response from `TableBody`s `row()`, `rows()` and `heterogeneous_rows()` functions. `row()` could just return the response. `rows()` and `heterogeneous_rows()` could return a tuple of the hovered row index and that rows response. I feel like this might be the cleaner soluction if only returning the hovered rows response isn't too limiting. I didn't implement `TableBuilder::select_rows()` as described [here](#3105 (comment)) because it requires an immutable borrow of the selection state for the lifetime of the `TableBuilder`. This makes updating the selection state from within the body unnecessarily complicated. Additionally the current design allows for selecting specific cells, though that could be possible by modifying `TableBuilder::select_rows()` to provide row and column indices like below. ```rust pub fn select_cells(is_selected: impl Fn(usize, usize) -> bool) -> Self ``` ## Hover Highlighting EDIT: Thanks to @samitbasu we now have hover highlighting too. ~This is not implemented yet. Ideally we'd have an api that allows to choose between highlighting the hovered cell, column or row. Should cells containing interactive widgets, be highlighted when hovering over the widget or only when hovering over the cell itself? I'd like to implement that before this gets merged though.~ Feedback is more than welcome. I'd be happy to make any changes necessary to get this merged. * Closes #1519 * Closes #1553 * Closes #3069 --------- Co-authored-by: Samit Basu <[email protected]> Co-authored-by: Emil Ernerfeldt <[email protected]>
- Loading branch information
1 parent
37762f7
commit 5a6d1cb
Showing
4 changed files
with
319 additions
and
109 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
Oops, something went wrong.