-
Notifications
You must be signed in to change notification settings - Fork 703
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
Fixes #16 - Add columned lists to TableView (with ListTableSource) #2593
Conversation
…ned view Also adds MinCellWidth to TableView
Thanks for taking the time to continue exploring this idea. You can pass a I added the Let me know what you think of this idea. I am happy to help with it further if you would like me to elaborate on this pattern. We can make methods public on Something like: public class ListTableSource : ITableSource {
public IList List;
private TableView tableView;
/// <summary>
/// Creates a new table instance based on the data in <paramref name="list"/>.
/// </summary>
/// <param name="list"></param>
/// <param name="tableView"></param>
public ListTableSource (TableView tableView, IList list)
{
this.tableView = tableView;
this.List = list;
// TODO: I think this is what FlowTable method currently does
Columns = CalculateColumns();
Rows = (int)Math.Ceiling (list.Count / (float)Columns);
}
/// <inheritdoc/>
public object this [int row, int col]
{
get {
var idx = (row * Columns) + col;
if(idx >= List.Count) {
return null;
}
return List [idx];
}
}
/// <inheritdoc/>
public int Count => List.Count;
/// <inheritdoc/>
public int Rows { get; private set; }
/// <inheritdoc/>
public int Columns { get; private set; }
/// <inheritdoc/>
public string [] ColumnNames => Enumerable.Range (0, Columns).Select (n => n.ToString ()).ToArray();
[...]
} |
Thank you for your help. In my first try after #2576 and based on your comments, I tried to do away with the subclass and make as few changes to TableView as possible. Initially I was passing just the necessary aspects of the View (rather than the View itself) into ListTableSource's constructor. But I still needed to add the orientation styles (direction to populate values, and direction to scroll) to TableView, and more importantly there's the fact that some (but not all) changes to the table's style or other properties (e.g., the View bounds or MaxCellWidth) require a reflow. |
I think passing the whole
I think a valid approach to this problem would be to register an event? what do you think? For example: + ListColumnStyle style;
private TableView tableView;
/// <summary>
/// Creates a new table instance based on the data in <paramref name="list"/>.
/// </summary>
/// <param name="list"></param>
/// <param name="tableView"></param>
- public ListTableSource (TableView tableView, IList list)
+ public ListTableSource (TableView tableView, IList list, ListColumnStyle style)
{
this.tableView = tableView;
this.List = list;
+ this.style = style;
// TODO:
Columns = CalculateColumns;
Rows = (int)Math.Ceiling (list.Count / (float)Columns);
+ // TODO: Depending on exactly when this event is called
+ // it may be 'too late' (view may have already been drawn).
+ // Not sure what the exact best event to tap for this is but
+ // this is the general idea.
+ // And if there isn't a good event for it we can add one!
+ tableView.DrawContent += TableView_DrawContent;
}
+ private Rect lastBounds;
+ private int lastMaxCellWidth;
+ private void TableView_DrawContent (object sender, DrawEventArgs e)
+ {
+ if(
+ (!tableView.Bounds.Equals(lastBounds)) ||
+ tableView.MaxCellWidth != lastMaxCellWidth /* ||
+ TODO add other conditions here */) {
+ Columns = CalculateColumns ();
+ }
+ lastBounds = tableView.Bounds;
+ lastMaxCellWidth = tableView.MaxCellWidth;
+ } |
Closing this in favor of #2603 . |
Note this also duplicates PR #2591 .
Pull Request checklist:
CTRL-K-D
to automatically reformat your files before committing.dotnet test
before commit///
style comments)