@pspeed
With the access to the slider’s sub-parts, the setBackground on the thumb button doesn’t appear to work. The increment button works fine, but not thumb. Maybe because it is simply added to the range node and not actually a Lemur child in the layout?
If I use styles to define the background of the thumb, it works fine.
Also, in the code below, I expected the DynamicInsetsComponent to center the slider, but it actually fills the entire width. Any idea why?
Code below is what I was using to test the thumb background and the slider width.
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Command;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.DefaultRangedValueModel;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.Slider;
import com.simsilica.lemur.component.BorderLayout;
import com.simsilica.lemur.component.DynamicInsetsComponent;
import com.simsilica.lemur.component.IconComponent;
import com.simsilica.lemur.component.TbtQuadBackgroundComponent;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SliderTest extends SimpleApplication {
private static final Logger logger = Logger.getLogger(SliderTest.class.getName());
public static void main(String[] args) {
SliderTest app = new SliderTest();
app.start();
}
@Override
public void simpleInitApp() {
GuiGlobals.initialize(this);
Container mainContainer = new Container(new BorderLayout());
mainContainer.setLocalTranslation(0f, settings.getHeight(), 0f);
mainContainer.setPreferredSize(
new Vector3f(settings.getWidth(), settings.getHeight(), 0f));
getGuiNode().attachChild(mainContainer);
float sliderBackgroundWidth = (float)(settings.getWidth()) / 2f;
float sliderBackgroundHeight = (float)(settings.getHeight()) / 10f;
Slider slider = new Slider(new DefaultRangedValueModel(-10, 10, 0), Axis.X);
slider.setPreferredSize(
new Vector3f(sliderBackgroundWidth, sliderBackgroundHeight, 0f));
slider.setInsetsComponent(new DynamicInsetsComponent(0.5f, 0.5f, 0.5f, 0.5f));
slider.setBackground(
TbtQuadBackgroundComponent.create(
"Interface/SliderBackground.png", 1f,
10, 20, 246, 10,
0f, false));
slider.getThumbButton().setText("");
slider.getThumbButton().setBackground(
new IconComponent("Interface/SliderPosition.png"));
slider.getIncrementButton().setText("");
slider.getIncrementButton().setBackground(
new IconComponent("Interface/SliderPosition.png"));
slider.getThumbButton().addCommands(Button.ButtonAction.Down, new Command() {
public void execute(Object source) {
logger.log(Level.INFO, "spinSlider Button Down");
}
});
slider.getThumbButton().addCommands(Button.ButtonAction.Up, new Command() {
public void execute(Object source) {
logger.log(Level.INFO, "spinSlider Button Up");
}
});
mainContainer.addChild(slider, BorderLayout.Position.South);
}
}
[/java]