- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<ScrollBar>
-
- com.googlecode.lanterna.gui2.ScrollBar
-
- All Implemented Interfaces:
Component
,TextGUIElement
public class ScrollBar extends AbstractComponent<ScrollBar>
Classic scrollbar that can be used to display where inside a larger component a view is showing. This implementation is not interactable and needs to be driven externally, meaning you can't focus on the scrollbar itself, you have to update its state as part of another component being modified.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 Classes Modifier and Type Class Description static class
ScrollBar.DefaultScrollBarRenderer
Default renderer forScrollBar
which will be used unless overridden.static class
ScrollBar.ScrollBarRenderer
Helper class for making newScrollBar
renderers a little bit cleaner
-
Method Summary
All Methods Instance Methods Concrete Methods 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 thisScrollBar
int
getScrollMaximum()
Returns the maximum scroll valueint
getScrollPosition()
Returns the position of theScrollBar
's trackerint
getViewSize()
Returns the view size of the scrollbarScrollBar
setScrollMaximum(int maximum)
Sets the maximum value the scrollbar's position (minus the view size) can haveScrollBar
setScrollPosition(int position)
Sets the scrollbar's position, should be a value between 0 andmaximum - 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-
Methods 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 Detail
-
direction
private final Direction direction
-
maximum
private int maximum
-
position
private int position
-
viewSize
private int viewSize
-
-
Constructor Detail
-
ScrollBar
public ScrollBar(Direction direction)
Creates a newScrollBar
with a specified direction- Parameters:
direction
- Direction of the scrollbar
-
-
Method Detail
-
getDirection
public Direction getDirection()
Returns the direction of thisScrollBar
- Returns:
- Direction of this
ScrollBar
-
setScrollMaximum
public ScrollBar setScrollMaximum(int maximum)
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
public ScrollBar setScrollPosition(int position)
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
public 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- 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
protected ComponentRenderer<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
-
-