Klasse UIScrollView

java.lang.Object
net.risingworld.api.ui.UIElement
net.risingworld.api.ui.UIScrollView
Alle implementierten Schnittstellen:
Serializable

public class UIScrollView extends UIElement
Represents a dynamic scroll view. Child elements added to the scroll view will only be visible within the scroll area. You can add any kind of content to the scroll view element.
Example: Create scroll view and add some elements to it
1//Create a new scroll view (vertical scrolling)
2UIScrollView scrollView = new UIScrollView(UIScrollView.ScrollViewMode.Vertical);
3
4//Set a size for the scroll area
5scrollView.setSize(700, 550, false);
6scrollView.setPosition(50f, 50f, true);
7
8//We want the scroll view to be centered
9scrollView.setPivot(Pivot.MiddleCenter);
10
11//Optionally set a border (in this case we only do it
12//to visualize the scroll view)
13scrollView.setBorderColor(ColorRGBA.Black.toIntRGBA());
14scrollView.setBorder(10);
15
16//Set some padding, so there is a gap between elements
17//and the upper/lower scroll view border
18scrollView.style.paddingTop.set(5);
19scrollView.style.paddingBottom.set(5);
20
21//Add scroll view to player UI
22player.addUIElement(scrollView);
23
24//Now we want to add 25 UI elements
25for (int i = 0; i < 25; i++) {
26 //Create child element
27 UIElement child = new UIElement();
28
29 //Set a random color
30 child.setBackgroundColor(Utils.GeneralUtils.nextRandomColor(false));
31
32 //Optionally set a border (again for reasons of visualization
33 //in this case)
34 child.setBorder(5);
35 child.setBorderColor(0x000000FF);
36
37 //We want the elements to have a defined height (70px)
38 child.style.height.set(70);
39
40 //Set some margin, so there is a gap between elements,
41 //but also a gap to the left and right border of the scroll view
42 child.style.marginTop.set(4);
43 child.style.marginLeft.set(10);
44 child.style.marginRight.set(10);
45
46 //Optionally we could add an arbitrary amount of childs
47 //to our child of course - in this case we just add a label
48 UILabel label = new UILabel("Element " + i);
49 label.setFontSize(30);
50 label.setTextAlign(TextAnchor.MiddleCenter);
51 child.addChild(label);
52
53 //To add an element to a scroll view, simply add it as child
54 scrollView.addChild(child);
55}
56
57//Optionally make the mouse cursor visible, so the player can
58//interact with the scroll view
59player.setMouseCursorVisible(true);
Siehe auch:
  • Konstruktordetails

    • UIScrollView

      public UIScrollView(UIScrollView.ScrollViewMode mode)
      Creates a new scroll view.
      Parameter:
      mode - scroll view mode. Cannot be changed retroactively.
  • Methodendetails

    • getScrollViewMode

      public UIScrollView.ScrollViewMode getScrollViewMode()
      Gets the scroll view mode.
      Gibt zurück:
      the scroll view mode.
    • setHorizontalScrollerVisibility

      public void setHorizontalScrollerVisibility(UIScrollView.ScrollerVisibility visibility)
      Sets the visibility for the horizontal scroll element.
      Parameter:
      visibility - the visibility setting for the horizontal scroller.
    • getHorizontalScrollerVisibility

      public UIScrollView.ScrollerVisibility getHorizontalScrollerVisibility()
      Gets the visibility setting for the horizontal scroll element.
      Gibt zurück:
      the horizontal scroller visibility setting.
    • setVerticalScrollerVisibility

      public void setVerticalScrollerVisibility(UIScrollView.ScrollerVisibility visibility)
      Sets the visibility for the vertical scroll element.
      Parameter:
      visibility - the visibility setting for the vertical scroller.
    • getVerticalScrollerVisibility

      public UIScrollView.ScrollerVisibility getVerticalScrollerVisibility()
      Gets the visibility setting for the vertical scroll element.
      Gibt zurück:
      the vertical scroller visibility setting.
    • setHorizontalPageSize

      public void setHorizontalPageSize(float pageSize)
    • getHorizontalPageSize

      public float getHorizontalPageSize()
    • setVerticalPageSize

      public void setVerticalPageSize(float pageSize)
    • getVerticalPageSize

      public float getVerticalPageSize()
    • setMouseWheelScrollSize

      public void setMouseWheelScrollSize(float scrollSize)
    • getMouseWheelScrollSize

      public float getMouseWheelScrollSize()
    • setElasticity

      public void setElasticity(float elasticity)
    • getElasticity

      public float getElasticity()