Record Class ComponentSnapshot

java.lang.Object
java.lang.Record
org.inspirenxe.strata.api.component.ComponentSnapshot
Record Components:
component - the live component this snapshot was taken of; never null
visible - whether the component was visible
enabled - whether the component was enabled
hovered - whether the pointer was over the component, and not over a descendant
pressed - whether a mouse button was held down that went down on the component
focused - whether the component had keyboard focus; always false for one that is not Focusable
margin - the component's margin; never null
minWidth - the component's minimum width
maxWidth - the component's maximum width
minHeight - the component's minimum height
maxHeight - the component's maximum height
horizontalAlignment - the component's horizontal alignment; never null
verticalAlignment - the component's vertical alignment; never null
bounds - the component's bounds, in the host's coordinates; never null
desiredWidth - the component's desired width
desiredHeight - the component's desired height
state - what the component's kind records about itself, or null if it records nothing

public record ComponentSnapshot(Component<?> component, boolean visible, boolean enabled, boolean hovered, boolean pressed, boolean focused, Insets margin, float minWidth, float maxWidth, float minHeight, float maxHeight, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Rect bounds, float desiredWidth, float desiredHeight, Object state) extends Record
The state of one component at the moment an event fired, before any handler or default behavior ran. Compare it with the live component, which component() returns, to see what the event changed. Input events and requests carry them, as SnapshotEvents.

A snapshot covers only the component itself. A container's snapshot holds the container's own state and nothing about its children; each child that was captured has a snapshot of its own.

Each field holds what the component's getter of the same name returned when the snapshot was taken, or for hover, press and focus, what the component's own code would have read. state() holds what the component's kind adds, such as a text box's text and caret: the built-in controls and panels record a nested State type (for example TextBox.State), and a CustomComponent records whatever its snapshotState hook returns.

Snapshots are immutable and stay valid after the event is delivered, unlike the event itself. They hold a reference to the live component, so keeping one keeps the component reachable.

  • Constructor Details

    • ComponentSnapshot

      public ComponentSnapshot(Component<?> component, boolean visible, boolean enabled, boolean hovered, boolean pressed, boolean focused, Insets margin, float minWidth, float maxWidth, float minHeight, float maxHeight, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Rect bounds, float desiredWidth, float desiredHeight, Object state)
      Checks the fields that must not be null.
  • Method Details

    • state

      public <S> Optional<S> state(Class<S> type)
      Returns state() as a given type.
      event.snapshot().state(TextBox.State.class).ifPresent(before -> ...);
      
      Type Parameters:
      S - the state type
      Parameters:
      type - the class the state is expected to be
      Returns:
      the state, or empty if there is none or it is not an instance of type
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • component

      public Component<?> component()
      Returns the value of the component record component.
      Returns:
      the value of the component record component
    • visible

      public boolean visible()
      Returns the value of the visible record component.
      Returns:
      the value of the visible record component
    • enabled

      public boolean enabled()
      Returns the value of the enabled record component.
      Returns:
      the value of the enabled record component
    • hovered

      public boolean hovered()
      Returns the value of the hovered record component.
      Returns:
      the value of the hovered record component
    • pressed

      public boolean pressed()
      Returns the value of the pressed record component.
      Returns:
      the value of the pressed record component
    • focused

      public boolean focused()
      Returns the value of the focused record component.
      Returns:
      the value of the focused record component
    • margin

      public Insets margin()
      Returns the value of the margin record component.
      Returns:
      the value of the margin record component
    • minWidth

      public float minWidth()
      Returns the value of the minWidth record component.
      Returns:
      the value of the minWidth record component
    • maxWidth

      public float maxWidth()
      Returns the value of the maxWidth record component.
      Returns:
      the value of the maxWidth record component
    • minHeight

      public float minHeight()
      Returns the value of the minHeight record component.
      Returns:
      the value of the minHeight record component
    • maxHeight

      public float maxHeight()
      Returns the value of the maxHeight record component.
      Returns:
      the value of the maxHeight record component
    • horizontalAlignment

      public HorizontalAlignment horizontalAlignment()
      Returns the value of the horizontalAlignment record component.
      Returns:
      the value of the horizontalAlignment record component
    • verticalAlignment

      public VerticalAlignment verticalAlignment()
      Returns the value of the verticalAlignment record component.
      Returns:
      the value of the verticalAlignment record component
    • bounds

      public Rect bounds()
      Returns the value of the bounds record component.
      Returns:
      the value of the bounds record component
    • desiredWidth

      public float desiredWidth()
      Returns the value of the desiredWidth record component.
      Returns:
      the value of the desiredWidth record component
    • desiredHeight

      public float desiredHeight()
      Returns the value of the desiredHeight record component.
      Returns:
      the value of the desiredHeight record component
    • state

      public Object state()
      Returns the value of the state record component.
      Returns:
      the value of the state record component