Best way to change controls contextually (desktop)

I have an application that supports a few different types of data that will be written to different elements in an XML file. That data changes, depending on what the element type is. For example: If you are editing a “Timecode” element, where the content of the text is generated by another application, the only thing you can change are text display attributes: size, color, background color, transparency. But if you’re editing a Custom Text element, you can do all of those plus there’s a text field to edit the text. For another, you would select an image from the filesystem, and you can adjust the scale of the image.

These controls appear on one side of my application, and that cluster of controls needs to change dynamically depending on what kind of object you’ve selected to edit.

So my question is: what’s the best way to set this up?

My initial thought was to put each individual control and its label inside a container. Then in another container I’d group the controls needed. I would have 3-4 containers that consist of the correct grouping of individual controls, and these would be grouped within yet another container, where I could turn the groupings on or off.

Here, the collapsed containers (such as cTextHeight) each contain one or two control elements and a label: like a slider and a text box to show the slider value, or a button to open a color picker. The expanded containers (cCustomTextSettings and cGeneratedTextSettings) hold groupings of the collapsed containers.

MainWindowTextContainer holds the two (for now, there will be more) grouped control containers, cCustomTextSettings and cGeneratedTextSettings, and would be embedded in the main window. I would then show or hide cCustomTextSettings or cGeneratedTextSettings as needed.

Just wondering if there’s a better way to do this or if this is over complicating things.

The way I have done this is to make a textfield suclass that has a bunch of flags that indicate what kind of characters to allow, or what kind of processing is implied. Then all the magic happens in KeyDown, which is quite long.

1 Like

I’m not sure I understand how this addresses the issue I’m dealing with. Can you elaborate?

I need to change the displayed set of controls in two situations:

  1. User selects a new type of object to add to a canvas, from a pulldown menu. The controls update to reflect the attributes that can be edited for that object.

  2. User clicks on an existing object in a canvas, which displays that object’s attributes in the controls, so they can be modified as needed.

You could use a PagePanel and just lay out the controls you want visible on each page. I tend to use ContainerControls for each page. Then you just switch which page is visible depending on the option’s needs.

3 Likes

I haven’t used page panels - I’ll take a look at that. Is it presented like tabs (with visible tab labels), or are they “stacked” in the same position and you don’t know (as an end user) that there are other panels? That’s the main thing: I just want it to seamlessly change without showing what’s going on under the hood

Right, like a tab panel without tabs, which can only change what is shown through code. One set of controls per “panel”, only one shown at a time.

1 Like

Whoa - that is cool. Thanks.

I just dropped the existing containers into separate panels, and it only took 5 minutes to get it up and running.

It allows you to have a control on the window whose attributes can be changed on the fly. One minute it’s a date input, the next it’s a dollar amount, the next it’s just text.