- All Implemented Interfaces:
Component
,TextGUIElement
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Default renderer forScrollBar
which will be used unless overridden.static class
Helper class for making newScrollBar
renderers a little bit cleaner -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ComponentRenderer
<ScrollBar> 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).Returns the direction of thisScrollBar
int
Returns the maximum scroll valueint
Returns the position of theScrollBar
's trackerint
Returns the view size of the scrollbarsetScrollMaximum
(int maximum) Sets the maximum value the scrollbar's position (minus the view size) can havesetScrollPosition
(int position) Sets the scrollbar's position, should be a value between 0 andmaximum - view size
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 positionMethods inherited from class com.googlecode.lanterna.gui2.AbstractComponent
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
-
Field Details
-
direction
-
maximum
private int maximum -
position
private int position -
viewSize
private int viewSize
-
-
Constructor Details
-
ScrollBar
Creates a newScrollBar
with a specified direction- Parameters:
direction
- Direction of the scrollbar
-
-
Method Details
-
getDirection
Returns the direction of thisScrollBar
- Returns:
- Direction of this
ScrollBar
-
setScrollMaximum
Sets the maximum value the scrollbar's position (minus the view size) can have- Parameters:
maximum
- Maximum value- Returns:
- Itself
-
getScrollMaximum
public int getScrollMaximum()Returns the maximum scroll value- Returns:
- Maximum scroll value
-
setScrollPosition
Sets the scrollbar's position, should be a value between 0 andmaximum - view size
- Parameters:
position
- Scrollbar's tracker's position- Returns:
- Itself
-
getScrollPosition
public int getScrollPosition()Returns the position of theScrollBar
's tracker- Returns:
- Position of the
ScrollBar
's tracker
-
setViewSize
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- Parameters:
viewSize
- View size of the scrollbar- Returns:
- Itself
-
getViewSize
public int getViewSize()Returns the view size of the scrollbar- Returns:
- View size of the scrollbar
-
createDefaultRenderer
Description copied from class:AbstractComponent
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). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRenderer
in classAbstractComponent<ScrollBar>
- Returns:
- Renderer to use when sizing and drawing this component
-