gridview: Add some helpers
Add helper functions to get the section of an item and to computes the column for an item, based on sections and the current number of columns.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "gtkmultiselection.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtksectionmodel.h"
|
||||
|
||||
/* Maximum number of list items created by the gridview.
|
||||
* For debugging, you can set this to G_MAXUINT to ensure
|
||||
@@ -434,6 +435,51 @@ gtk_grid_view_get_allocation (GtkListBase *base,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Returns the section that position falls into
|
||||
*/
|
||||
static void
|
||||
get_section_for_position (GtkGridView *self,
|
||||
unsigned int position,
|
||||
unsigned int *section_start,
|
||||
unsigned int *section_end)
|
||||
{
|
||||
GListModel *model;
|
||||
unsigned int start, end;
|
||||
|
||||
model = G_LIST_MODEL (gtk_list_item_manager_get_model (self->item_manager));
|
||||
|
||||
if (!gtk_list_item_manager_get_has_sections (self->item_manager))
|
||||
{
|
||||
start = 0;
|
||||
end = g_list_model_get_n_items (model);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_section_model_get_section (GTK_SECTION_MODEL (model), position, &start, &end);
|
||||
}
|
||||
|
||||
if (section_start)
|
||||
*section_start = start;
|
||||
if (section_end)
|
||||
*section_end = end;
|
||||
}
|
||||
|
||||
/* Returns the column that the given item will fall in, taking
|
||||
* sections into account. Note that this depends on whether
|
||||
* we are currently showing sections, and on the number of
|
||||
* columns that the grid is allocating.
|
||||
*/
|
||||
static unsigned int
|
||||
get_column_for_position (GtkGridView *self,
|
||||
unsigned int position)
|
||||
{
|
||||
unsigned int start;
|
||||
|
||||
get_section_for_position (self, position, &start, NULL);
|
||||
|
||||
return (position - start) % self->n_columns;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_grid_view_get_position_from_allocation (GtkListBase *base,
|
||||
int x,
|
||||
|
||||
Reference in New Issue
Block a user