Example usage for com.badlogic.gdx.scenes.scene2d.ui ScrollPane ScrollPane

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui ScrollPane ScrollPane

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui ScrollPane ScrollPane.

Prototype

public ScrollPane(Actor widget, ScrollPaneStyle style) 

Source Link

Usage

From source file:at.hid.tabletopsimulator.screens.About.java

License:Apache License

@Override
public void show() {
    TableTopSimulator.debug(this.getClass().toString(), "creating About screen");
    stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));

    Gdx.input.setInputProcessor(stage);//from   w  w w .j a v a  2s .co m

    // creating skin
    TableTopSimulator.debug(this.getClass().toString(), "creating skin");
    skin = TableTopSimulator.assets.get("ui/gui.json", Skin.class);

    table = new Table(skin);
    //      table.setFillParent(true);
    //      table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    // creating heading
    TableTopSimulator.debug(this.getClass().toString(), "creating heading");
    Label lblHeading = new Label(TableTopSimulator.getLangBundle().format("About.lblHeading.text"), skin);

    final Label lblContent = new Label("http://libgdx.badlogicgames.com/\r\n" + "\r\n"
            + "libGDX is licensed under the Apache 2 License,\r\n"
            + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n"
            + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!", skin,
            "content");

    // creating list

    final List<String> listAbout = new List<String>(skin, "content");
    ArrayList<String> newItems = new ArrayList<String>();
    newItems.add("libgdx");
    newItems.add("libgdx-utils");
    newItems.add("flare gameart");
    String[] data = new String[newItems.size()];
    listAbout.setItems(newItems.toArray(data));
    listAbout.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (listAbout.getSelected().equals("libgdx")) {
                lblContent.clear();
                lblContent.setText("http://libgdx.badlogicgames.com/\r\n" + "\r\n"
                        + "libGDX is licensed under the Apache 2 License,\r\n"
                        + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n"
                        + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!");
            } else if (listAbout.getSelected().equals("libgdx-utils")) {
                lblContent.clear();
                lblContent.setText("https://bitbucket.org/dermetfan/libgdx-utils/wiki/Home\r\n" + "\r\n"
                        + "/* Copyright (c) 2014 PixelScientists\r\n" + "*\r\n" + "* The MIT License (MIT)\r\n"
                        + "*\r\n"
                        + "* Permission is hereby granted, free of charge, to any person obtaining a copy of\r\n"
                        + "* this software and associated documentation files (the \"Software\"), to deal in\r\n"
                        + "* the Software without restriction, including without limitation the rights to\r\n"
                        + "* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\n"
                        + "* the Software, and to permit persons to whom the Software is furnished to do so,\r\n"
                        + "* subject to the following conditions:\r\n" + "*\r\n"
                        + "* The above copyright notice and this permission notice shall be included in all\r\n"
                        + "* copies or substantial portions of the Software.\r\n" + "*\r\n"
                        + "* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n"
                        + "* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n"
                        + "* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\n"
                        + "* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\n"
                        + "* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\n"
                        + "* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n"
                        + "*/");
            } else if (listAbout.getSelected().equals("flare gameart")) {
                lblContent.clear();
                lblContent.setText("https://github.com/clintbellanger/flare-game\r\n" + "\r\n"
                        + "Flare (the game) is Copyright 2010-2013 Clint Bellanger. Contributors retain copyrights to their original contributions.\r\n"
                        + "\r\n" + "The Flare Engine is released under GPL version 3 or later.\r\n" + "\r\n"
                        + "All of Flare's art and data files are released under CC-BY-SA 3.0. Later versions are permitted.\r\n"
                        + "\r\n"
                        + "The Liberation Sans fonts version 2 are released under the SIL Open Font License, Version 1.1.\r\n"
                        + "\r\n"
                        + "The GNU Unifont font is released under GPL v2, with the exception that embedding the font in a document does not in itself bind that document to the terms of the GPL.");
            }
        }
    });

    // creating buttons
    TableTopSimulator.debug(this.getClass().toString(), "creating buttons");
    TextButton btnBack = new TextButton(TableTopSimulator.getLangBundle().format("About.btnBack.text"), skin);
    btnBack.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            TableTopSimulator.debug(this.getClass().toString(), "switching to Options screen");
            ((Game) Gdx.app.getApplicationListener()).setScreen(new Options());
            dispose();
        }
    });
    btnBack.pad(10);

    ScrollPane spAboutList = new ScrollPane(null, skin);
    ScrollPane spAboutContent = new ScrollPane(null, skin);

    SplitPane splitAbout = new SplitPane(spAboutList, spAboutContent, false, skin);
    splitAbout.setSplitAmount(0.2f);

    spAboutList.setWidget(listAbout);
    spAboutContent.setWidget(lblContent);

    // building ui
    TableTopSimulator.debug(this.getClass().toString(), "building ui");
    table.add(lblHeading).spaceBottom(100).row();
    table.add(splitAbout).spaceBottom(15).width(1200).row();
    table.add(btnBack).spaceBottom(15).row();
    if (TableTopSimulator.DEBUG) {
        table.debug(); // draw debug lines 
        splitAbout.debug(); // draw debug lines 
    }
    stage.addActor(table);
}

