Class WidgetButton

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

public class WidgetButton extends Widget implements ITextInput, ISelectable
WidgetButton is a UI widget that represents a button. It extends the Widget class and implements IClickable, ITextInput, and ISelectable interfaces.
  • Constructor Details

    • WidgetButton

      public WidgetButton(int x, int y, int len, String text)
      Constructs a WidgetButton with specified position, length, and text. The button is initially not pressed.
      Parameters:
      x - The x-coordinate of the button.
      y - The y-coordinate of the button.
      len - The length of the button.
      text - The text displayed on the button.
    • WidgetButton

      public WidgetButton(int x, int y, int len, String text, TEXT_ALIGNMENT textAlignment)
      Constructs a WidgetButton with specified position, length, text, and text alignment. The button is initially not pressed.
      Parameters:
      x - The x-coordinate of the button.
      y - The y-coordinate of the button.
      len - The length of the button.
      text - The text displayed on the button.
      textAlignment - The text alignment of the button.
  • Method Details

    • select

      public void select()
      Marks the button as selected.
      Specified by:
      select in interface ISelectable
    • unselect

      public void unselect()
      Marks the button as unselected.
      Specified by:
      unselect in interface ISelectable
    • getPressed

      public boolean getPressed()
      Returns the pressed status of the button.
      Returns:
      true if the button is pressed, false otherwise.
    • clearPressed

      public void clearPressed()
      Clears the pressed status of the button.
    • drawSelection

      public void drawSelection(char[][] buffer, com.googlecode.lanterna.TextColor[][] printColor, com.googlecode.lanterna.TextColor[][] backColor)
      Returns the text displayed on the button.
      Specified by:
      drawSelection in interface ISelectable
      Parameters:
      buffer - The buffer to draw the text on.
      printColor - The print color of the text.
      backColor - The background color of the text.
    • draw

      public void draw(char[][] buffer, com.googlecode.lanterna.TextColor[][] printColor, com.googlecode.lanterna.TextColor[][] backColor)
      Draws the text displayed on the button.
      Specified by:
      draw in interface IDrawable
      Specified by:
      draw in class Widget
      Parameters:
      buffer - The buffer to draw the text on.
      printColor - The print color of the text.
      backColor - The background color of the text.
    • keyStroke

      public void keyStroke(com.googlecode.lanterna.input.KeyStroke keyStroke)
      Handles a keystroke input and changes the pressed status if the key is Enter.
      Specified by:
      keyStroke in interface ITextInput
      Parameters:
      keyStroke - The KeyStroke input to handle.