So, for anyone else coming to this thread trying to do this I had to make a change:
private static void setupButton(AssetManager assetManager, Styles styles, String id, String background, String pressed, String hover) {
QuadBackgroundComponent backgroundTx = new QuadBackgroundComponent(assetManager.loadTexture(background));
QuadBackgroundComponent pressedTx = new QuadBackgroundComponent(assetManager.loadTexture(pressed));
QuadBackgroundComponent hoverTx = new QuadBackgroundComponent(assetManager.loadTexture(hover));
Attributes attrs = styles.getSelector(Button.ELEMENT_ID, id);
attrs.set("background", backgroundTx);
attrs.set("insets", new Insets3f(2, 2, 2, 2));
List<Command<Button>> command = Collections.singletonList((source) -> {
if( source.isPressed() ) {
source.setBackground(pressedTx.clone());
} else {
if( source.isHighlightOn()) {
source.setBackground(hoverTx.clone());
} else {
source.setBackground(backgroundTx.clone());
}
}
});
Map<Button.ButtonAction, List<Command<Button>>> commands = new EnumMap<>(Button.ButtonAction.class);
commands.put(Button.ButtonAction.Down, command);
commands.put(Button.ButtonAction.Up, command);
commands.put(Button.ButtonAction.HighlightOn, command);
commands.put(Button.ButtonAction.HighlightOff, command);
attrs.set("buttonCommands", commands);
}
If I don’t clone()
the QuadBackgroundComponent every time it vanishes after the first time it is displayed!
i.e. the button displays, then when I hover over it the hover displays, but then when I move off it the original never comes back and we end up with an empty space!