package de.lessvoid.nifty.examples.scroll;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.controls.dynamic.LabelCreator;
import de.lessvoid.nifty.controls.scrollpanel.ScrollPanel;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

public class ScrollDemoStartScreen implements ScreenController {
  private Nifty nifty;
  private Screen screen;

  public void bind(final Nifty newNifty, final Screen newScreen) {
    screen = newScreen;
    nifty = newNifty;

    Element myScrollStuff = screen.findElementByName("myScrollStuff");
    if (myScrollStuff != null) {
      for (int i=0; i<100; i++) {
        addLabel(myScrollStuff, "hello " + i);
      }
      screen.layoutLayers();

      ScrollPanel scrollPanel = screen.findControl("scrollbarPanel", ScrollPanel.class);
      scrollPanel.initializeScrollPanel(screen, 0, myScrollStuff.getHeight() / 100.f);
    }
  }

  public void onStartScreen() {
  }

  private void addLabel(final Element myScrollStuff, final String text) {
    LabelCreator label = new LabelCreator(text);
    label.create(nifty, screen, myScrollStuff);
  }

  public void onEndScreen() {
  }

  public void back() {
    nifty.fromXml("all/intro.xml", "menu");
  }
}

@@ -129,16 +129,98 @@
 eator;%0D%0A
+import de.lessvoid.nifty.controls.scrollbar.controller.VerticalScrollbarControl;%0D%0A
 import d
@@ -1092,32 +1092,277 @@
 tartScreen() %7B%0D%0A
+    Element myScrollStuff = screen.findElementByName(%22myScrollStuff%22);%0D%0A    screen.findElementByName(%22scrollbarPanel%22).findControl(%22nifty-internal-vertical-scrollbar%22, VerticalScrollbarControl.class).setCurrentValue(myScrollStuff.getHeight());%0D%0A
   %7D%0D%0A%0D%0A  private

set current scrollpos to maximum to test scrolling of the scrollbar handle to the end for nifty support