[gnome-calendar] week-grid : seperate week's events overlaps.
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] week-grid : seperate week's events overlaps.
- Date: Tue, 11 Jul 2017 01:46:15 +0000 (UTC)
commit 1360fe01e88f2761d8030388fe2c2993a145f404
Author: Abdullahi Usman <abdullahismn7 gmail com>
Date: Mon Jul 10 11:43:36 2017 +0100
week-grid : seperate week's events overlaps.
The week view can display mutilple events that can partly or fully span
same time ranges.
But week view fails to make correct assumption about the width of events when
two or more events span some time ranges in which these events also span some
time ranges with other events, and whereby the number of these other events
that they span time ranges with does not coincide with the number of the events
that the other event also span. Week view ended up calculating cells that
appears horizontally jointed up. Also int16_compare() does not dereference the
pointer from g_ptr_array_sort() correctly and that makes it sort events
incorrectly and hence making events appears vertically jointed up.
If an event have other events in which they span some time, we calcuate its width
by taking into consideration of all the events that the other event may span
time with. The event that has the higher number of time spans is considered.
We also save and retrieve our positions using UINT_TO_POINTER and POINTER_TO_UINT()
respectively, and then dereference the pointer from g_ptr_array_sort() correctly.
https://bugzilla.gnome.org/show_bug.cgi?id=777416
src/views/gcal-week-grid.c | 41 +++++++++++++++++++++++++++++++++++------
1 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/src/views/gcal-week-grid.c b/src/views/gcal-week-grid.c
index be4182f..28d6d5d 100644
--- a/src/views/gcal-week-grid.c
+++ b/src/views/gcal-week-grid.c
@@ -184,10 +184,10 @@ get_event_range (GcalWeekGrid *self,
}
static inline gint
-int16_compare (gconstpointer a,
- gconstpointer b)
+uint16_compare (gconstpointer a,
+ gconstpointer b)
{
- return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b);
+ return GPOINTER_TO_UINT (*(gint*)a) - GPOINTER_TO_UINT (*(gint*)b);
}
static inline guint
@@ -204,7 +204,7 @@ get_event_index (GcalRangeTree *tree,
if (!array)
return 0;
- g_ptr_array_sort (array, int16_compare);
+ g_ptr_array_sort (array, uint16_compare);
for (i = 0; array && i < array->len; i++)
{
@@ -235,6 +235,35 @@ count_overlaps_at_range (GcalRangeTree *self,
n_events = gcal_range_tree_count_entries_at_range (self, i, i + 1);
+ if (n_events == 0)
+ break;
+
+ counter = MAX (counter, n_events);
+ }
+
+ return counter;
+}
+
+static guint
+count_overlaps_of_event (GcalRangeTree *self,
+ guint16 day_start,
+ guint16 day_end,
+ guint16 event_start,
+ guint16 event_end)
+{
+ guint64 i, counter;
+
+ counter = count_overlaps_at_range (self, event_start, day_end);
+
+ for (i = event_start; i > day_start; i--)
+ {
+ guint n_events;
+
+ n_events = gcal_range_tree_count_entries_at_range (self, i - 1, i);
+
+ if (n_events == 0)
+ break;
+
counter = MAX (counter, n_events);
}
@@ -652,7 +681,7 @@ gcal_week_grid_size_allocate (GtkWidget *widget,
context = gtk_widget_get_style_context (event_widget);
/* The total number of events available in this range */
- events_at_range = count_overlaps_at_range (self->events, data->start, data->end);
+ events_at_range = count_overlaps_of_event (self->events, day_start, day_end, data->start,
data->end);
/* The real horizontal position of this event */
widget_index = get_event_index (overlaps, data->start, data->end);
@@ -689,7 +718,7 @@ gcal_week_grid_size_allocate (GtkWidget *widget,
gcal_range_tree_add_range (overlaps,
data->start,
data->end,
- GINT_TO_POINTER (widget_index));
+ GUINT_TO_POINTER (widget_index));
}
g_clear_pointer (&widgets_data, g_ptr_array_unref);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]