use of com.badlogic.gdx.scenes.scene2d.utils.Selection in project talos by rockbite.
the class DynamicItemListWidget method getSubWidget.
@Override
public Actor getSubWidget() {
Table table = new Table();
Skin skin = TalosMain.Instance().getSkin();
Table topBar = new Table();
topBar.setBackground(ColorLibrary.obtainBackground(getSkin(), ColorLibrary.BackgroundColor.DARK_GRAY));
SquareButton newBtn = new SquareButton(skin, skin.getDrawable("timeline-btn-icon-new"));
SquareButton deleteBtn = new SquareButton(skin, skin.getDrawable("timeline-btn-icon-delete"));
topBar.add().expandX();
topBar.add(newBtn).padRight(2);
topBar.add(deleteBtn).padRight(2);
list = new FilteredTree<>(skin, "modern");
list.draggable = true;
list.setItemListener(new FilteredTree.ItemListener() {
@Override
public void onNodeMove(FilteredTree.Node parentToMoveTo, FilteredTree.Node childThatHasMoved, int indexInParent, int indexOfPayloadInPayloadBefore) {
callValueChanged(makeDataArray());
}
@Override
public void delete(Array<FilteredTree.Node> nodes) {
deleteSelection();
}
});
table.add(list).growX();
table.row();
table.add(topBar).growX().padLeft(-10).padRight(-10);
newBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
ItemData newItemData = new ItemData(defaultItemName, defaultItemName);
Selection<FilteredTree.Node<Object>> selection = list.getSelection();
FilteredTree.Node node;
if (selection.size() > 0) {
int index = 0;
Array<FilteredTree.Node<Object>> rootNodes = list.getRootNodes();
for (index = 0; index < rootNodes.size; index++) {
if (rootNodes.get(index) == selection.first()) {
break;
}
}
node = addNode(newItemData, index + 1);
} else {
node = addNode(newItemData);
}
callValueChanged(makeDataArray());
EditableLabel label = (EditableLabel) node.getActor();
label.setEditMode();
}
});
deleteBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
deleteSelection();
}
});
return table;
}
Aggregations