From source file:com.badlogic.gdx.tests.ScrollPaneWithDynamicScrolling.java

License:Apache License

public void create() {
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    Gdx.input.setInputProcessor(stage);/* ww  w  . j  a v a 2  s. c om*/

    dynamicLabel = new Label("Chat box begin here", skin);

    float chatWidth = 200;
    float controlHeight = 300;

    scrollPane = new ScrollPane(dynamicLabel, skin);

    Table main = new Table();

    main.setFillParent(true);

    TextButton btAdd = new TextButton("Add text and scroll down", skin);

    main.add(btAdd).row();
    main.add(scrollPane).size(200, 100);

    stage.addActor(main);

    stage.setDebugAll(true);

    btAdd.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            dynamicLabel.setText(dynamicLabel.getText() + "\nline " + count++);
            scrollPane.scrollTo(0, 0, 0, 0);
        }
    });

}

From source file:com.bladecoder.engineeditor.ui.AssetsList.java

License:Apache License

public AssetsList(Skin skin) {
    super(skin);/*from  ww w  .  j  av  a  2  s.c o  m*/

    assetTypes = new SelectBox<String>(skin);
    assetTypes.setItems(ASSET_TYPES);

    this.skin = skin;

    list = new CustomList<String>(skin);

    Array<String> items = new Array<String>();
    list.setItems(items);

    ScrollPane scrollPane = new ScrollPane(list, skin);
    container = new Container<ScrollPane>(scrollPane);
    container.fill();
    container.prefHeight(1000);

    toolbar = new EditToolbar(skin);
    //      debug();
    add(assetTypes).expandX().fillX();
    row();
    add(toolbar).expandX().fillX();
    row();
    add(container).expand().fill();

    toolbar.addCreateListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            create();
        }
    });

    toolbar.addEditListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            edit();
        }
    });

    toolbar.addDeleteListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            delete();
        }
    });

    list.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            toolbar.disableEdit(false);
        }
    });

    Ctx.project.addPropertyChangeListener(Project.NOTIFY_PROJECT_LOADED, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent arg0) {
            toolbar.disableCreate(Ctx.project.getProjectDir() == null);
            addAssets();
        }
    });

    assetTypes.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            addAssets();
        }
    });
}

From source file:com.bladecoder.engineeditor.ui.components.EditDialog.java

License:Apache License

public EditDialog(String title, Skin skin) {
    super(title, skin);

    this.skin = skin;

    setResizable(false);/* w w  w. j  a  va2  s .  co m*/

    infoLbl = new Label("", skin);
    infoLbl.setWrap(true);
    centerPanel = new Table(skin);
    infoCell = getContentTable().add((Widget) infoLbl).prefWidth(200);
    getContentTable().add(new ScrollPane(centerPanel, skin)).maxHeight(Gdx.graphics.getHeight() * 0.8f)
            .maxWidth(Gdx.graphics.getWidth() * 0.7f).minHeight(Gdx.graphics.getHeight() * 0.5f)
            .minWidth(Gdx.graphics.getWidth() * 0.5f);

    centerPanel.addListener(new InputListener() {
        @Override
        public void enter(InputEvent event, float x, float y, int pointer,
                com.badlogic.gdx.scenes.scene2d.Actor fromActor) {
            //            EditorLogger.debug("ENTER - X: " + x + " Y: " + y);
            getStage().setScrollFocus(centerPanel);
        }
    });

    button("OK", true);
    button("Cancel", false);
    // DISABLE the enter key because conflicts when newline in TextFields
    //      key(Keys.ENTER, true);
    key(Keys.ESCAPE, false);

    padBottom(10);
    padLeft(10);
    padRight(10);
}

From source file:com.bladecoder.engineeditor.ui.components.EditList.java

License:Apache License

