Class WPanel

java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WPanel
Direct Known Subclasses:
WCardPanel, WClippedPanel, WPanelWithInsets, WScrollPanel, WTabPanel

public abstract class WPanel extends WWidget
Panels are widgets that contain other widgets.
  • Field Details

    • children

      protected final List<WWidget> children
      The widgets contained within this panel.

      The list is mutable.

  • Constructor Details

    • WPanel

      public WPanel()
  • Method Details

    • remove

      public void remove(WWidget w)
      Removes the widget from this panel.
      Parameters:
      w - the removed widget
    • canResize

      public boolean canResize()
      Description copied from class: WWidget
      Checks whether this widget can be resized using WWidget.setSize(int, int).
      Overrides:
      canResize in class WWidget
      Returns:
      true if this widget can be resized, false otherwise
    • setBackgroundPainter

      @Environment(CLIENT) public WPanel setBackgroundPainter(BackgroundPainter painter)
      Sets the BackgroundPainter of this panel.
      Parameters:
      painter - the new painter
      Returns:
      this panel
    • getBackgroundPainter

      @Environment(CLIENT) public BackgroundPainter getBackgroundPainter()
      Gets the current BackgroundPainter of this panel.
      Returns:
      the painter
    • layout

      public void layout()
      Uses this Panel's layout rules to reposition and resize components to fit nicely in the panel.
    • expandToFit

      protected void expandToFit(WWidget w)
      Expands this panel be at least as large as the widget.
      Parameters:
      w - the widget
    • expandToFit

      protected void expandToFit(WWidget w, Insets insets)
      Expands this panel be at least as large as the widget.
      Parameters:
      w - the widget
      insets - the layout insets
      Since:
      4.0.0
    • hit

      public WWidget hit(int x, int y)
      Finds the most specific child node at this location.
      Overrides:
      hit in class WWidget
    • validate

      public void validate(GuiDescription c)
      Creates component peers and initializes animation data for this Widget and all its children. The host screen handler must clear any heavyweight peers from its records before this method is called.

      This method must be called on the root panel of any screen once the widgets have been initialized.

      Subclasses should call super.validate(c) to ensure that children are validated.

      Overrides:
      validate in class WWidget
      Parameters:
      c - the host GUI description
    • setHost

      public void setHost(GuiDescription host)
      Description copied from class: WWidget
      Sets the host of this widget and all its children without creating peers.
      Overrides:
      setHost in class WWidget
      Parameters:
      host - the new host
      See Also:
    • paint

      @Environment(CLIENT) public void paint(DrawContext context, int x, int y, int mouseX, int mouseY)
      Description copied from class: WWidget
      Paints this widget.
      Overrides:
      paint in class WWidget
      Parameters:
      context - the draw context
      x - this widget's X coordinate on the screen
      y - this widget's Y coordinate on the screen
      mouseX - the X coordinate of the cursor
      mouseY - the X coordinate of the cursor
    • tick

      @Environment(CLIENT) public void tick()
      Ticks all children of this panel.
      Overrides:
      tick in class WWidget
    • onShown

      public void onShown()
      Description copied from class: WWidget
      Notifies this widget that it is visible and shows any hidden peers of itself and its children.
      Overrides:
      onShown in class WWidget
    • onHidden

      public void onHidden()
      Description copied from class: WWidget
      Notifies this widget that it won't be drawn and hides any visible peers of itself and its children.

      The default implementation releases this widget's focus if it is focused. Overriding implementations might want to do this as well.

      Overrides:
      onHidden in class WWidget
    • addPainters

      @Environment(CLIENT) public void addPainters()
      Adds the default background painters to this widget and all children.

      Always called before GuiDescription.addPainters() to allow users to modify painters.

      Subclasses should call super.addPainters() to ensure that children have proper default painters.

      Overrides:
      addPainters in class WWidget
      Since:
      3.0.0
    • streamChildren

      public final Stream<WWidget> streamChildren()
      Returns a stream of all visible top-level widgets in this panel.
      Returns:
      a stream of all visible top-level widgets in this panel
      Since:
      4.2.0
    • toString

      public String toString()
      Overrides:
      toString in class Object