Class WidgetToggle

java.lang.Object
app.ui.widgets.Widget
app.ui.widgets.WidgetToggle
All Implemented Interfaces:
IDrawable, ISelectable, ITextInput

public class WidgetToggle extends Widget implements ITextInput, ISelectable
WidgetToggle represents a toggle button in a user interface. It can be pressed or unpressed, changing its state and appearance.
  • Constructor Details

    • WidgetToggle

      public WidgetToggle(int x, int y, int len, String text)
      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

      public WidgetToggle(int x, int y, int len, String text, TEXT_ALIGNMENT textAlignment)
      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:
      select in interface ISelectable
    • unselect

      public void unselect()
      Sets the toggle to an unselected state.
      Specified by:
      unselect in interface ISelectable
    • 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:
      drawSelection in interface ISelectable
      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.
      Specified by:
      draw in interface IDrawable
      Specified by:
      draw in class Widget
      Parameters:
      buffer - The character buffer for drawing the widget.
      printColor - The color buffer for text color.
      backColor - The color buffer for background color.
    • keyStroke

      public void keyStroke(com.googlecode.lanterna.input.KeyStroke keyStroke)
      Handles a key stroke input for the toggle.
      Specified by:
      keyStroke in interface ITextInput
      Parameters:
      keyStroke - The key stroke input.