Package app.ui.widgets
Class WidgetToggle
java.lang.Object
app.ui.widgets.Widget
app.ui.widgets.WidgetToggle
- All Implemented Interfaces:
IDrawable,ISelectable,ITextInput
WidgetToggle represents a toggle button in a user interface.
It can be pressed or unpressed, changing its state and appearance.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionWidgetToggle(int x, int y, int len, String text) Constructs a WidgetToggle with a specified text and default alignment.WidgetToggle(int x, int y, int len, String text, TEXT_ALIGNMENT textAlignment) Constructs a WidgetToggle with a specified text and alignment. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the pressed state of the toggle, setting it to unpressed.voiddraw(char[][] buffer, com.googlecode.lanterna.TextColor[][] printColor, com.googlecode.lanterna.TextColor[][] backColor) Draws the toggle widget on the provided buffer.voiddrawSelection(char[][] buffer, com.googlecode.lanterna.TextColor[][] printColor, com.googlecode.lanterna.TextColor[][] backColor) Draws the selection state of the toggle on the provided buffer.booleanReturns the pressed state of the toggle.voidkeyStroke(com.googlecode.lanterna.input.KeyStroke keyStroke) Handles a key stroke input for the toggle.voidselect()Sets the toggle to a selected state.voidSets the toggle to a pressed state.voidunselect()Sets the toggle to an unselected state.Methods inherited from class app.ui.widgets.Widget
drawText, getLen, getSelected, getSkipSelection, getText, getWidgetID, getX, getY, isHide, setHide, setSkipSelection, setText, setWidgetID
-
Constructor Details
-
WidgetToggle
Constructs a WidgetToggle with a specified text and default alignment.- Parameters:
x- The x-coordinate of the widget.y- The y-coordinate of the widget.len- The length of the widget.text- The text displayed next to the toggle.
-
WidgetToggle
Constructs a WidgetToggle with a specified text and alignment.- Parameters:
x- The x-coordinate of the widget.y- The y-coordinate of the widget.len- The length of the widget.text- The text displayed next to the toggle.textAlignment- The alignment of the text within the widget.
-
-
Method Details
-
select
public void select()Sets the toggle to a selected state.- Specified by:
selectin interfaceISelectable
-
unselect
public void unselect()Sets the toggle to an unselected state.- Specified by:
unselectin interfaceISelectable
-
getPressed
public boolean getPressed()Returns the pressed state of the toggle.- Returns:
- true if the toggle is pressed, false otherwise.
-
clearPressed
public void clearPressed()Clears the pressed state of the toggle, setting it to unpressed. -
setPressed
public void setPressed()Sets the toggle to a pressed state. -
drawSelection
public void drawSelection(char[][] buffer, com.googlecode.lanterna.TextColor[][] printColor, com.googlecode.lanterna.TextColor[][] backColor) Draws the selection state of the toggle on the provided buffer.- Specified by:
drawSelectionin interfaceISelectable- Parameters:
buffer- The character buffer for drawing the widget.printColor- The color buffer for text color.backColor- The color buffer for background color.
-
draw
public void draw(char[][] buffer, com.googlecode.lanterna.TextColor[][] printColor, com.googlecode.lanterna.TextColor[][] backColor) Draws the toggle widget on the provided buffer. -
keyStroke
public void keyStroke(com.googlecode.lanterna.input.KeyStroke keyStroke) Handles a key stroke input for the toggle.- Specified by:
keyStrokein interfaceITextInput- Parameters:
keyStroke- The key stroke input.
-