I’ve been trying to reload a lemur style. I’ve tried many workarounds but I can’t find any way. What I got so far is (for a desired panel):
Styles styles = GuiGlobals.getInstance().getStyles();
//styles.clearCache();
new StyleLoader().loadStyle(styleFile.toString(), new FileReader(styleFile));
styles.applyStyles(container, container.getElementId(), container.getStyle());
if(styles.getAttributes(container.getElementId(), container.getStyle()).get("layout")
== null) {
container.setLayout(layout);
} else {
// Patch because of the layout children aren't updated correctly
for(Node node : layout.getChildren()) {
container.getLayout().addChild(node);
}
}
However, it doesn’t matter how I try to patch/workaround the re-styling, I can’t achieve it.
I wanted to make an style auto-updater so I could change the style file and have the changes shown in real-time (As far as I know, it would have the limitation of that all code-made styling wouldn’t work, but is something I can afford) but I’m not sure this is currently possible with Lemur or not. If so, any help to have the styling reload well-done is welcome ;).
A simple test-case to try it:
public class TestLemurReloadStyles extends SimpleApplication {
Container container;
Panel inPanel;
float time;
public static void main(String[] args) {
new TestLemurReloadStyles().start();
}
public void simpleInitApp() {
// Lemur Gui setup
GuiGlobals.initialize(stateManager.getApplication());
BaseStyles.loadGlassStyle();
GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
container = new Container(new SpringGridLayout(Axis.Y, Axis.X, FillMode.None, FillMode.None));
inPanel = container.addChild(new Panel());
inPanel.setPreferredSize(new Vector3f(50, 50, 1));
container.setPreferredSize(new Vector3f(100, 100, 1));
container.setLocalTranslation(300, 300, 0);
guiNode.attachChild(container);
}
@Override
public void simpleUpdate(float tpf) {
super.simpleUpdate(tpf);
time += tpf;
if(time > 3) {
System.out.println("Reloading styles");
GuiLayout layout = container.getLayout();
GuiGlobals.getInstance().getStyles().applyStyles(container, container.getElementId(), container.getStyle());
GuiGlobals.getInstance().getStyles().applyStyles(inPanel, inPanel.getElementId(), inPanel.getStyle());
if(GuiGlobals.getInstance().getStyles().getAttributes(container.getElementId(), container.getStyle()).get("layout") == null) {
container.setLayout(layout);
} else {
//Patch because of the layout children aren't updated correctly
for(Node node : layout.getChildren()) {
container.getLayout().addChild(node);
}
}
inPanel.setPreferredSize(new Vector3f(50, 50, 1));
time = 0;
}
}
}