Search in sources :

Example 1 with ScrollPane

use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane in project libgdx by libgdx.

the class GroupCullingTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    root = new Table();
    root.setFillParent(true);
    stage.addActor(root);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Table labels = new Table();
    root.add(new ScrollPane(labels, skin)).expand().fill();
    root.row();
    root.add(drawnLabel = new Label("", skin));
    for (int i = 0; i < count; i++) {
        labels.add(new Label("Label: " + i, skin) {

            public void draw(Batch batch, float parentAlpha) {
                super.draw(batch, parentAlpha);
                drawn++;
            }
        });
        labels.row();
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Batch(com.badlogic.gdx.graphics.g2d.Batch) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 2 with ScrollPane

use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane in project libgdx by libgdx.

the class InterpolationTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
    renderer = new ShapeRenderer();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage(new ScreenViewport());
    resetPositions();
    Field[] interpolationFields = ClassReflection.getFields(Interpolation.class);
    // see how many fields are actually interpolations (for safety; other fields may be added with future)
    int interpolationMembers = 0;
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationMembers++;
    // get interpolation names
    interpolationNames = new String[interpolationMembers];
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationNames[i] = interpolationFields[i].getName();
    selectedInterpolation = interpolationNames[0];
    list = new List(skin);
    list.setItems(interpolationNames);
    list.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            selectedInterpolation = list.getSelected();
            time = 0;
            resetPositions();
        }
    });
    ScrollPane scroll = new ScrollPane(list, skin);
    scroll.setFadeScrollBars(false);
    scroll.setScrollingDisabled(true, false);
    table = new Table();
    table.setFillParent(true);
    table.add(scroll).expandX().left().width(100);
    stage.addActor(table);
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean scrolled(int amount) {
            if (!Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
                return false;
            duration -= amount / 15f;
            duration = MathUtils.clamp(duration, 0, Float.POSITIVE_INFINITY);
            return true;
        }
    }, stage, new InputAdapter() {

        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (// if "walking" was interrupted by this touch down event
            !Float.isNaN(time))
                // set startPosition to the current position
                startPosition.set(getPosition(time));
            targetPosition.set(stage.screenToStageCoordinates(targetPosition.set(screenX, screenY)));
            time = 0;
            return true;
        }
    }));
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) Field(com.badlogic.gdx.utils.reflect.Field) Interpolation(com.badlogic.gdx.math.Interpolation) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) List(com.badlogic.gdx.scenes.scene2d.ui.List) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 3 with ScrollPane

use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane in project libgdx by libgdx.

the class TextAreaScrollTest method create.

@Override
public void create() {
    stage = new Stage(new ScreenViewport());
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);
    Table container = new Table();
    stage.addActor(container);
    container.setFillParent(true);
    container.pad(10).defaults().expandX().fillX().space(4);
    textArea = new TextArea(">>> FIRST LINE <<<\n" + "Scrolling to the bottom of the area you should see the last line.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Scrolling to the top of the area you should see the first line.\n" + ">>> LAST LINE <<<", skin) {

        public float getPrefHeight() {
            return getLines() * getStyle().font.getLineHeight();
        }
    };
    scrollPane = new ScrollPane(textArea, skin);
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    container.row().height(350);
    container.add(scrollPane);
    container.debugAll();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport)

Example 4 with ScrollPane

use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane in project commons-gdx by gemserk.

the class Actors method threeOptionsDialog.

