mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 13:41:07 +00:00
popover: allow setting popup layout offset
Currently there is no way to alter the offset of the popup when positioning with GdkPopupLayout. This makes using the popup difficult for scenarios like completion windows where you may need to offset the window by a given amount for aligning text. gtk_popover_set_offset() allows setting these values and are analagous to the function of the same name for GdkPopupLayout.
This commit is contained in:
parent
7625ccd6fa
commit
4d88e3af17
@ -6270,6 +6270,8 @@ gtk_popover_set_autohide
|
||||
gtk_popover_get_autohide
|
||||
gtk_popover_set_has_arrow
|
||||
gtk_popover_get_has_arrow
|
||||
gtk_popover_set_offset
|
||||
gtk_popover_get_offset
|
||||
gtk_popover_set_default_widget
|
||||
<SUBSECTION Standard>
|
||||
GTK_TYPE_POPOVER
|
||||
|
@ -150,6 +150,9 @@ typedef struct {
|
||||
gboolean mnemonics_visible;
|
||||
gboolean disable_auto_mnemonics;
|
||||
|
||||
int x_offset;
|
||||
int y_offset;
|
||||
|
||||
guint mnemonics_display_timeout_id;
|
||||
|
||||
GtkWidget *child;
|
||||
@ -550,6 +553,9 @@ create_popup_layout (GtkPopover *popover)
|
||||
surface_anchor);
|
||||
gdk_popup_layout_set_anchor_hints (layout, anchor_hints);
|
||||
|
||||
if (priv->x_offset || priv->y_offset)
|
||||
gdk_popup_layout_set_offset (layout, priv->x_offset, priv->y_offset);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@ -2162,3 +2168,56 @@ gtk_popover_disable_auto_mnemonics (GtkPopover *popover)
|
||||
|
||||
priv->disable_auto_mnemonics = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_popover_set_offset:
|
||||
* @popover: a #GtkPopover
|
||||
* @x_offset: the x offset to adjust the position by
|
||||
* @y_offset: the y offset to adjust the position by
|
||||
*
|
||||
* Sets the offset to use when calculating the position of the popover.
|
||||
*
|
||||
* These values are used when preparing the #GtkPopupLayout for positioning
|
||||
* the popover.
|
||||
*/
|
||||
void
|
||||
gtk_popover_set_offset (GtkPopover *popover,
|
||||
int x_offset,
|
||||
int y_offset)
|
||||
{
|
||||
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
||||
|
||||
g_return_if_fail (GTK_IS_POPOVER (popover));
|
||||
|
||||
if (priv->x_offset != x_offset || priv->y_offset != y_offset)
|
||||
{
|
||||
priv->x_offset = x_offset;
|
||||
priv->y_offset = y_offset;
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (popover));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_popover_get_offset:
|
||||
* @popover: a #GtkPopover
|
||||
* @x_offset: (out) (nullable): a location for the x_offset
|
||||
* @y_offset: (out) (nullable): a location for the y_offset
|
||||
*
|
||||
* Gets the offset previous set with gtk_popover_set_offset().
|
||||
*/
|
||||
void
|
||||
gtk_popover_get_offset (GtkPopover *popover,
|
||||
int *x_offset,
|
||||
int *y_offset)
|
||||
{
|
||||
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
|
||||
|
||||
g_return_if_fail (GTK_IS_POPOVER (popover));
|
||||
|
||||
if (x_offset)
|
||||
*x_offset = priv->x_offset;
|
||||
|
||||
if (y_offset)
|
||||
*y_offset = priv->y_offset;
|
||||
}
|
||||
|
@ -103,6 +103,15 @@ void gtk_popover_popup (GtkPopover *popover);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_popdown (GtkPopover *popover);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_offset (GtkPopover *popover,
|
||||
int x_offset,
|
||||
int y_offset);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_get_offset (GtkPopover *popover,
|
||||
int *x_offset,
|
||||
int *y_offset);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_popover_set_default_widget (GtkPopover *popover,
|
||||
GtkWidget *widget);
|
||||
|
Loading…
Reference in New Issue
Block a user