Class Popover

All Implemented Interfaces:
PointerInterface
Direct Known Subclasses:
EmojiChooser, PopoverMenu

public class Popover extends Widget
`GtkPopover` is a bubble-like context popup.

![An example GtkPopover](popover.png)

It is primarily meant to provide context-dependent information
or options. Popovers are attached to a parent widget. By default,
they point to the whole widget area, although this behavior can be
changed with [method@Gtk.Popover.set_pointing_to].

The position of a popover relative to the widget it is attached to
can also be changed with [method@Gtk.Popover.set_position]

By default, `GtkPopover` performs a grab, in order to ensure input
events get redirected to it while it is shown, and also so the popover
is dismissed in the expected situations (clicks outside the popover,
or the Escape key being pressed). If no such modal behavior is desired
on a popover, [method@Gtk.Popover.set_autohide] may be called on it to
tweak its behavior.

## GtkPopover as menu replacement

`GtkPopover` is often used to replace menus. The best was to do this
is to use the [class@Gtk.PopoverMenu] subclass which supports being
populated from a `GMenuModel` with [ctor@Gtk.PopoverMenu.new_from_model].

```xml
<section>
<attribute name="display-hint">horizontal-buttons</attribute>
<item>
<attribute name="label">Cut</attribute>
<attribute name="action">app.cut</attribute>
<attribute name="verb-icon">edit-cut-symbolic</attribute>
</item>
<item>
<attribute name="label">Copy</attribute>
<attribute name="action">app.copy</attribute>
<attribute name="verb-icon">edit-copy-symbolic</attribute>
</item>
<item>
<attribute name="label">Paste</attribute>
<attribute name="action">app.paste</attribute>
<attribute name="verb-icon">edit-paste-symbolic</attribute>
</item>
</section>
```

# CSS nodes

```
popover[.menu]
├── arrow
╰── contents.background
╰── <child>
```

The contents child node always gets the .background style class
and the popover itself gets the .menu style class if the popover
is menu-like (i.e. `GtkPopoverMenu`).

Particular uses of `GtkPopover`, such as touch selection popups or
magnifiers in `GtkEntry` or `GtkTextView` get style classes like
.touch-selection or .magnifier to differentiate from plain popovers.

When styling a popover directly, the popover node should usually
not have any background. The visible part of the popover can have
a shadow. To specify it in CSS, set the box-shadow of the contents node.

Note that, in order to accomplish appropriate arrow visuals, `GtkPopover`
uses custom drawing for the arrow node. This makes it possible for the
arrow to change its shape dynamically, but it also limits the possibilities
of styling it using CSS. In particular, the arrow gets drawn over the
content node's border and shadow, so they look like one shape, which
means that the border width of the content node and the arrow node should
be the same. The arrow also does not support any border shape other than
solid, no border-radius, only one border width (border-bottom-width is
used) and no box-shadow.

