Iced: How would you tackle a 'table view'?

Created on 3 Jul 2020  路  2Comments  路  Source: hecrj/iced

First of all, good job on this crate. It's very impressive. I am still dipping my toes in Rust, and currently working on a simple MacOS/Windows application which should display a list of items in a 'table view'-like component. Think of it like:

image

I am reaching out because I am a little unsure what you would do in a situation like this. Is it best to go ahead an use a combination of Row with a Scrollable? I don't think dequeuing will be required since I wouldn't have a that big (< 100) list. However small details such as the header titles would be awesome.

Do you have any suggestion how I could tackle this? I looked at #189 which looked like something i could use maybe.
Thanks a lot.

feature question

Most helpful comment

It's hard to say how I would tie everything together without actually working actively on it. In any case, here are some initial thoughts:

  • My first approach would consist in building a custom Table widget to layout contents based on column widths and reuse the Scrollable event logic.
  • There would be some table::State which would only hold the scrollable::State, column widths, and the current active column ordering.
  • I would try to keep table data and column definition completely decoupled from the table::State. The data and the columns would be provided in the view logic. Therefore, the widget logic should assume they could change at any time.
  • It would be great to define columns as a name and a first-class "mapper" (i.e. a function &T -> String or a trait). Then, the input of the table could be a simple iterator of &T values (Iterator<Item = &T>). The widget would deal with mapping an &T to a String for each column, sort accordingly, and finally present the data.
  • The logic that would handle the resize of columns by dragging should be very similar to the resizing logic of the PaneGrid widget (see #397).
  • elm-sortable-table is a nice Elm package that implements sortable tables and I believe we could draw some inspiration from it.

Hope that helps!

All 2 comments

It's hard to say how I would tie everything together without actually working actively on it. In any case, here are some initial thoughts:

  • My first approach would consist in building a custom Table widget to layout contents based on column widths and reuse the Scrollable event logic.
  • There would be some table::State which would only hold the scrollable::State, column widths, and the current active column ordering.
  • I would try to keep table data and column definition completely decoupled from the table::State. The data and the columns would be provided in the view logic. Therefore, the widget logic should assume they could change at any time.
  • It would be great to define columns as a name and a first-class "mapper" (i.e. a function &T -> String or a trait). Then, the input of the table could be a simple iterator of &T values (Iterator<Item = &T>). The widget would deal with mapping an &T to a String for each column, sort accordingly, and finally present the data.
  • The logic that would handle the resize of columns by dragging should be very similar to the resizing logic of the PaneGrid widget (see #397).
  • elm-sortable-table is a nice Elm package that implements sortable tables and I believe we could draw some inspiration from it.

Hope that helps!

Thank you @hecrj. This was exactly the response I was looking for.
Again, good job on this project. Amazing work.

Closing this issue down for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Charles-Schleich picture Charles-Schleich  路  3Comments

kszlim picture kszlim  路  4Comments

michael-hart picture michael-hart  路  4Comments

hecrj picture hecrj  路  3Comments

aentity picture aentity  路  4Comments