public EditList(Skin skin) {
    super(skin);/*ww w .j  ava2 s .  c  om*/

    this.skin = skin;

    list = new CustomList<T>(skin);

    Array<T> items = new Array<T>();
    list.setItems(items);

    ScrollPane scrollPane = new ScrollPane(list, skin);
    container = new Container<ScrollPane>(scrollPane);
    container.fill();
    container.prefHeight(1000);

    toolbar = new EditToolbar(skin);
    //      debug();
    add(toolbar).expandX().fillX();
    row();
    add(container).expand().fill();

    toolbar.addCreateListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            create();
        }
    });

    toolbar.addEditListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            edit();
        }
    });

    toolbar.addDeleteListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            delete();
        }
    });

    toolbar.addCopyListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            copy();
        }
    });

    toolbar.addPasteListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            paste();
        }
    });

    list.addListener(new InputListener() {
        @Override
        public void enter(InputEvent event, float x, float y, int pointer,
                com.badlogic.gdx.scenes.scene2d.Actor fromActor) {
            //            EditorLogger.debug("ENTER - X: " + x + " Y: " + y);
            getStage().setScrollFocus(list);
        }
    });
}

From source file:com.bladecoder.engineeditor.ui.components.EditTree.java

License:Apache License

public EditTree(Skin skin) {
    super(skin);/*from  ww  w. jav  a  2 s.  c om*/

    this.skin = skin;
    upBtn = new ImageButton(skin);
    downBtn = new ImageButton(skin);
    leftBtn = new ImageButton(skin);
    rightBtn = new ImageButton(skin);

    tree = new Tree(skin);

    ScrollPane scrollPane = new ScrollPane(tree, skin);
    container = new Container<ScrollPane>(scrollPane);
    container.fill();
    container.prefHeight(1000);

    toolbar = new EditToolbar(skin);
    //      debug();
    add(toolbar).expandX().fillX();
    row().fill();
    add(container).expandY().fill();

    toolbar.addToolBarButton(upBtn, "ic_up", "Move up", "Move up");
    toolbar.addToolBarButton(downBtn, "ic_down", "Move down", "Move down");
    toolbar.addToolBarButton(leftBtn, "ic_left", "Child", "Move to child option");
    toolbar.addToolBarButton(rightBtn, "ic_right", "Parent", "Move to parent option");
    toolbar.addCreateListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            create();
        }
    });

    toolbar.addEditListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            edit();
        }
    });

    toolbar.addDeleteListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            delete();
        }
    });

    toolbar.addCopyListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            copy();
        }
    });

    toolbar.addPasteListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            paste();
        }
    });

    upBtn.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            upNode();
        }
    });

    downBtn.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            downNode();
        }
    });

    leftBtn.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            leftNode();
        }
    });

    rightBtn.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            rightNode();
        }
    });

    tree.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Selection<Node> selection = tree.getSelection();

            if (selection.isEmpty()) {
                upBtn.setDisabled(true);
                downBtn.setDisabled(true);

                leftBtn.setDisabled(true);
                rightBtn.setDisabled(true);
            } else {

                Node nodeSel = selection.first();

                int level = nodeSel.getLevel();
                Array<Node> siblings = getSiblings();

                upBtn.setDisabled(siblings.get(0) == nodeSel);
                downBtn.setDisabled(siblings.get(siblings.size - 1) == nodeSel);

                leftBtn.setDisabled(level == 1);
                rightBtn.setDisabled(siblings.get(0) == nodeSel);
            }

            toolbar.disableEdit(selection == null);
        }

    });
}

From source file:com.bladecoder.engineeditor.ui.components.TextInputPanel.java

License:Apache License

TextInputPanel(Skin skin, String title, String desc, boolean mandatory, String defaultValue) {
    input = new TextArea("", skin);
    input.setPrefRows(10);//from  w  w w.  ja  va2s.  c  o  m

    ScrollPane scroll = new ScrollPane(input, skin);

    init(skin, title, desc, scroll, mandatory, defaultValue);
}

From source file:com.blastedstudios.gdxworld.util.ui.TreeFileChooser.java

License:Apache License

/** builds {@link #chooseButton}, {@link #cancelButtonListener}, {@link #tree}, {@link #treePane} */
protected void buildWidgets() {
    (tree = new Tree(style.treeStyle)).addListener(treeListener);
    if (style.scrollPaneStyle != null)
        treePane = new ScrollPane(tree, style.scrollPaneStyle);
    else/*from ww  w  .j  ava  2 s  .  c  om*/
        treePane = new ScrollPane(tree);
    (chooseButton = Scene2DUtils.newButton(style.selectButtonStyle, "select"))
            .addListener(chooseButtonListener);
    chooseButton.setDisabled(true);
    (cancelButton = Scene2DUtils.newButton(style.cancelButtonStyle, "cancel"))
            .addListener(cancelButtonListener);
}

