Search in sources :

Example 16 with MenuItem

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;
}
Also used : MenuItem(com.kotcrab.vis.ui.widget.MenuItem)

Example 17 with MenuItem

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();
                }
            });
        }
    });
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Actor(com.badlogic.gdx.scenes.scene2d.Actor) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 18 with MenuItem

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;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Actor(com.badlogic.gdx.scenes.scene2d.Actor) FileTypeFilter(com.kotcrab.vis.ui.widget.file.FileTypeFilter) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 19 with MenuItem

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);
}
Also used : Color(com.badlogic.gdx.graphics.Color) MenuItem(com.kotcrab.vis.ui.widget.MenuItem) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) EditableLabel(com.talosvfx.talos.editor.widgets.ui.EditableLabel) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Vector2(com.badlogic.gdx.math.Vector2) Actor(com.badlogic.gdx.scenes.scene2d.Actor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) PopupMenu(com.kotcrab.vis.ui.widget.PopupMenu)

Example 20 with MenuItem

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;
}
Also used : MenuItem(com.kotcrab.vis.ui.widget.MenuItem)

Aggregations

MenuItem (com.kotcrab.vis.ui.widget.MenuItem)29 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)12 PopupMenu (com.kotcrab.vis.ui.widget.PopupMenu)12 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)11 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Menu (com.kotcrab.vis.ui.widget.Menu)5 Vector2 (com.badlogic.gdx.math.Vector2)4 Array (com.badlogic.gdx.utils.Array)4 MenuItemListener (games.rednblack.editor.event.MenuItemListener)4 H2DPopupMenu (games.rednblack.h2d.common.view.ui.widget.H2DPopupMenu)4 Color (com.badlogic.gdx.graphics.Color)3 ColorPickerAdapter (com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)3 Rectangle (com.badlogic.gdx.math.Rectangle)2 XmlReader (com.badlogic.gdx.utils.XmlReader)2 InputValidator (com.kotcrab.vis.ui.util.InputValidator)2 InputDialogListener (com.kotcrab.vis.ui.util.dialog.InputDialogListener)2 EditableLabel (com.talosvfx.talos.editor.widgets.ui.EditableLabel)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1