public static Actor threeOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, String thirdOption, Skin skin) {
    Window window = new Window(titleText, skin);
    window.setMovable(false);
    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);
    TextButton thirdOptionButton = new TextButton(thirdOption, skin);
    firstOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });
    secondOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });
    thirdOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(2);
        }
    });
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    for (int i = 0; i < texts.length; i++) {
        window.row().padLeft(20);
        Label label = new Label(texts[i], skin);
        label.setWrap(true);
        window.add(label).align(Align.left).colspan(2).fillX();
    }
    window.row().fill().expandX().padTop(10);
    window.add(firstOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(secondOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(thirdOptionButton).align(Align.center).padLeft(30).padRight(30);
    ScrollPane scrollPane = new ScrollPane(window);
    scrollPane.setWidth(Gdx.graphics.getWidth() * 0.95f);
    scrollPane.setHeight(Gdx.graphics.getHeight() * 0.95f);
    scrollPane.setX(Gdx.graphics.getWidth() * 0.5f - scrollPane.getWidth() * 0.5f);
    scrollPane.setY(Gdx.graphics.getHeight() * 0.5f - scrollPane.getHeight() * 0.5f);
    return scrollPane;
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 5 with ScrollPane

use of com.badlogic.gdx.scenes.scene2d.ui.ScrollPane in project gdx-skineditor by cobolfoo.

the class PreviewPane method refresh.

/**
	 * 
	 */
public void refresh() {
    Gdx.app.log("PreviewPane", "Refresh pane!");
    clear();
    ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
    String widget = button.getUserObject().toString();
    String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
    try {
        Class<?> style = Class.forName(widgetStyle);
        ObjectMap<String, ?> styles = game.skinProject.getAll(style);
        if (styles == null) {
            Label label = new Label("No styles defined for this widget type", game.skin, "error");
            add(label).row().pad(10);
        } else {
            Keys<String> keys = styles.keys();
            Array<String> sortedKeys = new Array<String>();
            for (String key : keys) {
                sortedKeys.add(key);
            }
            sortedKeys.sort();
            for (String key : sortedKeys) {
                // We render one per key
                add(new Label(key, game.skin, "title")).left().pad(10).expandX().row();
                try {
                    if (widget.equals("Label")) {
                        Label w = new Label("This is a Label widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("Button")) {
                        // Button
                        Button w = new Button(game.skinProject, key);
                        add(w).width(120).height(32).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextButton")) {
                        // TextButton
                        TextButton w = new TextButton("This is a TextButton widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("ImageButton")) {
                        // ImageButton
                        ImageButton w = new ImageButton(game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("CheckBox")) {
                        // CheckBox
                        CheckBox w = new CheckBox("This is a CheckBox widget", game.skinProject, key);
                        w.setChecked(true);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextField")) {
                        // TextField
                        TextField w = new TextField("This is a TextField widget", game.skinProject, key);
                        if (w.getStyle().fontColor == null) {
                            throw new Exception("Textfield style requires a font color!");
                        }
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).row();
                    } else if (widget.equals("List")) {
                        // List
                        List w = new List(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("List widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).height(120).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SelectBox")) {
                        // SelectBox
                        SelectBox<String> w = new SelectBox<String>(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("SelectBox widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("ProgressBar")) {
                        // ProgressBar
                        ProgressBarStyle progressStyle = game.skinProject.get(key, ProgressBarStyle.class);
                        // Check for edge-case: fields knob and knobBefore are optional but at least one should be specified
                        if (progressStyle.knob == null && progressStyle.knobBefore == null) {
                            throw new IllegalArgumentException("Fields 'knob' and 'knobBefore' in ProgressBarStyle are both optional but at least one should be specified");
                        }
                        ProgressBar w = new ProgressBar(0, 100, 5, false, progressStyle);
                        w.setValue(50);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Slider")) {
                        // Slider
                        Slider w = new Slider(0, 100, 5, false, game.skinProject, key);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                        w.addListener(stopTouchDown);
                        Slider w2 = new Slider(0, 100, 5, true, game.skinProject, key);
                        add(w2).pad(10).padBottom(20).expandX().fillX().row();
                        w2.addListener(stopTouchDown);
                    } else if (widget.equals("ScrollPane")) {
                        // ScrollPane
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 20; i++) {
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").row();
                        }
                        ScrollPane w = new ScrollPane(t, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.setFlickScroll(true);
                        w.setScrollbarsOnTop(true);
                        w.setScrollBarPositions(true, true);
                        w.setFadeScrollBars(false);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SplitPane")) {
                        for (int j = 0; j < 2; j++) {
                            Table t = new Table(game.skin);
                            t.setBackground(game.skin.getDrawable("default-rect"));
                            Table t2 = new Table(game.skin);
                            t2.setBackground(game.skin.getDrawable("default-rect"));
                            for (int i = 0; i < 20; i++) {
                                t.add("This is a SplitPane Widget").pad(10).row();
                                t2.add("This is a SplitPane Widget").pad(10).row();
                            }
                            SplitPane w = new SplitPane(t, t2, (j % 2 == 0), game.skinProject, key);
                            w.addListener(stopTouchDown);
                            add(w).pad(10).width(220).height(160).padBottom(20).expandX().fillX();
                        }
                        row();
                    } else if (widget.equals("Window")) {
                        // Window
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 5; i++) {
                            t.add("This is a Window Widget").row();
                        }
                        Window w = new Window("This is a Window Widget", game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.add(t);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Touchpad")) {
                        // Touchpad
                        Touchpad w = new Touchpad(0, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Tree")) {
                        // Tree
                        Tree w = new Tree(game.skinProject, key);
                        Tree.Node node = new Tree.Node(new Label("This", game.skin));
                        Tree.Node node1 = new Tree.Node(new Label("is", game.skin));
                        Tree.Node node2 = new Tree.Node(new Label("a", game.skin));
                        Tree.Node node3 = new Tree.Node(new Label("Tree", game.skin));
                        Tree.Node node4 = new Tree.Node(new Label("Widget", game.skin));
                        node3.add(node4);
                        node2.add(node3);
                        node1.add(node2);
                        node.add(node1);
                        w.add(node);
                        w.expandAll();
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else {
                        add(new Label("Unknown widget type!", game.skin, "error")).pad(10).padBottom(20).row();
                    }
                } catch (Exception e) {
                    add(new Label("Please fill all required fields", game.skin, "error")).pad(10).padBottom(20).row();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Node(com.badlogic.gdx.graphics.g3d.model.Node) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ProgressBarStyle(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) List(com.badlogic.gdx.scenes.scene2d.ui.List) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Array(com.badlogic.gdx.utils.Array) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)

Aggregations

ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)15 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)11 Stage (com.badlogic.gdx.scenes.scene2d.Stage)9 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)9 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)9 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)9 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)5 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)5 List (com.badlogic.gdx.scenes.scene2d.ui.List)4 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)4 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)3 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)3 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)3 Texture (com.badlogic.gdx.graphics.Texture)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)2 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)2 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)2