|
|
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » How to create a GridCtrl with fixed cell size
|
|
Re: How to create a GridCtrl with fixed cell size [message #15939 is a reply to message #15938] |
Mon, 19 May 2008 12:32 |
cbpporter
Messages: 1401 Registered: September 2007
|
Ultimate Contributor |
|
|
mrjt wrote on Mon, 19 May 2008 13:23 | Do you mean something like a spreadsheet?
|
No, not like a spreadsheet. For example, if at first I have 5 columns, and after resize 6 could fit, then I need the control to add a column and the first row to display the first 6 items, not just the first 5 as before the resize (and the rest of the rows to pick up the change, and also shift their items). I call this a vertical list . Something like the way Toolbar expands and aligns items as you change the size of the window.
Anyway, I need to look into the difference between GridCtrl and ArrayCtrl. Believe it or not, I never needed anything else except ColumnList up until now.
|
|
|
|
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15949 is a reply to message #15938] |
Mon, 19 May 2008 17:23 |
|
Please change your code to:
grd.Ready(false);
grd. Clear(true);
for (int i = 0; i < w; i++)
grd.AddColumn("Test", 105);
grd.Ready(true);
Ready(false) tells grid to not refresh util ready flag will be set again. Normally for each addcolumn grid recalculated widths of columns.
|
|
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15952 is a reply to message #15947] |
Mon, 19 May 2008 18:09 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
It seems to me that what you need is very similar to ColumnList, with only 2 (main) differences:
- items drawn left to right (not top to bottom)
- number of columns determined dynamically based on item width
so my suggestion would to modify that.
I've attached my quick and dirty attempt (it works quite well though). Use like a ColumnList, but you'll have to set ItemWidth to get sensible results when using a Display (default width is 50).
-
Attachment: RowList.zip
(Size: 6.09KB, Downloaded 288 times)
[Updated on: Mon, 19 May 2008 18:09] Report message to a moderator
|
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15963 is a reply to message #15952] |
Tue, 20 May 2008 02:23 |
cbpporter
Messages: 1401 Registered: September 2007
|
Ultimate Contributor |
|
|
mrjt wrote on Mon, 19 May 2008 19:09 | It seems to me that what you need is very similar to ColumnList, with only 2 (main) differences:
- items drawn left to right (not top to bottom)
- number of columns determined dynamically based on item width
so my suggestion would to modify that.
I've attached my quick and dirty attempt (it works quite well though). Use like a ColumnList, but you'll have to set ItemWidth to get sensible results when using a Display (default width is 50).
|
Thank you very much for using your free time to try this. You are right: I do need something like a ColumnList: actually I was using that before, but I need another draw order. It seems that the way such a list with multiple columns is drawn is confusing for a lot of people, so I had to disable the multiple column option, leaving it to a default of one. But because of the waste of space, I find myself in this situation...
I'll definitely try out you code and probably merge it into ColumnList if possible, seeing as U++ lacks a traditional list control with an optional "icons" layout (like CListCtrl from MFC).
But before that, since I already started with GridCtrl, I have to clear up some issues first.
I used this pretty ugly code to get the control to look and behave as I want it. By using Add variants I could only get a static number of items on a row, so I had to use Set:
void KanjiFlash::PopulateGrid()
{
if (!curList)
return;
grdKanji.Clear();
Vector<Kanji *> &v = *curList;
int cx = 0, cy = 0;
int w = grdKanji.GetSize().cx / CellHeight;
int h = v.GetCount() / w;
if (v.GetCount() * 1.0 / w != h)
h++;
//section 1
//for (int i = 0 ; i < h; i++)
// grdKanji.AddRow("").AlignBottom().Height(CellHeight);
for (int i = 0; i < v.GetCount(); i++)
{
const Kanji& kanji = *v[i];
grdKanji.Set(cy, cx, kanji.Literal());
cx++;
if (cx >= w)
{
cx = 0;
cy++;
}
}
//section 2
//for (int i = 0 ; i < h; i++)
// grdKanji.GetRow(i).AlignBottom().Height(CellHeight);
}
void KanjiFlash::Layout()
{
int w = grdKanji.GetSize().cx / CellHeight;
grdKanji.Ready(false);
grdKanji.Clear(true);
for (int i = 0; i < w; i++)
grdKanji.AddColumn("", CellHeight);
grdKanji.Ready(true);
PopulateGrid();
}
This pretty much works, except some problems.
There are two sections of commented out code. I need to uncomment the first section If I want to adjust the look of each individual row. Here I get two problems:
1. The control doesn't seem to show the scrollbar correctly, and even if it shows it, sometimes the last row is scrolled only about to the middle. It seems that the Height statement is the culprit (CellHeight is 40 under my tests).
2. AlignBottom or any other align doesn't seem to work.
If I uncomment the second section (it doesn't mater if the first is commented or not), rows are drawn at incorrect positions, but react to mouse at correct coordinates.
Also on a side note, I couldn't find a GetRowCount, event though a GetColumnCount is present.
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15964 is a reply to message #15963] |
Tue, 20 May 2008 08:19 |
|
Quote: |
1. The control doesn't seem to show the scrollbar correctly, and even if it shows it, sometimes the last row is scrolled only about to the middle. It seems that the Height statement is the culprit (CellHeight is 40 under my tests).
2. AlignBottom or any other align doesn't seem to work.
If I uncomment the second section (it doesn't mater if the first is commented or not), rows are drawn at incorrect positions, but react to mouse at correct coordinates.
|
Ok, I'll check it (AlignBottom should work - maybe I broke sth..)
Quote: |
Also on a side note, I couldn't find a GetRowCount, event though a GetColumnCount is present.
|
simply use GetCount(). Maybe I'll add GetRowCount alias too.
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15965 is a reply to message #15964] |
Tue, 20 May 2008 09:07 |
|
Please do following corrections to your code:
in Layout()
for (int i = 0; i < w; i++)
grd.AddColumn("").AlignBottom();
and in PopulateGrid()
//section 1
for (int i = 0 ; i < h; i++)
grd.AddRow(1, CellHeight);
Now everything should work. Height() is a only sytnax sugar. It dosn't couse grid refresh, rows heights recaluclation. However it can be confusign. I'll think about it. Align* for particualr row doesn't work now. I'll fix that in the next release.
|
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15968 is a reply to message #15966] |
Tue, 20 May 2008 11:13 |
|
mrjt wrote on Tue, 20 May 2008 04:49 |
I have exactly the same issue, I hate the way ColumnList works. My main issues:
- Lack of key/value support (every other list-style control supports it, why not ColumnList?)
- Bizarre scrolling. A columnized list should scroll sideways to show new columns, not the vertically one item at a time. I think this is the one that really confuses people.
- Difficult selection determination
|
I like scrolling in column list. It dosn't scroll columns but items in visible columns. This is a very good solution for long list (at least for me). You can adjust columns count by changing the width of just one column (I mean here it's easy to make more items visible without resizing the widget). Of course similar possibility could be implemented in classical approach.
What you need is arrayctrl/gridctrl which adjust columns count automaticaly for given list count. It can be easily done. However grid/array ctrl are heavy controls. I would suggest creating a new control (RowList e.g).
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15971 is a reply to message #15966] |
Tue, 20 May 2008 14:18 |
cbpporter
Messages: 1401 Registered: September 2007
|
Ultimate Contributor |
|
|
Well I don't like the scrolling but I definitely appreciate how useful it is for list of a lot of items and I've gotten used to it. But if the user is unable to scroll and desperately tries to find an item on a different column only after a small scroll, that's a problem. Anyway, I'm OK with it in general, and in this case I'll use grid.
mrjt wrote on Tue, 20 May 2008 11:49 |
I would be surprised you could do this, the changes are too widespread and complete to be integrated as an addition feature without adding considerable bloat and complexity.
|
I did some diff's and the bloat wouldn't be that great, but the complexity would define telly take a hard hit. ColumnList is nice and light weight, and since it is called ColumnList, maybe it's not the best idea to merge the two? Then how about some testing, debugging if necessary, and maybe adding key/value support and including it in Bazaar?
I have one last question regarding GridCtrl: what does Item::Clickable do? It does not seem to do what I imagined. And can I set a cell so that it is not clickable/selectable. I need this only for tail cells.
|
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15973 is a reply to message #15971] |
Tue, 20 May 2008 15:33 |
|
Quote: | I have one last question regarding GridCtrl: what does Item::Clickable do? It does not seem to do what I imagined. And can I set a cell so that it is not clickable/selectable. I need this only for tail cells.
|
Clicakble means cell is clickable or not, i.e cell can or can't be selected. Could you post here your whole package so I could test it?
|
|
|
Goto Forum:
Current Time: Sat Jun 08 09:43:22 CEST 2024
Total time taken to generate the page: 0.01368 seconds
|
|
|