Merge branch 'adaptive-emojichooser' into 'master'

Adaptive emojichooser

Closes #3307

See merge request GNOME/gtk!2989
This commit is contained in:
Matthias Clasen 2021-01-26 05:07:46 +00:00
commit 20895d6f3f
3 changed files with 41 additions and 16 deletions

View File

@ -1081,16 +1081,35 @@ keynav_failed (GtkWidget *box,
GtkEmojiChooser *chooser)
{
EmojiSection *next;
GtkWidget *focus;
GtkWidget *focus;
GtkWidget *child;
GtkWidget *sibling;
int i;
int column;
int n_columns = 7;
int child_x;
focus = gtk_root_get_focus (gtk_widget_get_root (box));
if (focus == NULL)
return FALSE;
/* determine the number of columns */
child_x = -1;
for (i = 0; i < 20; i++)
{
GtkAllocation alloc;
gtk_widget_get_allocation (GTK_WIDGET (gtk_flow_box_get_child_at_index (GTK_FLOW_BOX (box), i)),
&alloc);
if (alloc.x > child_x)
child_x = alloc.x;
else
{
n_columns = i;
break;
}
}
child = gtk_widget_get_ancestor (focus, GTK_TYPE_EMOJI_CHOOSER_CHILD);
i = 0;
@ -1099,7 +1118,7 @@ keynav_failed (GtkWidget *box,
sibling = gtk_widget_get_next_sibling (sibling))
i++;
column = i % 7;
column = i % n_columns;
if (direction == GTK_DIR_DOWN)
{
@ -1131,7 +1150,7 @@ keynav_failed (GtkWidget *box,
sibling;
sibling = gtk_widget_get_next_sibling (sibling), i++)
{
if ((i % 7) == column)
if ((i % n_columns) == column)
child = sibling;
}
if (child)

View File

@ -360,7 +360,9 @@ did_flip_vertically (GdkGravity original_gravity,
static void
update_popover_layout (GtkPopover *popover,
GdkPopupLayout *layout)
GdkPopupLayout *layout,
int width,
int height)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
GdkRectangle final_rect;
@ -413,7 +415,9 @@ update_popover_layout (GtkPopover *popover,
break;
}
if (priv->final_position != position)
if (priv->final_position != position ||
priv->final_rect.width != width ||
priv->final_rect.height != height)
{
gtk_widget_queue_allocate (GTK_WIDGET (popover));
g_clear_pointer (&priv->arrow_render_node, gsk_render_node_unref);
@ -545,9 +549,9 @@ create_popup_layout (GtkPopover *popover)
g_assert_not_reached ();
}
layout = gdk_popup_layout_new (&rect,
parent_anchor,
surface_anchor);
anchor_hints |= GDK_ANCHOR_RESIZE;
layout = gdk_popup_layout_new (&rect, parent_anchor, surface_anchor);
gdk_popup_layout_set_anchor_hints (layout, anchor_hints);
if (priv->x_offset || priv->y_offset)
@ -560,17 +564,17 @@ static gboolean
present_popup (GtkPopover *popover)
{
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
GtkRequisition req;
GtkRequisition nat;
GdkPopupLayout *layout;
layout = create_popup_layout (popover);
gtk_widget_get_preferred_size (GTK_WIDGET (popover), NULL, &req);
gtk_widget_get_preferred_size (GTK_WIDGET (popover), NULL, &nat);
if (gdk_popup_present (GDK_POPUP (priv->surface),
MAX (req.width, 1),
MAX (req.height, 1),
nat.width, nat.height,
layout))
{
update_popover_layout (popover, layout);
update_popover_layout (popover, layout, nat.width, nat.height);
return TRUE;
}
@ -631,7 +635,7 @@ gtk_popover_native_layout (GtkNative *native,
GtkPopoverPrivate *priv = gtk_popover_get_instance_private (popover);
GtkWidget *widget = GTK_WIDGET (popover);
update_popover_layout (popover, gdk_popup_layout_ref (priv->layout));
update_popover_layout (popover, gdk_popup_layout_ref (priv->layout), width, height);
if (gtk_widget_needs_allocate (widget))
{

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<template class="GtkEmojiChooser" parent="GtkPopover">
<property name="height-request">410</property>
<style>
<class name="emoji-picker"/>
</style>
@ -33,7 +34,6 @@
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="vexpand">1</property>
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">250</property>
<style>
<class name="view"/>
</style>
@ -217,7 +217,9 @@
</object>
</child>
<child>
<object class="GtkBox">
<object class="GtkFlowBox">
<property name="min-children-per-line">3</property>
<property name="max-children-per-line">10</property>
<style>
<class name="emoji-toolbar"/>
</style>