Class SurfaceNode

java.lang.Object
com.codename1.surfaces.SurfaceNode
Direct Known Subclasses:
SurfaceContainer, SurfaceDynamicText, SurfaceImage, SurfaceProgress, SurfaceSpacer, SurfaceText, SurfaceVector

public abstract class SurfaceNode extends Object

The base class of all surface layout nodes. A surface descriptor is a small tree of nodes (columns, rows, boxes, text, images, progress indicators) that every platform can render natively while the app process is not running -- so a node is pure data: there are no listeners, no theme lookups and no live Image references in the serialized form.

All nodes share the styling in this class: padding, background color, corner radius, alignment within the parent, flexible weight, an optional fixed size and an optional action. An action is a plain string id (plus optional parameters) delivered to the handler registered with Surfaces.setActionHandler(...) when the user taps the node -- see SurfaceActionEvent.

All dimensions are in display-independent pixels (dips).

  • Constructor Details

    • SurfaceNode

      public SurfaceNode()
  • Method Details

    • setPadding

      public SurfaceNode setPadding(int all)

      Sets the same padding on all four sides.

      Parameters
      • all: padding in dips
      Returns

      this node, for chaining

    • setPadding

      public SurfaceNode setPadding(int top, int right, int bottom, int left)

      Sets the padding of each side individually.

      Parameters
      • top: top padding in dips
      • right: right padding in dips
      • bottom: bottom padding in dips
      • left: left padding in dips
      Returns

      this node, for chaining

    • setBackground

      public SurfaceNode setBackground(SurfaceColor color)

      Sets the background color of this node.

      Parameters
      • color: the background color
      Returns

      this node, for chaining

    • setCornerRadius

      public SurfaceNode setCornerRadius(int radius)

      Sets the corner radius applied to the node's background. May render square on Android versions below 12.

      Parameters
      • radius: the corner radius in dips
      Returns

      this node, for chaining

    • setAlignment

      public SurfaceNode setAlignment(SurfaceAlignment alignment)

      Sets this node's alignment within its parent. In a SurfaceBox all nine positions apply; in rows and columns only the cross-axis component is used.

      Parameters
      • alignment: the alignment
      Returns

      this node, for chaining

    • setWeight

      public SurfaceNode setWeight(int weight)

      Sets the flexible-space weight of this node within a row or column. Nodes with a weight share the leftover space of the parent proportionally; a weight of 0 (the default) sizes the node to its natural size.

      Parameters
      • weight: the relative weight, 0 for natural sizing
      Returns

      this node, for chaining

    • setSize

      public SurfaceNode setSize(int widthDips, int heightDips)

      Sets a fixed size for this node. A value of 0 (the default) keeps the natural size of the respective axis.

      Parameters
      • widthDips: fixed width in dips, 0 for natural width
      • heightDips: fixed height in dips, 0 for natural height
      Returns

      this node, for chaining

    • setAction

      public SurfaceNode setAction(String actionId)

      Assigns a tap action to this node. Tapping the node opens (or foregrounds) the app and delivers the action id to the handler registered with Surfaces.setActionHandler(...). Note that small iOS home-screen widgets only honor the action of the root node.

      Parameters
      • actionId: the app-defined action identifier
      Returns

      this node, for chaining

    • setAction

      public SurfaceNode setAction(String actionId, Map<String,Object> params)

      Assigns a tap action with parameters to this node. The parameter map may contain String, Number and Boolean values and is delivered verbatim with the SurfaceActionEvent.

      Parameters
      • actionId: the app-defined action identifier
      • params: parameters delivered with the action, may be null
      Returns

      this node, for chaining

    • getPaddingTop

      public int getPaddingTop()
      Returns the top padding in dips.
    • getPaddingRight

      public int getPaddingRight()
      Returns the right padding in dips.
    • getPaddingBottom

      public int getPaddingBottom()
      Returns the bottom padding in dips.
    • getPaddingLeft

      public int getPaddingLeft()
      Returns the left padding in dips.
    • getBackground

      public SurfaceColor getBackground()
      Returns the background color, or null.
    • getCornerRadius

      public int getCornerRadius()
      Returns the corner radius in dips.
    • getAlignment

      public SurfaceAlignment getAlignment()
      Returns the alignment within the parent, or null for the platform default.
    • getWeight

      public int getWeight()
      Returns the flexible-space weight, 0 when naturally sized.
    • getWidthDips

      public int getWidthDips()
      Returns the fixed width in dips, 0 when naturally sized.
    • getHeightDips

      public int getHeightDips()
      Returns the fixed height in dips, 0 when naturally sized.
    • getActionId

      public String getActionId()
      Returns the tap action id, or null.
    • getActionParams

      public Map<String,Object> getActionParams()
      Returns the tap action parameters, or null.