Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
281264 is currently offline  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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Javier,

Since no one more skilled answered yet, it looks like I will have to do it Smile

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 #28458 is a reply to message #28454] Thu, 02 September 2010 15:44 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Honza,

Thank you. I have already solved the matter. I have used SetCtrl to embed the external controls in the ArrayCtrl. Perhaps this can be done in other fashion but with Ctrls it becomes difficult to me (for example I do not know what control has been clicked/modified/etc.).

Anyhow, many thanks.

Cheers,

Javier


Re: Help needed to program an array ctrl. [message #28465 is a reply to message #28458] Thu, 02 September 2010 16:44 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 #28467 is a reply to message #28465] Thu, 02 September 2010 17:44 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Your example is quite fine.

I have some queries regarding Ctrls:

1.- for example, how do you know what control has been updated?. To me that is a kind of an enigma. From your example, after an event on a ctrl, all the rows are read and written to l.

2.- What is DUMP(1)?;what is its role in the destructor?

I am enclosing what I have done. I am afraid that there are much better ways to do it (basically I dismissed Ctrls and opted for SetCtrl; I have created several Arrays of controls and then I have to update all the Arrays every time a layer is added or removed: it looks convoluted; am I overcomplicating this?).

So, the question lingers: if you want to fine control the array’s content (i.e. to modify the content of a cell after a click or execute some code after and in accordance with the click’s outcome) is it possible to do it with Ctrls and/or widgetfactories?.

Cheers,

Javier

Re: Help needed to program an array ctrl. [message #28473 is a reply to message #28467] Thu, 02 September 2010 21:48 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Wink 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")Wink 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 Smile

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 Go to previous message
281264 is currently offline  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.
Previous Topic: Several options: what to use?
Next Topic: Problems in growing up from newbie
Goto Forum:
  


Current Time: Fri Apr 19 00:53:57 CEST 2024

Total time taken to generate the page: 0.02375 seconds