From source file:com.forerunnergames.peril.client.ui.widgets.messagebox.DefaultMessageBox.java

License:Open Source License

public DefaultMessageBox(final MessageBoxStyle style, final WidgetFactory widgetFactory) {
    Arguments.checkIsNotNull(style, "style");
    Arguments.checkIsNotNull(widgetFactory, "widgetFactory");

    this.style = style;
    this.widgetFactory = widgetFactory;

    table = new Table();

    configureTable();/*from w ww  . jav  a2  s  . c o  m*/

    scrollPane = new ScrollPane(table,
            widgetFactory.createScrollPaneStyle(style.getScrollPaneStyle(), style.getScrollbarStyle())) {
        private final int scissorsDeltaY = 2 + DefaultMessageBox.this.style.getScrollPaddingBottom();
        private final int scissorsDeltaHeight = 1 - DefaultMessageBox.this.style.getScrollPaddingTop()
                - DefaultMessageBox.this.style.getScrollPaddingBottom();

        @Override
        protected void drawChildren(final Batch batch, final float parentAlpha) {
            final Rectangle scissors = ScissorStack.popScissors();
            scissors.setY(scissors.getY() + scissorsDeltaY);
            scissors.setHeight(scissors.getHeight() + scissorsDeltaHeight);
            ScissorStack.pushScissors(scissors);
            super.drawChildren(batch, parentAlpha);
        }
    };

    scrollPane.setOverscroll(false, false);
    scrollPane.setFlickScroll(true);
    scrollPane.setForceScroll(false, style.areScrollbarsRequired());
    scrollPane.setFadeScrollBars(false);
    scrollPane.setScrollingDisabled(true, false);
    scrollPane.setScrollBarPositions(true, true);
    scrollPane.setScrollbarsOnTop(false);
    scrollPane.setSmoothScrolling(true);
    scrollPane.setVariableSizeKnobs(true);

    scrollPane.addListener(new InputListener() {
        @Override
        public void enter(final InputEvent event, final float x, final float y, final int pointer,
                final Actor fromActor) {
            if (scrollPane.getStage() == null)
                return;

            scrollPane.getStage().setScrollFocus(scrollPane);
        }

        @Override
        public void exit(final InputEvent event, final float x, final float y, final int pointer,
                final Actor toActor) {
            if (scrollPane.getStage() == null)
                return;

            scrollPane.getStage().setScrollFocus(null);
        }
    });
}

From source file:com.gdx.extension.ui.slide.SlideShow.java

License:Apache License

public SlideShow(boolean isVertical, Skin skin, String styleName) {
    super(skin);//from  w  w  w  . java 2  s .c o m

    setStyle(skin.get(styleName, SlideShowStyle.class));

    this.isVertical = isVertical;

    content = (isVertical) ? new VerticalGroup() : new HorizontalGroup();

    ScrollPaneStyle _scrollStyle = new ScrollPaneStyle();
    contentScroll = new ScrollPane(content, _scrollStyle);
    contentScroll.setScrollingDisabled(isVertical, !isVertical);
    contentScroll.setOverscroll(false, false);

    setBackground(style.background);

    previousScrollButton = new ImageButton(getStyle().previousScroll);
    previousScrollButtonCell = add(previousScrollButton);
    if (isVertical)
        previousScrollButtonCell.row();
    Cell<ScrollPane> _contentCell = add(contentScroll);
    if (isVertical)
        _contentCell.row();
    nextScrollButton = new ImageButton(getStyle().nextScroll);
    nextScrollButtonCell = add(nextScrollButton);

    previousScrollButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (SlideShow.this.isVertical)
                contentScroll.setScrollPercentY(contentScroll.getScrollPercentY() - 0.1f);
            else
                contentScroll.setScrollPercentX(contentScroll.getScrollPercentX() - 0.1f);
        }

    });
    nextScrollButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (SlideShow.this.isVertical)
                contentScroll.setScrollPercentY(contentScroll.getScrollPercentY() + 0.1f);
            else
                contentScroll.setScrollPercentX(contentScroll.getScrollPercentX() + 0.1f);
        }

    });
}