Search in sources :

Example 1 with TextFieldFilter

use of com.kotcrab.vis.ui.widget.VisTextField.TextFieldFilter in project vis-ui by kotcrab.

the class BasicColorPicker method createHexTable.

private VisTable createHexTable() {
    VisTable table = new VisTable(true);
    table.add(new VisLabel(HEX.get()));
    table.add(hexField = new VisValidatableTextField("00000000")).width(HEX_FIELD_WIDTH * sizes.scaleFactor);
    table.row();
    hexField.setMaxLength(HEX_COLOR_LENGTH);
    hexField.setProgrammaticChangeEvents(false);
    hexField.setTextFieldFilter(new TextFieldFilter() {

        @Override
        public boolean acceptChar(VisTextField textField, char c) {
            return Character.isDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
        }
    });
    hexField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (hexField.getText().length() == (allowAlphaEdit ? HEX_COLOR_LENGTH_WITH_ALPHA : HEX_COLOR_LENGTH)) {
                setColor(Color.valueOf(hexField.getText()), false);
            }
        }
    });
    return table;
}
Also used : VisTextField(com.kotcrab.vis.ui.widget.VisTextField) VisTable(com.kotcrab.vis.ui.widget.VisTable) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextFieldFilter(com.kotcrab.vis.ui.widget.VisTextField.TextFieldFilter) VisLabel(com.kotcrab.vis.ui.widget.VisLabel) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 VisLabel (com.kotcrab.vis.ui.widget.VisLabel)1 VisTable (com.kotcrab.vis.ui.widget.VisTable)1 VisTextField (com.kotcrab.vis.ui.widget.VisTextField)1 TextFieldFilter (com.kotcrab.vis.ui.widget.VisTextField.TextFieldFilter)1 VisValidatableTextField (com.kotcrab.vis.ui.widget.VisValidatableTextField)1