Custom Tags for Custom Controls

Is it possible to add custom tags for a custom control I’m designing? It’s a simple toggle button with two states, and it would be really handy to have an active and inactive tag with the filename of the image to be displayed in each case. Something like this, for example:
See First Example

Trying this just gives an XML error as the XSD doesn’t allow those tags (obviously). I tried a work around like this:
See Second Example

But in my Controller for toggle-button, I can’t seem to find any reference to those elements.

Ok, bigger issue first. How can I get XML to be shown? It’s being stripped out, I assume, because it’s seen as HTML tags. Using the code button doesn’t work… :-?

At the moment you need to pastebin it and post a link.

Thanks zarch, I’ve updated my post with links to examples.

Anyone got any insight into whether this is possible?

I’m not sure off hand - I think it is though, Isn’t there something like param name=x value=y ?

@zarch said: I'm not sure off hand - I think it is though, Isn't there something like param name=x value=y ?

I tried to find any information on such a tag, but nothing seems to exist. If it’s not possible, do you know where I could suggest such a feature?

Why not just use them as attributes like this.

{control name=“toggle-button” id=“button1” activeImg=“active.png” inactiveImg=“inactive.png”}
{/control}

Then your controller for the toogle button can handle this and set the image of the element in your control definition.
The attributes can be retrieved in the bind-method of the controller via the properties.

[java] @Override
public void bind(final Nifty nifty, final Screen screen, final Element element, final Properties parameter, final Attributes controlDefinitionAttributes) {
String active = parameter.getProperty(“activeImg”);
String inactive = parameter.getProperty(“inactiveImg”);
}[/java]

1 Like
@baalze said: Why not just use them as attributes like this.

{control name=“toggle-button” id=“button1” activeImg=“active.png” inactiveImg=“inactive.png”}
{/control}

Then your controller for the toogle button can handle this and set the image of the element in your control definition.
The attributes can be retrieved in the bind-method of the controller via the properties.

[java] @Override
public void bind(final Nifty nifty, final Screen screen, final Element element, final Properties parameter, final Attributes controlDefinitionAttributes) {
String active = parameter.getProperty(“activeImg”);
String inactive = parameter.getProperty(“inactiveImg”);
}[/java]

I could definitely do that but there are a couple of things I don’t particularly like about that solution. For one, that doesn’t easily allow me to add other attributes for each image. If for example I wanted to also have text overlayed, I’d have to add attributes activeImgText and inactiveImgText. ImageMode resizing would also make it more complicated. Secondly, that tag already has a load of attributes, and it doesn’t feel like a very ‘XML’-y solution! :stuck_out_tongue_winking_eye:

Thanks for providing an alternative that works though :slight_smile: