Search in sources :

Example 1 with ValueEndChangeEvent

use of com.ray3k.stripe.RangeSlider.ValueEndChangeEvent in project skin-composer by raeleus.

the class TextAreaListeners method textAreaSelectionListener.

public static EventListener textAreaSelectionListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simTextArea = (DialogSceneComposerModel.SimTextArea) simActor;
    var popTableClickListener = new PopTableClickListener(skin) {

        {
            getPopTable().key(Keys.ESCAPE, popTable::hide);
        }

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            update();
        }

        public void update() {
            var popTable = getPopTable();
            popTable.clearChildren();
            var table = new Table();
            popTable.add(table);
            var positionLabel = new Label("Cursor Position: (" + simTextArea.cursorPosition + ")", skin, "scene-label-colored");
            table.add(positionLabel);
            table.row();
            var slider = new Slider(0, simTextArea.text == null ? 0 : simTextArea.text.length(), 1, false, skin, "scene");
            slider.setValue(simTextArea.cursorPosition);
            table.add(slider).minWidth(200);
            slider.addListener(handListener);
            slider.addListener(new TextTooltip("The cursor position when the TextArea has keyboard focus.", tooltipManager, skin, "scene"));
            slider.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.textAreaCursorPosition(MathUtils.round(slider.getValue()));
                    positionLabel.setText("Cursor Position: (" + simTextArea.cursorPosition + ")");
                }
            });
            table.row();
            var selectionLabel = new Label("Selection: (" + simTextArea.selectionStart + ", " + simTextArea.selectionEnd + ")", skin, "scene-label-colored");
            table.add(selectionLabel);
            table.row();
            var rangeSlider = new RangeSlider(skin, "scene");
            rangeSlider.setMinimum(0);
            rangeSlider.setMaximum(simTextArea.text == null ? 0 : simTextArea.text.length());
            rangeSlider.setIncrement(1);
            rangeSlider.setValueBegin(simTextArea.selectionStart);
            rangeSlider.setValueEnd(simTextArea.selectionEnd);
            rangeSlider.setDisabled(simTextArea.selectAll);
            table.add(rangeSlider).minWidth(200);
            rangeSlider.getKnobBegin().addListener(handListener);
            rangeSlider.getKnobEnd().addListener(handListener);
            rangeSlider.addListener(new TextTooltip("The text range to be selected if this TextArea has keyboard focus.", tooltipManager, skin, "scene"));
            rangeSlider.addListener(new ValueBeginChangeListener() {

                @Override
                public void changed(ValueBeginChangeEvent event, float value, Actor actor) {
                    events.textAreaSelectionStart(MathUtils.round(value));
                }
            });
            rangeSlider.addListener(new ValueEndChangeListener() {

                @Override
                public void changed(ValueEndChangeEvent event, float value, Actor actor) {
                    events.textAreaSelectionEnd(MathUtils.round(value));
                }
            });
            rangeSlider.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    selectionLabel.setText("Selection: (" + simTextArea.selectionStart + ", " + simTextArea.selectionEnd + ")");
                }
            });
            table.row();
            var label = new Label("Select All: ", skin, "scene-label-colored");
            table.add(label);
            table.row();
            var textButton = new TextButton(simTextArea.selectAll ? "TRUE" : "FALSE", skin, "scene-small");
            textButton.setChecked(simTextArea.selectAll);
            table.add(textButton).minWidth(100);
            textButton.addListener(handListener);
            textButton.addListener(new TextTooltip("Convenience option to select all text.", tooltipManager, skin, "scene"));
            textButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    textButton.setText(textButton.isChecked() ? "TRUE" : "FALSE");
                    events.textAreaSelectAll(textButton.isChecked());
                    rangeSlider.setDisabled(textButton.isChecked());
                }
            });
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : ValueEndChangeEvent(com.ray3k.stripe.RangeSlider.ValueEndChangeEvent) StyleSelectorPopTable(com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable) RangeSlider(com.ray3k.stripe.RangeSlider) RangeSlider(com.ray3k.stripe.RangeSlider) ValueEndChangeListener(com.ray3k.stripe.RangeSlider.ValueEndChangeListener) ValueBeginChangeEvent(com.ray3k.stripe.RangeSlider.ValueBeginChangeEvent) ValueEndChangeEvent(com.ray3k.stripe.RangeSlider.ValueEndChangeEvent) ValueBeginChangeEvent(com.ray3k.stripe.RangeSlider.ValueBeginChangeEvent) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ValueBeginChangeListener(com.ray3k.stripe.RangeSlider.ValueBeginChangeListener) ValueEndChangeListener(com.ray3k.stripe.RangeSlider.ValueEndChangeListener) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ValueBeginChangeListener(com.ray3k.stripe.RangeSlider.ValueBeginChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 2 with ValueEndChangeEvent

use of com.ray3k.stripe.RangeSlider.ValueEndChangeEvent in project skin-composer by raeleus.

the class TextFieldListeners method textFieldSelectionListener.

public static EventListener textFieldSelectionListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simTextField = (DialogSceneComposerModel.SimTextField) simActor;
    var popTableClickListener = new PopTableClickListener(skin) {

        {
            getPopTable().key(Keys.ESCAPE, popTable::hide);
        }

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            update();
        }

        public void update() {
            var popTable = getPopTable();
            popTable.clearChildren();
            var table = new Table();
            popTable.add(table);
            var positionLabel = new Label("Cursor Position: (" + simTextField.cursorPosition + ")", skin, "scene-label-colored");
            table.add(positionLabel);
            table.row();
            var slider = new Slider(0, simTextField.text == null ? 0 : simTextField.text.length(), 1, false, skin, "scene");
            slider.setValue(simTextField.cursorPosition);
            table.add(slider).minWidth(200);
            slider.addListener(handListener);
            slider.addListener(new TextTooltip("The cursor position when the textfield has keyboard focus.", tooltipManager, skin, "scene"));
            slider.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.textFieldCursorPosition(MathUtils.round(slider.getValue()));
                    positionLabel.setText("Cursor Position: (" + simTextField.cursorPosition + ")");
                }
            });
            table.row();
            var selectionLabel = new Label("Selection: (" + simTextField.selectionStart + ", " + simTextField.selectionEnd + ")", skin, "scene-label-colored");
            table.add(selectionLabel);
            table.row();
            var rangeSlider = new RangeSlider(skin, "scene");
            rangeSlider.setMinimum(0);
            rangeSlider.setMaximum(simTextField.text == null ? 0 : simTextField.text.length());
            rangeSlider.setIncrement(1);
            rangeSlider.setValueBegin(simTextField.selectionStart);
            rangeSlider.setValueEnd(simTextField.selectionEnd);
            rangeSlider.setDisabled(simTextField.selectAll);
            table.add(rangeSlider).minWidth(200);
            rangeSlider.getKnobBegin().addListener(handListener);
            rangeSlider.getKnobEnd().addListener(handListener);
            rangeSlider.addListener(new TextTooltip("The text range to be selected if this textField has keyboard focus.", tooltipManager, skin, "scene"));
            rangeSlider.addListener(new ValueBeginChangeListener() {

                @Override
                public void changed(ValueBeginChangeEvent event, float value, Actor actor) {
                    events.textFieldSelectionStart(MathUtils.round(value));
                }
            });
            rangeSlider.addListener(new ValueEndChangeListener() {

                @Override
                public void changed(ValueEndChangeEvent event, float value, Actor actor) {
                    events.textFieldSelectionEnd(MathUtils.round(value));
                }
            });
            rangeSlider.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    selectionLabel.setText("Selection: (" + simTextField.selectionStart + ", " + simTextField.selectionEnd + ")");
                }
            });
            table.row();
            var label = new Label("Select All: ", skin, "scene-label-colored");
            table.add(label);
            table.row();
            var textButton = new TextButton(simTextField.selectAll ? "TRUE" : "FALSE", skin, "scene-small");
            textButton.setChecked(simTextField.selectAll);
            table.add(textButton).minWidth(100);
            textButton.addListener(handListener);
            textButton.addListener(new TextTooltip("Convenience option to select all text.", tooltipManager, skin, "scene"));
            textButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    textButton.setText(textButton.isChecked() ? "TRUE" : "FALSE");
                    events.textFieldSelectAll(textButton.isChecked());
                    rangeSlider.setDisabled(textButton.isChecked());
                }
            });
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : ValueEndChangeEvent(com.ray3k.stripe.RangeSlider.ValueEndChangeEvent) StyleSelectorPopTable(com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable) RangeSlider(com.ray3k.stripe.RangeSlider) RangeSlider(com.ray3k.stripe.RangeSlider) ValueEndChangeListener(com.ray3k.stripe.RangeSlider.ValueEndChangeListener) ValueBeginChangeEvent(com.ray3k.stripe.RangeSlider.ValueBeginChangeEvent) ValueEndChangeEvent(com.ray3k.stripe.RangeSlider.ValueEndChangeEvent) ValueBeginChangeEvent(com.ray3k.stripe.RangeSlider.ValueBeginChangeEvent) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ValueBeginChangeListener(com.ray3k.stripe.RangeSlider.ValueBeginChangeListener) ValueEndChangeListener(com.ray3k.stripe.RangeSlider.ValueEndChangeListener) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ValueBeginChangeListener(com.ray3k.stripe.RangeSlider.ValueBeginChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)2 StyleSelectorPopTable (com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable)2 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)2 RangeSlider (com.ray3k.stripe.RangeSlider)2 ValueBeginChangeEvent (com.ray3k.stripe.RangeSlider.ValueBeginChangeEvent)2 ValueBeginChangeListener (com.ray3k.stripe.RangeSlider.ValueBeginChangeListener)2 ValueEndChangeEvent (com.ray3k.stripe.RangeSlider.ValueEndChangeEvent)2 ValueEndChangeListener (com.ray3k.stripe.RangeSlider.ValueEndChangeListener)2