https://docs.gtk.org/gtk4/class.Popover.html

  • Field Details

  • Constructor Details

    • Popover

      public Popover(PointerContainer pointer)
    • Popover

      public Popover()
      Creates a new `GtkPopover`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • getAutohide

      public boolean getAutohide()
      Returns whether the popover is modal.

      See [method@Gtk.Popover.set_autohide] for the
      implications of this.
      Returns:
      %TRUE if @popover is modal
    • getCascadePopdown

      public boolean getCascadePopdown()
      Returns whether the popover will close after a modal child is closed.
      Returns:
      %TRUE if @popover will close after a modal child.
    • getChild

      public Widget getChild()
      Gets the child widget of @popover.
      Returns:
      the child widget of @popover
    • getHasArrow

      public boolean getHasArrow()
      Gets whether this popover is showing an arrow
      pointing at the widget that it is relative to.
      Returns:
      whether the popover has an arrow
    • getMnemonicsVisible

      public boolean getMnemonicsVisible()
      Gets whether mnemonics are visible.
      Returns:
      %TRUE if mnemonics are supposed to be visible in this popover
    • getOffset

      public void getOffset(@Nullable Int x_offset, @Nullable Int y_offset)
      Gets the offset previous set with gtk_popover_set_offset().
      Parameters:
      x_offset - a location for the x_offset
      y_offset - a location for the y_offset
    • getPointingTo

      public boolean getPointingTo(@Nonnull Rectangle rect)
      Gets the rectangle that the popover points to.

      If a rectangle to point to has been set, this function will
      return %TRUE and fill in @rect with such rectangle, otherwise
      it will return %FALSE and fill in @rect with the parent
      widget coordinates.
      Parameters:
      rect - location to store the rectangle
      Returns:
      %TRUE if a rectangle to point to was set.
    • getPosition

      public int getPosition()
      Returns the preferred position of @popover.
      Returns:
      The preferred position.
    • popdown

      public void popdown()
      Pops @popover down.

      This may have the side-effect of closing a parent popover
      as well. See [property@Gtk.Popover:cascade-popdown].
    • popup

      public void popup()
      Pops @popover up.
    • present

      public void present()
      Presents the popover to the user.
    • setAutohide

      public void setAutohide(boolean autohide)
      Sets whether @popover is modal.

      A modal popover will grab the keyboard focus on it when being
      displayed. Focus will wrap around within the popover. Clicking
      outside the popover area or pressing Esc will dismiss the popover.

      Called this function on an already showing popup with a new
      autohide value different from the current one, will cause the
      popup to be hidden.
      Parameters:
      autohide - %TRUE to dismiss the popover on outside clicks
    • setCascadePopdown

      public void setCascadePopdown(boolean cascade_popdown)
      If @cascade_popdown is %TRUE, the popover will be
      closed when a child modal popover is closed.

      If %FALSE, @popover will stay visible.
      Parameters:
      cascade_popdown - %TRUE if the popover should follow a child closing
    • setChild

      public void setChild(@Nullable Widget child)
      Sets the child widget of @popover.
      Parameters:
      child - the child widget
    • setDefaultWidget

      public void setDefaultWidget(@Nullable Widget widget)
      Sets the default widget of a `GtkPopover`.

      The default widget is the widget that’s activated when the user
      presses Enter in a dialog (for example). This function sets or
      unsets the default widget for a `GtkPopover`.
      Parameters:
      widget - a child widget of @popover to set as the default, or %NULL to unset the default widget for the popover
    • setHasArrow

      public void setHasArrow(boolean has_arrow)
      Sets whether this popover should draw an arrow
      pointing at the widget it is relative to.
      Parameters:
      has_arrow - %TRUE to draw an arrow
    • setMnemonicsVisible

      public void setMnemonicsVisible(boolean mnemonics_visible)
      Sets whether mnemonics should be visible.
      Parameters:
      mnemonics_visible - the new value
    • setOffset

      public void setOffset(int x_offset, int y_offset)
      Sets the offset to use when calculating the position
      of the popover.

      These values are used when preparing the [struct@Gdk.PopupLayout]
      for positioning the popover.
      Parameters:
      x_offset - the x offset to adjust the position by
      y_offset - the y offset to adjust the position by
    • setPointingTo

      public void setPointingTo(@Nullable Rectangle rect)
      Sets the rectangle that @popover points to.

      This is in the coordinate space of the @popover parent.
      Parameters:
      rect - rectangle to point to
    • setPosition

      public void setPosition(int position)
      Sets the preferred position for @popover to appear.

      If the @popover is currently visible, it will be immediately
      updated.

      This preference will be respected where possible, although
      on lack of space (eg. if close to the window edges), the
      `GtkPopover` may choose to appear on the opposite side.
      Parameters:
      position - preferred popover position
    • onActivateDefault

      public SignalHandler onActivateDefault(Popover.OnActivateDefault signal)
      Connect to signal "activate-default".
      See Popover.OnActivateDefault.onActivateDefault() for signal description.
      Field SIGNAL_ON_ACTIVATE_DEFAULT contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onClosed

      public SignalHandler onClosed(Popover.OnClosed signal)
      Connect to signal "closed".
      See Popover.OnClosed.onClosed() for signal description.
      Field SIGNAL_ON_CLOSED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • asNative

      public Native asNative()
      Implements interface Native. Call this to get access to interface functions.
      Returns:
      Native
    • asShortcutManager

      public ShortcutManager asShortcutManager()
      Implements interface ShortcutManager. Call this to get access to interface functions.
      Returns:
      ShortcutManager
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()