|
|
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 #15982 is a reply to message #15981] |
Wed, 21 May 2008 15:58 |
|
cbpporter wrote on Wed, 21 May 2008 09:48 |
Now I need to determine the current row & column. I found a GetCurrentRow (but no GetCurrentColumn), but the value which it returned seems to be off (and even constant in my case). There is also GetCursor, which returns (-1, -1)? And which is the event for cell change?
|
GetCursorPos return Point with currently pointed cell otherwise it returns Point(-1, -1). It should work. If not please give me some more information (calling context) or attach a test case.
Quote: |
And is there an easier way to do key/value stuff than using a Value and GridDisplay?
|
What you mean exactely? What do you want to achieve?
|
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15984 is a reply to message #15983] |
Wed, 21 May 2008 17:45 |
|
Quote: |
GetCursorPos worked. I just had to change event from WhenCursor to WhenChangeRow & WhenChangeCol. With WhenCursor it was always (-1,-1), even though this event triggered on cell change.
|
Starange, you should get correct values in WhenCursor. I'll try to check it.
Quote: |
Like in most other cases, I need to insert some data in the container widget, but I need it to display some text. From what I could tell from the interface of GridCtrl, is that you insert some arbitrary type converted to a Value, and write a custom Display to display a string while the control holds you values.
|
Ok, now I understand. One cell holds one Value object. If you want key/value pair conected with one cell you have to use some structure as Value. As for displaying. You have to extend GridDisplay class which contain some useful methods like SetLeft/Right/CenterImage.
You could also do somehting like this:
grd.AddIndex(); this column will hold keys (and it will be invisible)
grd.AddColumn(); this column will hold values
grd.AddIndex()
grd.AddColumn
In GridDisplay you can access via parent member neighbours' values. You can also read current position via col, row members.
Hope that will help you somehow
[Updated on: Wed, 21 May 2008 17:45] Report message to a moderator
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #15999 is a reply to message #15984] |
Thu, 22 May 2008 11:50 |
cbpporter
Messages: 1401 Registered: September 2007
|
Ultimate Contributor |
|
|
[quote title=unodgs wrote on Wed, 21 May 2008 18:45]Quote: |
Ok, now I understand. One cell holds one Value object. If you want key/value pair conected with one cell you have to use some structure as Value. As for displaying. You have to extend GridDisplay class which contain some useful methods like SetLeft/Right/CenterImage.
|
Yes, I know that. This was not a question of how, it was a question of principle. I was asking why isn't there and easier method of doing it. The scenario I described is a fairly common one IMO. It's great that you can use a Display and do really fancy stuff if you need it, but in most cases I just want to display a simple text extracted from the Value in exactly the same position and with same style as if I had inserted a string directly. In such cases, using Display is a little overkill, and witting them can be repetitive and tedious.
Let's take for example a Paint method from Dispaly:
virtual void Paint(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const
It has 6 parameters, and all have useful predefined values which you'll rarely ignore or change and go ahead and use them. A large portion of these displays consists of a simple w.DrawText and maybe some position calculation. Since U++ is in general good at detecting common idioms and offering some API, mechanism or clever trick for it, I was wondering why it doesn't offer something like that in this case. For example, something like:
struct MyDisplay: TextDisplay
{
virtual String Text(const Value &q) const;
}
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #16001 is a reply to message #15999] |
Thu, 22 May 2008 12:10 |
|
You can use converters. For example:
struct SexConv : Convert
{
Value Format(const Value& q) const
{
switch(int(q))
{
case SEX_MALE: return "Male";
case SEX_FEMALE: return "Female";
case SEX_CHILD: return "Child";
}
return Null;
}
};
grid.AddColumn("Key column").SetConvert(Single<SexConverter>());
grid.Add(SEX_MALE).Add(SEX_FEMALE);
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #16005 is a reply to message #16001] |
Thu, 22 May 2008 15:03 |
cbpporter
Messages: 1401 Registered: September 2007
|
Ultimate Contributor |
|
|
Great! I never though about using a Converter for this. And since String is ref counted (and my strings are also short), it should be fairly quick to extract a field from the value this way.
I've done some code clean-up and am very happy with the result. I do miss the ColumnList look a little, so I'm going to add an option to switch between a ColumnList output and a GridCtrl one, with grid being default .
I still have 2 questions not 100% related to GridCtrl:
1. I noticed that displaying a large number of CJK characters is pretty slow. I tried replacing all the CJK characters with English ones, and the control was blazing fast again, so I don't believe it's related to GridCtrl. I wonder if there is a native limitation in the drawing sped of these chars (they are quite a bit more complex that other ones), or is this related to U++. I remember Mirek saying once that after he fixed some bugs regarding the determination of the metrics for these chars, it became slow, so he had to speed it up.
2. Is there an Array like container, but which does not free the memory occupied by it's items? I'm using Vector<Foo *> right now.
|
|
|
|
|
|
|
|
|
|
|
Re: How to create a GridCtrl with fixed cell size [message #16337 is a reply to message #16205] |
Mon, 09 June 2008 10:08 |
|
cbpporter wrote on Mon, 02 June 2008 05:06 | A secondary issue appeared in cases when after a layout change which resulted in a scrollbar the user executed another one: the top row would not be updated on scroll.
So I decided to investigate GridCtrl and I found the solution to both problems. After calling Ready(false), a Clear(true) does not update the scrollbar information, so that computations done in layout still have the scrollbar size included, because of the way GetSize investigates the frame count to return the adjusted size.
So the issues can be solved by either swapping the order of the Ready and Clear call, or by calling UpdateScrollbars after the clear.
|
The problem is UpdateSb in Clear is called when grid is in ready state, but I think it can be called always - then you will get proper values in your Layout method. I will commit the change today to uvs.
|
|
|
Goto Forum:
Current Time: Wed May 15 04:15:41 CEST 2024
Total time taken to generate the page: 0.03515 seconds
|
|
|