Gnome::Gtk4::Popover
Description
Gnome::Gtk4::Popover is a bubble-like context popup.
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 .set-pointing-to()
.
The position of a popover relative to the widget it is attached to can also be changed with .set-position()
By default, Gnome::Gtk4::Popover 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, .set-autohide()
may be called on it to tweak its behavior.
GtkPopover as menu replacement
Gnome::Gtk4::Popover is often used to replace menus. The best was to do this is to use the Gnome::Gtk4::PopoverMenu subclass which supports being populated from a Gnome::Gio::MenuModel with .new-from-model() in class Gnome::Gtk4::PopoverMenu
.
CSS nodes
Gnome::Gtk4::Popover has a main node with name popover, an arrow with name arrow, and another node for the content named contents. The popover node always gets the `.background` style class. It also gets the `.menu` style class if the popover is menu-like, e.g. is a Gnome::Gtk4::PopoverMenu.
Particular uses of Gnome::Gtk4::Popover, such as touch selection popups or magnifiers in Gnome::Gtk4::Entry or Gnome::Gtk4::TextView 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, Gnome::Gtk4::Popover 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.
Class initialization
new
:native-object
Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object :$native-object! )
new-popover
Creates a new Gnome::Gtk4::Popover.
method new-popover ( --> Gnome::Gtk4::Popover \)
Methods
get-autohide
Returns whether the popover is modal.
See .set-autohide()
for the implications of this.
method get-autohide (--> Bool )
Return value; True
if $popover
is modal.
get-cascade-popdown
Returns whether the popover will close after a modal child is closed.
method get-cascade-popdown (--> Bool )
Return value; True
if $popover
will close after a modal child..
get-child
Gets the child widget of $popover
.
method get-child (--> N-Object )
Return value; the child widget of $popover
.
get-has-arrow
Gets whether this popover is showing an arrow pointing at the widget that it is relative to.
method get-has-arrow (--> Bool )
Return value; whether the popover has an arrow.
get-mnemonics-visible
Gets whether mnemonics are visible.
method get-mnemonics-visible (--> Bool )
Return value; True
if mnemonics are supposed to be visible in this popover.
get-offset
Gets the offset previous set with .set-offset()()
.
method get-offset ( Array[Int] $x-offset, Array[Int] $y-offset )
$x-offset; (transfer ownership: full) a location for the x_offset.
$y-offset; (transfer ownership: full) a location for the y_offset.
get-pointing-to
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.
method get-pointing-to ( N-Object $rect --> Bool )
$rect; location to store the rectangle
Return value; True
if a rectangle to point to was set..
get-position
Returns the preferred position of $popover
.
method get-position (--> GtkPositionType )
Return value; The preferred position..
popdown
Pops $popover
down.
This may have the side-effect of closing a parent popover as well. See cascade-popdown.
method popdown ( )
popup
Pops $popover
up.
method popup ( )
present
Allocate a size for the Gnome::Gtk4::Popover.
This function needs to be called in size-allocate by widgets who have a Gnome::Gtk4::Popover as child. When using a layout manager, this is happening automatically.
To make a popover appear on screen, use .popup()
.
method present ( )
set-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.
method set-autohide ( Bool() $autohide )
$autohide;
True
to dismiss the popover on outside clicks.
set-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.
method set-cascade-popdown ( Bool() $cascade-popdown )
$cascade-popdown;
True
if the popover should follow a child closing.
set-child
Sets the child widget of $popover
.
method set-child ( N-Object() $child )
$child; the child widget.
set-default-widget
Sets the default widget of a Gnome::Gtk4::Popover.
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 Gnome::Gtk4::Popover.
method set-default-widget ( N-Object() $widget )
$widget; a child widget of
$popover
to set as the default, or undefined to unset the default widget for the popover.
set-has-arrow
Sets whether this popover should draw an arrow pointing at the widget it is relative to.
method set-has-arrow ( Bool() $has-arrow )
$has-arrow;
True
to draw an arrow.
set-mnemonics-visible
Sets whether mnemonics should be visible.
method set-mnemonics-visible ( Bool() $mnemonics-visible )
$mnemonics-visible; the new value.
set-offset
Sets the offset to use when calculating the position of the popover.
These values are used when preparing the Gnome::Gdk4::N-PopupLayout for positioning the popover.
method set-offset ( Int() $x-offset, Int() $y-offset )
$x-offset; the x offset to adjust the position by.
$y-offset; the y offset to adjust the position by.
set-pointing-to
Sets the rectangle that $popover
points to.
This is in the coordinate space of the $popover
parent.
method set-pointing-to ( N-Object $rect )
$rect; rectangle to point to
set-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 Gnome::Gtk4::Popover may choose to appear on the opposite side.
method set-position ( GtkPositionType $position )
$position; preferred popover position.
Signals
activate-default
Emitted whend the user activates the default widget.
This is a [keybinding signal](class.SignalAction.html).
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Popover :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Popover object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
closed
Emitted when the popover is closed.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::Popover :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::Popover object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.