-
Notifications
You must be signed in to change notification settings - Fork 700
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 #2573
Conversation
…ned view Also adds MinCellWidth to TableVIew
Though ListColumnView uses a lot from TableView, such that it would be highly duplicative to parent directly to View, there's a fair bit that doesn't apply as well, such that I imagine it would be confusing to use in practice. Should I perhaps create a new parent GridView that they can both share? |
I love the idea of supporting I can see that your approach is viable where you are subclassing and converting to
The user would be free to write their own too e.g. interface ITableDataSource
{
int Rows { get; }
int Columns { get; }
string[] ColumnNames { get; }
object this[int row, int col]
{
get;
}
} This will be breaking but we are working on v2 I think we should consider it as its a nice feature and it is quite a common use case (to use arbitrary objects as the table data items). That is the approach taken in TermKit and looks like it will make
https://github.com/migueldeicaza/TermKit/blob/main/Sources/TermKit/Views/DataTable.swift The GoalThe more I look at it, the more I'm excited about the idea. Check this out! How cool would it be for an API user to be able to do something like: var s = new EnumerableTableDataSource<Process>(Process.GetProcesses(),
new()
{
{ "Name",(p)=>p.ProcessName},
{ "Id",(p)=>p.Id},
{ "HasExited",(p)=>p.HasExited},
});
myTableView.Table = s; The class EnumerableTableDataSource<T> : ITableDataSource
{
private T[] data;
private string[] cols;
private Dictionary<string, Func<T, object>> lamdas;
public EnumerableTableDataSource(IEnumerable<T> data, Dictionary<string, Func<T,object>> columnDefinitions)
{
this.data = data.ToArray();
this.cols = columnDefinitions.Keys.ToArray();
this.lamdas = columnDefinitions;
}
public object this[int row, int col]
{
get => this.lamdas[ColumnNames[col]](this.data[row]);
}
public int Rows => data.Length;
public int Columns => cols.Length;
public string[] ColumnNames => cols;
} |
Love! |
I do have another branch where I first used TableView directly (though in my quick solution Table and ListData could be separately assigned to--your idea makes better sense). However, there are public methods and fields that make sense in only one or the other use case. From the point of view of a TableView, the few that I added certainly, but from the point of view of a ListColumnView, it no longer makes sense to have headers or FullRowSelect or TableSelection or otherwise treat any particular row or column differently from another. Maybe that's OK, but it bears some thought. |
Ok I'll pull my refactoring idea above out into a separate issue.
Ah yes I see. Your view is almost like a Layout. You could imagine that a View layout grid could be used to do something like this? Currently we don't have 'flow' , 'stack' or 'grid' style layouts.
So for example it would be very difficult to modify I've not really got a point here just adding some background I guess. |
That's right, though leveraging TableView's scalability is still important to the use case I'm attempting here. I'm imagining this could be used, for instance, to make the FileDialog have an alternate "list view" layout (rather than the "detail view" used currently), using limited screen real estate more effectively when you're only concerned with looking through a large number of filenames.
My idea wasn't to add a GridView in the sense of hosting Views within given cells, though that would certainly be cool.
Yes, an ability to "word wrap" would be interesting... however, you'd have to add horizontal cell lines, which cuts the opposite way in terms of best using screen real estate. On the other hand, I suppose you could use underlines and/or something like the throughline header I added to #2574 ... or alternating colors? In any case, that's also beyond what I was attempting here. |
I think that still makes sense for this PR, I'm just questioning what should reside within TableView or a new parent. |
It is shockingly eerie that just yesterday I was thinking about a "wrap" layout mode. I was looking at the "ColorPocker" code and thinking I wanted it to support arbitrary rows/cols. "this could all be just a list of radio buttons with no text; it'd be nice of we had a 'word wrap these Views' mode". |
@tig : This is not fixed. This was about generating an automatic layout based on the viewport size rather than just being able to use a list to create a one-dimensional table. Obviously it needed to change as a result of #2576 , but since an implementation of ITableSource doesn't have any information about the view, I still have to either add methods to TableView or create a child class in addition to adding a ListTableSource. FWIW, I'll open a new PR [ #2593 ] that incorporates @tznind 's changes, and you can decide what to do with it. |
Got it. I was confused. |
Add ListColumnView (child of TableView), displays an IList in a columned view
As I mentioned in #2514 , I wanted to make it easier to flexibly create multi-column lists. This is what I put together. I still need to add Unit Tests and re-add sorting to the Scenario, but I wanted to see if this solution makes sense to you guys.
Pull Request checklist:
CTRL-K-D
to automatically reformat your files before committing.dotnet test
before commit///
style comments)