As the nodes are just Actor
s, you could place you node content (the labels and sliders) first in some container like Table
or Container
and give the actual content a bit of margin in that wrapper container.
After you explanation about what you want to achieve the above won't work as you want to move the plus and minus buttons that are used to expand and collapse the Tree
's Tree.Node
s.
I don't think the Scene2D Tree
implementation will allow you to set the indentation level to be anything other than the max of the width of the plus and the minus Drawable
s.
But there are always ways around that. The bad news is that the field you need to alter is a private field so simply inheriting Tree
won't allow you to fix it, but if you're willing to get a bit dirty you can achieve what you're looking for using some reflection.
Instead of doing something like this
Tree tree = new Tree(skin);
// Add nodes to tree here
You could do this;
// First create an instance of Tree where the setStyle method is overridden
tree = new Tree(skin) {
@Override
public void setStyle(TreeStyle style) {
super.setStyle(style);
// After having called the base class's setStyle,
// use horrible reflection to find and alter the indentSpacing field.
try {
Field field = Tree.class.getDeclaredField("indentSpacing");
field.setAccessible(true);
field.set(this, 8); // This is how much you want each plus and minus indented.
// Normally this is set to something like
// Math.max(style.plus.getMinWidth(), style.minus.getMinWidth())
System.out.println(field);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
};
// You will likely want to play around with this to make sure the node
// content is not rendered too close to the plus/minus
tree.setIconSpacing(4, 4);
// Add tree nodes here!
This is obviously not ideal, but will likely be easier than creating a new version of Tree
and get the pull request accepted. Only good thing about this approach is that it involves almost no typing for you.
Alternatively you can just copy the Tree
code and change it accordingly.