EmojiChooser: Ensure always have a selected button
We were only selecting a section’s button if the adjustment y coord was within its heading, so scrolling slightly into it unchecked all buttons. This also fixes how we could end up with the first 2 selected, somehow. https://bugzilla.gnome.org/show_bug.cgi?id=787172
This commit is contained in:
@@ -404,38 +404,54 @@ populate_emoji_chooser (GtkEmojiChooser *chooser)
|
|||||||
g_bytes_unref (bytes);
|
g_bytes_unref (bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
update_state (EmojiSection *section,
|
|
||||||
double value)
|
|
||||||
{
|
|
||||||
GtkAllocation alloc = { 0, 0, 0, 20 };
|
|
||||||
|
|
||||||
if (section->heading)
|
|
||||||
gtk_widget_get_allocation (section->heading, &alloc);
|
|
||||||
|
|
||||||
if (alloc.y <= value && value < alloc.y + alloc.height)
|
|
||||||
gtk_widget_set_state_flags (section->button, GTK_STATE_FLAG_CHECKED, FALSE);
|
|
||||||
else
|
|
||||||
gtk_widget_unset_state_flags (section->button, GTK_STATE_FLAG_CHECKED);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
adj_value_changed (GtkAdjustment *adj,
|
adj_value_changed (GtkAdjustment *adj,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GtkEmojiChooser *chooser = data;
|
GtkEmojiChooser *chooser = data;
|
||||||
double value = gtk_adjustment_get_value (adj);
|
double value = gtk_adjustment_get_value (adj);
|
||||||
|
EmojiSection const *sections[] = {
|
||||||
|
&chooser->recent,
|
||||||
|
&chooser->people,
|
||||||
|
&chooser->body,
|
||||||
|
&chooser->nature,
|
||||||
|
&chooser->food,
|
||||||
|
&chooser->travel,
|
||||||
|
&chooser->activities,
|
||||||
|
&chooser->objects,
|
||||||
|
&chooser->symbols,
|
||||||
|
&chooser->flags,
|
||||||
|
};
|
||||||
|
EmojiSection const *select_section = sections[0];
|
||||||
|
gsize i;
|
||||||
|
|
||||||
update_state (&chooser->recent, value);
|
/* Figure out which section the current scroll position is within */
|
||||||
update_state (&chooser->people, value);
|
for (i = 0; i < G_N_ELEMENTS (sections); ++i)
|
||||||
update_state (&chooser->body, value);
|
{
|
||||||
update_state (&chooser->nature, value);
|
EmojiSection const *section = sections[i];
|
||||||
update_state (&chooser->food, value);
|
GtkAllocation alloc;
|
||||||
update_state (&chooser->travel, value);
|
|
||||||
update_state (&chooser->activities, value);
|
if (section->heading)
|
||||||
update_state (&chooser->objects, value);
|
gtk_widget_get_allocation (section->heading, &alloc);
|
||||||
update_state (&chooser->symbols, value);
|
else
|
||||||
update_state (&chooser->flags, value);
|
gtk_widget_get_allocation (section->box, &alloc);
|
||||||
|
|
||||||
|
if (value < alloc.y)
|
||||||
|
break;
|
||||||
|
|
||||||
|
select_section = section;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Un/Check the section buttons accordingly */
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (sections); ++i)
|
||||||
|
{
|
||||||
|
EmojiSection const *section = sections[i];
|
||||||
|
|
||||||
|
if (section == select_section)
|
||||||
|
gtk_widget_set_state_flags (section->button, GTK_STATE_FLAG_CHECKED, FALSE);
|
||||||
|
else
|
||||||
|
gtk_widget_unset_state_flags (section->button, GTK_STATE_FLAG_CHECKED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|||||||
Reference in New Issue
Block a user