Class PopupLayout

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class PopupLayout extends ProxyInstance

Contains information that is necessary position a Popup relative to its parent.

The positioning requires a negotiation with the windowing system, since it depends on external constraints, such as the position of the parent surface, and the screen dimensions.

The basic ingredients are a rectangle on the parent surface, and the anchor on both that rectangle and the popup. The anchors specify a side or corner to place next to each other.

Popup anchors

For cases where placing the anchors next to each other would make the popup extend offscreen, the layout includes some hints for how to resolve this problem. The hints may suggest to flip the anchor position to the other side, or to 'slide' the popup along a side, or to resize it.

Flipping popups

Sliding popups

These hints may be combined.

Ultimatively, it is up to the windowing system to determine the position and size of the popup. You can learn about the result by calling Popup.getPositionX(), Popup.getPositionY(), Popup.getRectAnchor() and Popup.getSurfaceAnchor() after the popup has been presented. This can be used to adjust the rendering. For example, GtkPopover changes its arrow position accordingly. But you have to be careful avoid changing the size of the popover, or it has to be presented again.

  • Constructor Details

    • PopupLayout

      public PopupLayout(MemorySegment address)
      Create a PopupLayout proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • PopupLayout

      public PopupLayout(Rectangle anchorRect, Gravity rectAnchor, Gravity surfaceAnchor)

      Create a popup layout description.

      Used together with Popup.present(int, int, PopupLayout) to describe how a popup surface should be placed and behave on-screen.

      anchorRect is relative to the top-left corner of the surface's parent. rectAnchor and surfaceAnchor determine anchor points on anchorRect and surface to pin together.

      The position of anchorRect's anchor point can optionally be offset using setOffset(int, int), which is equivalent to offsetting the position of surface.

      Parameters:
      anchorRect - the anchor rectangle to align surface with
      rectAnchor - the point on anchorRect to align with surface's anchor point
      surfaceAnchor - the point on surface to align with rect's anchor point
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the PopupLayout class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • copy

      public PopupLayout copy()
      Makes a copy of layout.
      Returns:
      a copy of layout.
    • equal

      public boolean equal(PopupLayout other)
      Check whether this PopupLayout and other has identical layout properties.
      Parameters:
      other - another popup layout
      Returns:
      true if this PopupLayout and other have identical layout properties, otherwise false.
    • getAnchorHints

      public Set<AnchorHints> getAnchorHints()
      Get the anchor hints.
      Returns:
      the anchor hints
    • getAnchorRect

      public Rectangle getAnchorRect()
      Get the anchor rectangle.
      Returns:
      The anchor rectangle
    • getOffset

      public void getOffset(Out<Integer> dx, Out<Integer> dy)
      Retrieves the offset for the anchor rectangle.
      Parameters:
      dx - return location for the delta X coordinate
      dy - return location for the delta Y coordinate
    • getRectAnchor

      public Gravity getRectAnchor()
      Returns the anchor position on the anchor rectangle.
      Returns:
      the anchor on the anchor rectangle.
    • getShadowWidth

      public void getShadowWidth(Out<Integer> left, Out<Integer> right, Out<Integer> top, Out<Integer> bottom)
      Obtains the shadow widths of this layout.
      Parameters:
      left - return location for the left shadow width
      right - return location for the right shadow width
      top - return location for the top shadow width
      bottom - return location for the bottom shadow width
      Since:
      4.2
    • getSurfaceAnchor

      public Gravity getSurfaceAnchor()
      Returns the anchor position on the popup surface.
      Returns:
      the anchor on the popup surface.
    • ref

      public PopupLayout ref()
      Increases the reference count of value.
      Returns:
      the same this PopupLayout
    • setAnchorHints

      public void setAnchorHints(Set<AnchorHints> anchorHints)

      Set new anchor hints.

      The set anchorHints determines how surface will be moved if the anchor points cause it to move off-screen. For example, GDK_ANCHOR_FLIP_X will replace GDK_GRAVITY_NORTH_WEST with GDK_GRAVITY_NORTH_EAST and vice versa if surface extends beyond the left or right edges of the monitor.

      Parameters:
      anchorHints - the new anchor hints
    • setAnchorHints

      public void setAnchorHints(AnchorHints... anchorHints)

      Set new anchor hints.

      The set anchorHints determines how surface will be moved if the anchor points cause it to move off-screen. For example, GDK_ANCHOR_FLIP_X will replace GDK_GRAVITY_NORTH_WEST with GDK_GRAVITY_NORTH_EAST and vice versa if surface extends beyond the left or right edges of the monitor.

      Parameters:
      anchorHints - the new anchor hints
    • setAnchorRect

      public void setAnchorRect(Rectangle anchorRect)
      Set the anchor rectangle.
      Parameters:
      anchorRect - the new anchor rectangle
    • setOffset

      public void setOffset(int dx, int dy)
      Offset the position of the anchor rectangle with the given delta.
      Parameters:
      dx - x delta to offset the anchor rectangle with
      dy - y delta to offset the anchor rectangle with
    • setRectAnchor

      public void setRectAnchor(Gravity anchor)
      Set the anchor on the anchor rectangle.
      Parameters:
      anchor - the new rect anchor
    • setShadowWidth

      public void setShadowWidth(int left, int right, int top, int bottom)

      Sets the shadow width of the popup.

      The shadow width corresponds to the part of the computed surface size that would consist of the shadow margin surrounding the window, would there be any.

      Parameters:
      left - width of the left part of the shadow
      right - width of the right part of the shadow
      top - height of the top part of the shadow
      bottom - height of the bottom part of the shadow
      Since:
      4.2
    • setSurfaceAnchor

      public void setSurfaceAnchor(Gravity anchor)
      Set the anchor on the popup surface.
      Parameters:
      anchor - the new popup surface anchor
    • unref

      public void unref()
      Decreases the reference count of value.