java.lang.Object
io.github.somesourcecode.someguiapi.scene.Node
io.github.somesourcecode.someguiapi.scene.Parent
Direct Known Subclasses:
Region

public abstract class Parent extends Node
The base class for all nodes that can have children.

This class handles all hierarchy-related operations, such as adding and removing child nodes, layout and rendering.

Since:
1.0.0
  • Constructor Details

    • Parent

      protected Parent()
      Constructs a new parent node.
      Since:
      1.0.0
  • Method Details

    • getChildren

      protected ObservableList<Node> getChildren()
      Returns the list of children of this parent.
      Returns:
      the list of children
      Since:
      1.0.0
    • isSceneRoot

      public boolean isSceneRoot()
      Returns whether this parent is the root of a scene.
      Returns:
      whether this parent is the root of a scene
      Since:
      2.0.0
    • lookup

      public Node lookup(String selector)
      Description copied from class: Node
      Finds this Node or the first sub-node by the given selector.

      For example, to find a node with the id "my-node", the method can be used like this: scene.lookup("#my-node").

      Overrides:
      lookup in class Node
      Parameters:
      selector - the selector
      Returns:
      the first node that matches the selector, null if none is found
    • lookupAll

      protected Set<Node> lookupAll(String selector, Set<Node> results)
      Used by Node and Parent to traverse the scene graph to find all nodes that match the given selector.

      Note: This method should never create the result set. That should be done by the Node class implementation.

      Overrides:
      lookupAll in class Node
      Parameters:
      selector - the selector
      results - the results
      Returns:
      a set of nodes that match the selector; null if none is found
    • requestLayout

      public void requestLayout()
      Requests a layout update for this parent. Layout will be applied on the next layout pass.
      Since:
      2.0.0
    • needsLayout

      public boolean needsLayout()
      Returns whether this parent needs a layout update.
      Returns:
      whether this parent needs a layout update
      Since:
      2.0.0
      See Also:
    • layout

      public final void layout()
      Recursively applies the layout to all children and itself.
      Since:
      1.0.0
    • layoutChildren

      protected void layoutChildren()
    • getBackground

      public Background getBackground()
      Returns the background of this parent.
      Returns:
      the background
      Since:
      1.0.0
    • setBackground

      public void setBackground(Background background)
      Sets the background of this parent. It will be rendered behind all children.
      Parameters:
      background - the new background
      Since:
      1.0.0
    • renderPixelAt

      public Pixel renderPixelAt(int x, int y)
      Description copied from class: Node
      Returns a Pixel that should be rendered at the given coordinates. The coordinates are relative to this parent's bounds.
      Specified by:
      renderPixelAt in class Node
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the pixel at the given coordinates, or null if there is no pixel at the given coordinates
    • nodeAt

      public Node nodeAt(int x, int y)
      Description copied from class: Node
      Returns the node at the given coordinates. The coordinates are relative to this parent's bounds.
      Specified by:
      nodeAt in class Node
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the node at the given coordinates, or null if there is no node at the given coordinates