|
|
Home » Community » Newbie corner » Help needed to program an array ctrl.
Help needed to program an array ctrl. [message #28337] |
Sun, 29 August 2010 18:34 |
281264
Messages: 270 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
Hi,
I need some help in programming an array control. The objective is:
1.- to manage a list of objects; each object is actually a struct called Layer. Each layer has the following variables:
a) A String for its name;
b) A bool for determining whether the layer is on/off;
c) A bool for determining whether the layer is current layer;
d) A bool for determining whether the layer is lock/unlock;
e) A Color for its colour.
2.- From the visual/functional point of view these are the requisites in the array control:
a) The String it is just an editor; no special feature;
b) Layer on/off: it has to be represented by an image of a bulb, which status on/off is depicted by the bulb with/without light. The selection of the bulb’s status is made by clicking on it.
c) Selection of current layer: I think that this should be a Switch ctrl. Evidently, only one layer can be the current.
d) lock/unlock: similar to b) but with a different image(s).
e) Colour: I have found that ColorPusher ctrl suits this feature well.
3.- All the layers will be stored in a Vector.
So, having said that, how to tackle the matter? I am requesting help for the array ctrl’s information in the manual is a bit confusing (at least to a newcomer like me). I would really appreciate some help/hints.
Many thanks,
Javier
|
|
|
Re: Help needed to program an array ctrl. [message #28454 is a reply to message #28337] |
Thu, 02 September 2010 13:02 |
|
Hi Javier,
Since no one more skilled answered yet, it looks like I will have to do it
1) I assume you already has the struct ready, it is really simple.
2) You should decide wheather you want to use the ArrayCtrl just for displaying the state of Layers, or if you actually want to use it to modify them as well. I guess it is more user friendly to have the actual controls in the ArrayCtrl, similar to e.g. Layers dialog in photoshop.
a,e) This is simple, just have a look to reference/ArrayCtrl*
b,d) I would use a Button, changing image in the WhenAction callback, possible also set same color as background and no frame, to make it look better.
c) I think you don't need separate switch, you can use the layer that is currently selected in ArrayCtrl as the active one.
3) You can choose many strategies... In some cases it is enough to have the informations in ArrayCtrl alone and access them when necessary. In other cases, especially when you need to pass the layers list somewhere etc., you have to either re-create (part of) the ArrayCtrl everytime the underlaying Vector<Layer> changes, or you can make a function that gathers all the values from ArrayCtrl and creates the Vector<Layer> which can be done worked with further. This depends a lot on your actual needs...
I will try to put together some basic code and post it up here for you later if I have some spare time...
Best regards,
Honza
|
|
|
|
Re: Help needed to program an array ctrl. [message #28465 is a reply to message #28458] |
Thu, 02 September 2010 16:44 |
|
I'm glad to hear you solved it already. I put together a little bit of code, so I post it here for your reference and for anyone else in the future. It is far from ideal, since I am not very familiar with ArrayCtrl and I also tried to keep it as simple as possible.
Best regards,
Honza
-
Attachment: layers.zip
(Size: 2.02KB, Downloaded 187 times)
|
|
|
|
Re: Help needed to program an array ctrl. [message #28473 is a reply to message #28467] |
Thu, 02 September 2010 21:48 |
|
Yes, I assumed that there is not too much layers, so it will be fast enough to recreate them all every time something changes.
As for your questions:
1) If I wanted to know which Ctrl changed, I would probably use external controls. Then you can assign a Callback1 to each which will pass the row number to the called function. Exactly as you did it in your code You just have a little bug there - if you delete some row, the following have messed up ids (layer_id!=row index). I would suggest you to add an index to the array (AddIndex("id") and store layer_id in it. So you can use that instead of the row number.
2) DUMPC is a debugging macro that dumps the content of container into the log file (Debug > View log file in theide). I put it there just to make sure the layers are updated correctly, there is no deeper meaning into that destructor. I also called it once in the constructor.
The most complicated thing about ArrayCtrl is that it supports a lot of different usage patterns. Actually it should be even able to work with external data source, but I never seen that and the help only says that it is awkward
Unfortunately I can't tell you what is the simplest solution to your problem, I simply don't know. Maybe someone else can give you better advice.
Thinking about it now, I found one more solution. You could create your own Ctrl, representing the whole layer (i.e. including all the Ctrls in a single widget). It would be a little bit more work to create it, but might save a lot of work on handling all the thing separately. But that is just my idea, I never did something like that.
Honza
|
|
|
Re: Help needed to program an array ctrl. [message #28474 is a reply to message #28473] |
Thu, 02 September 2010 22:09 |
281264
Messages: 270 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
Thank you for your advice.
As you are well guessing, the number of rows (layers) will be small, so your approach is correct as well.
Regarding the id of layers, it is made on purpose for this is a unique identifier, created at the time of any layer's creation and permanently “glued” to every layer; it never changes, regardless of the layers erased/created.
Unless I am mistake, IMO, there are no other ways to do this task. What surprises me is that, apparently, Ctrls has some limitations, although the concept is impeccable.
Cheers,
Javier.
|
|
|
Goto Forum:
Current Time: Fri Apr 19 00:53:57 CEST 2024
Total time taken to generate the page: 0.02375 seconds
|
|
|