Merge branch 'matthiasc/for-main' into 'main'

emojichooser: Stop using gtk_widget_get_allocation

See merge request GNOME/gtk!5749
This commit is contained in:
Matthias Clasen
2023-03-30 02:45:56 +00:00

View File

@@ -260,14 +260,18 @@ scroll_to_section (EmojiSection *section)
{
GtkEmojiChooser *chooser;
GtkAdjustment *adj;
GtkAllocation alloc = { 0, 0, 0, 0 };
graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 0, 0);
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (section->box, GTK_TYPE_EMOJI_CHOOSER));
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
if (section->heading)
gtk_widget_get_allocation (section->heading, &alloc);
gtk_adjustment_animate_to_value (adj, alloc.y - BOX_SPACE);
{
if (!gtk_widget_compute_bounds (section->heading, gtk_widget_get_parent (section->heading), &bounds))
graphene_rect_init (&bounds, 0, 0, 0, 0);
}
gtk_adjustment_animate_to_value (adj, bounds.origin.y - BOX_SPACE);
}
static void
@@ -275,16 +279,17 @@ scroll_to_child (GtkWidget *child)
{
GtkEmojiChooser *chooser;
GtkAdjustment *adj;
GtkAllocation alloc;
graphene_point_t p;
double value;
double page_size;
graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 0, 0);
chooser = GTK_EMOJI_CHOOSER (gtk_widget_get_ancestor (child, GTK_TYPE_EMOJI_CHOOSER));
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
gtk_widget_get_allocation (child, &alloc);
if (!gtk_widget_compute_bounds (child, gtk_widget_get_parent (child), &bounds))
graphene_rect_init (&bounds, 0, 0, 0, 0);
value = gtk_adjustment_get_value (adj);
page_size = gtk_adjustment_get_page_size (adj);
@@ -295,8 +300,8 @@ scroll_to_child (GtkWidget *child)
if (p.y < value)
gtk_adjustment_animate_to_value (adj, p.y);
else if (p.y + alloc.height >= value + page_size)
gtk_adjustment_animate_to_value (adj, value + ((p.y + alloc.height) - (value + page_size)));
else if (p.y + bounds.size.height >= value + page_size)
gtk_adjustment_animate_to_value (adj, value + ((p.y + bounds.size.height) - (value + page_size)));
}
static void
@@ -794,17 +799,21 @@ adj_value_changed (GtkAdjustment *adj,
for (i = 0; i < G_N_ELEMENTS (sections); ++i)
{
EmojiSection const *section = sections[i];
GtkAllocation alloc;
GtkWidget *child;
graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 0, 0);
if (!gtk_widget_get_visible (section->box))
continue;
if (section->heading)
gtk_widget_get_allocation (section->heading, &alloc);
child = section->heading;
else
gtk_widget_get_allocation (section->box, &alloc);
child = section->box;
if (value < alloc.y - BOX_SPACE)
if (!gtk_widget_compute_bounds (child, gtk_widget_get_parent (child), &bounds))
graphene_rect_init (&bounds, 0, 0, 0, 0);
if (value < bounds.origin.y - BOX_SPACE)
break;
select_section = section;
@@ -1141,10 +1150,10 @@ keynav_failed (GtkWidget *box,
GtkWidget *focus;
GtkWidget *child;
GtkWidget *sibling;
GtkAllocation alloc;
int i;
int column;
int child_x;
graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 0, 0);
focus = gtk_root_get_focus (gtk_widget_get_root (box));
if (focus == NULL)
@@ -1161,14 +1170,15 @@ keynav_failed (GtkWidget *box,
if (!gtk_widget_get_child_visible (sibling))
continue;
gtk_widget_get_allocation (sibling, &alloc);
if (!gtk_widget_compute_bounds (sibling, box, &bounds))
graphene_rect_init (&bounds, 0, 0, 0, 0);
if (alloc.x < child_x)
if (bounds.origin.x < child_x)
column = 0;
else
column++;
child_x = alloc.x;
child_x = (int) bounds.origin.x;
if (sibling == child)
break;
@@ -1192,14 +1202,15 @@ keynav_failed (GtkWidget *box,
if (!gtk_widget_get_child_visible (sibling))
continue;
gtk_widget_get_allocation (sibling, &alloc);
if (!gtk_widget_compute_bounds (sibling, next->box, &bounds))
graphene_rect_init (&bounds, 0, 0, 0, 0);
if (alloc.x < child_x)
if (bounds.origin.x < child_x)
i = 0;
else
i++;
child_x = alloc.x;
child_x = (int) bounds.origin.x;
if (i == column)
{
@@ -1228,14 +1239,15 @@ keynav_failed (GtkWidget *box,
if (!gtk_widget_get_child_visible (sibling))
continue;
gtk_widget_get_allocation (sibling, &alloc);
if (!gtk_widget_compute_bounds (sibling, next->box, &bounds))
graphene_rect_init (&bounds, 0, 0, 0, 0);
if (alloc.x < child_x)
if (bounds.origin.x < child_x)
i = 0;
else
i++;
child_x = alloc.x;
child_x = (int) bounds.origin.x;
if (i == column)
child = sibling;