use of com.kotcrab.vis.ui.widget.MenuItem in project vis-ui by kotcrab.
the class AbstractSuggestionPopup method createMenuItem.
protected MenuItem createMenuItem(String name) {
MenuItem item = new MenuItem(name);
item.getImageCell().size(0);
item.getShortcutCell().space(0).pad(0);
item.getSubMenuIconCell().size(0).space(0).pad(0);
return item;
}
use of com.kotcrab.vis.ui.widget.MenuItem in project vis-ui by kotcrab.
the class DirsSuggestionPopup method createDirSuggestions.
private void createDirSuggestions(final Stage stage, final float width) {
final String pathFieldText = pathField.getText();
// quiet period before listing files takes too long and popup will be removed
addAction(Actions.sequence(Actions.delay(0.2f, Actions.removeActor())));
if (listDirFuture != null)
listDirFuture.cancel(true);
listDirFuture = listDirExecutor.submit(new Runnable() {
@Override
public void run() {
FileHandle enteredDir = Gdx.files.absolute(pathFieldText);
final FileHandle listDir;
final String partialPath;
if (enteredDir.exists()) {
listDir = enteredDir;
partialPath = "";
} else {
listDir = enteredDir.parent();
partialPath = enteredDir.name();
}
final FileHandle[] files = listDir.list(chooser.getFileFilter());
if (Thread.currentThread().isInterrupted())
return;
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
clearChildren();
clearActions();
int suggestions = 0;
for (final FileHandle file : files) {
if (file.exists() == false || file.isDirectory() == false)
continue;
if (file.name().startsWith(partialPath) == false || file.name().equals(partialPath))
continue;
MenuItem item = createMenuItem(file.path());
item.getLabel().setEllipsis(true);
item.getLabelCell().width(width - 20);
addItem(item);
item.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
chooser.setDirectory(file, FileChooser.HistoryPolicy.ADD);
}
});
suggestions++;
if (suggestions == MAX_SUGGESTIONS) {
break;
}
}
if (suggestions == 0) {
remove();
return;
}
showMenu(stage, pathField);
setWidth(width);
layout();
}
});
}
});
}
use of com.kotcrab.vis.ui.widget.MenuItem in project vis-ui by kotcrab.
the class FileSuggestionPopup method createSuggestions.
private int createSuggestions(Array<FileHandle> files, final VisTextField fileNameField) {
clearChildren();
int suggestions = 0;
for (final FileHandle file : files) {
if (file.name().startsWith(fileNameField.getText()) && file.name().equals(fileNameField.getText()) == false) {
MenuItem item = createMenuItem(getTrimmedName(file.name()));
item.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
chooser.highlightFiles(file);
}
});
addItem(item);
suggestions++;
}
if (suggestions == MAX_SUGGESTIONS) {
break;
}
}
if (// don't show matches when there are files that actually exist and matched previous search
chooser.getMode() == FileChooser.Mode.SAVE && suggestions == 0 && chooser.getActiveFileTypeFilterRule() != null && fileNameField.getText().matches(".*\\.")) {
FileTypeFilter.Rule rule = chooser.getActiveFileTypeFilterRule();
for (String extension : rule.getExtensions()) {
MenuItem item = createMenuItem(fileNameField.getText() + extension);
final String arbitraryPath = fileNameField.getText() + extension;
item.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
fileNameField.setText(arbitraryPath);
fileNameField.setCursorAtTextEnd();
}
});
addItem(item);
suggestions++;
}
}
return suggestions;
}
use of com.kotcrab.vis.ui.widget.MenuItem in project talos by rockbite.
the class NodeGroup method init.
public void init(Skin skin) {
this.skin = skin;
frameImage = new Image(skin.getDrawable("group_frame"));
frameImage.setColor(44 / 255f, 140 / 255f, 209 / 255f, 1f);
addActor(frameImage);
topHit = new Actor();
topHit.setTouchable(Touchable.enabled);
addActor(topHit);
title = new EditableLabel("GROUP NAME", skin);
addActor(title);
settings = new ImageButton(skin, "settings");
settings.setSize(25, 25);
addActor(settings);
settings.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
final Vector2 vec = new Vector2(Gdx.input.getX(), Gdx.input.getY());
(TalosMain.Instance().UIStage().getStage().getViewport()).unproject(vec);
settingsPopup.showMenu(TalosMain.Instance().UIStage().getStage(), vec.x, vec.y);
}
});
settingsPopup = new PopupMenu();
MenuItem changeColorMenuItem = new MenuItem("Change Color");
MenuItem ungroupMenuItem = new MenuItem("Ungroup");
settingsPopup.addItem(changeColorMenuItem);
settingsPopup.addItem(ungroupMenuItem);
changeColorMenuItem.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
TalosMain.Instance().UIStage().showColorPicker(new ColorPickerAdapter() {
@Override
public void changed(Color newColor) {
super.changed(newColor);
frameImage.setColor(newColor);
}
});
}
});
ungroupMenuItem.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
nodeBoard.removeGroup(NodeGroup.this);
}
});
topHit.addListener(new ClickListener() {
Vector2 tmp = new Vector2();
Vector2 pos = new Vector2();
Vector2 diff = new Vector2();
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
pos.set(x, y);
topHit.localToStageCoordinates(pos);
nodeBoard.setSelectedNodes(nodes);
return true;
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
tmp.set(x, y);
topHit.localToStageCoordinates(tmp);
diff.set(tmp).sub(pos);
moveGroupBy(diff.x, diff.y);
pos.set(tmp);
super.touchDragged(event, x, y, pointer);
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
event.cancel();
}
});
setTouchable(Touchable.childrenOnly);
frameImage.setTouchable(Touchable.disabled);
}
use of com.kotcrab.vis.ui.widget.MenuItem in project talos by rockbite.
the class ContextualMenu method addItem.
public MenuItem addItem(String text, ClickListener listener) {
MenuItem item = new MenuItem(text);
item.addListener(listener);
popupMenu.addItem(item);
return item;
}
Aggregations