I have experimented with styling and attributes in Lemur.
I used a Springgridlayout to set 2 containers to a specific position.
That was working well.
Then I thought I would like to set that specific layout via style and attribute.
I have used the following code:
SpringGridLayout layoutasattribut = new SpringGridLayout(Axis.X,Axis.Y,FillMode.Even,FillMode.Even);
Container L1 = new Container();
L1.addChild(new Label("L1"));
Container L2 = new Container();
L2.addChild(new Label("L2"));
layoutasattribut.addChild(1,1,L1);
layoutasattribut.addChild(2,2,L2);
Attributes attr= styles.getSelector (new ElementId(Container.ELEMENT_ID),"Testlayout");
attr.set("layout",layoutasattribut);
Later in code I call the saved layout via
Container C1 = new Container(new ElementId(Container.ELEMENT_ID),"Testlayout");
but it is not showing the expected outcome. If I configure a container directly in
code like this
Container L3 = new Container(layoutasattribut);
GuiNode.attachChild(L3);
...
I can see the result shown above. It seems that the child containers, that are stored to the SpringGridLayout get lost during the application of the style.
In
com\simsilica\lemur\style\Styles.class, line 285
“value” contains the two children set via attribute
285 if (value != null) {
286 if (value instanceof GuiComponent) {
287 value = ((GuiComponent)value).clone();
but the .clone() function in line 287 that leads to
\com\simsilica\lemur\component\SpringGridLayout.class, line 68
is loosing the children.
67 public SpringGridLayout clone() {
68 SpringGridLayout result = new SpringGridLayout(this.mainAxis, this.minorAxis, this.mainFill, this.minorFill);
69 return result;
}
If I understood the code in SpringGridLayout.class this is intended.
My question(s) are:
How is it possible to store a layout with children as an style?
Is it usefull to do this or may it be better to do the setting in code when the
Gui is actually painted?