Component
, TextGUIElement
public class ScrollBar extends AbstractComponent<ScrollBar>
ScrollBar
s are either horizontal or vertical,
which affects the way they appear and how they are drawn.
This class works on two concepts, the min-position-max values and the view size. The minimum value is always 0 and
cannot be changed. The maximum value is 100 and can be adjusted programmatically. Position value is whever along the
axis of 0 to max the scrollbar's tracker currently is placed. The view size is an important concept, it determines
how big the tracker should be and limits the position so that it can only reach maximum value - view size
.
The regular way to use the ScrollBar
class is to tie it to the model-view of another component and set the
scrollbar's maximum to the total height (or width, if the scrollbar is horizontal) of the model-view. View size
should then be assigned based on the current size of the view, meaning as the terminal and/or the GUI changes and the
components visible space changes, the scrollbar's view size is updated along with it. Finally the position of the
scrollbar should be equal to the scroll offset in the component.
Modifier and Type | Class | Description |
---|---|---|
static class |
ScrollBar.DefaultScrollBarRenderer |
Default renderer for
ScrollBar which will be used unless overridden. |
static class |
ScrollBar.ScrollBarRenderer |
Helper class for making new
ScrollBar renderers a little bit cleaner |
Constructor | Description |
---|---|
ScrollBar(Direction direction) |
Creates a new
ScrollBar with a specified direction |
Modifier and Type | Method | Description |
---|---|---|
protected ComponentRenderer<ScrollBar> |
createDefaultRenderer() |
When you create a custom component, you need to implement this method and return a Renderer which is responsible
for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).
|
Direction |
getDirection() |
Returns the direction of this
ScrollBar |
int |
getScrollMaximum() |
Returns the maximum scroll value
|
int |
getScrollPosition() |
Returns the position of the
ScrollBar 's tracker |
int |
getViewSize() |
Returns the view size of the scrollbar
|
ScrollBar |
setScrollMaximum(int maximum) |
Sets the maximum value the scrollbar's position (minus the view size) can have
|
ScrollBar |
setScrollPosition(int position) |
Sets the scrollbar's position, should be a value between 0 and
maximum - view size |
ScrollBar |
setViewSize(int viewSize) |
Sets the view size of the scrollbar, determining how big the scrollbar's tracker should be and also affecting the
maximum value of tracker's position
|
addTo, calculatePreferredSize, draw, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, toBasePane, toGlobal, withBorder
public ScrollBar(Direction direction)
ScrollBar
with a specified directiondirection
- Direction of the scrollbarpublic Direction getDirection()
ScrollBar
ScrollBar
public ScrollBar setScrollMaximum(int maximum)
maximum
- Maximum valuepublic int getScrollMaximum()
public ScrollBar setScrollPosition(int position)
maximum - view size
position
- Scrollbar's tracker's positionpublic int getScrollPosition()
ScrollBar
's trackerScrollBar
's trackerpublic ScrollBar setViewSize(int viewSize)
viewSize
- View size of the scrollbarpublic int getViewSize()
protected ComponentRenderer<ScrollBar> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractComponent<ScrollBar>
Copyright © 2020. All rights reserved.