[gnome-calendar/wip/pandusonu/week-view] week-view: smoothly scroll the grid when moving to today
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/pandusonu/week-view] week-view: smoothly scroll the grid when moving to today
- Date: Wed, 14 Dec 2016 19:00:59 +0000 (UTC)
commit e8906c9e04fc22a595f06f8fec4463c695d62082
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Tue Dec 13 15:13:52 2016 -0200
week-view: smoothly scroll the grid when moving to today
src/views/gcal-week-view.c | 35 ++++++++++++++++++++++++++++-------
1 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 6dbee22..0263a07 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -68,6 +68,8 @@ struct _GcalWeekView
icaltimetype *current_date;
GcalManager *manager; /* weak referenced */
+ guint scroll_grid_timeout_id;
+
gint clicked_cell;
};
@@ -132,24 +134,27 @@ on_event_activated (GcalWeekView *self,
}
/* Auxiliary methods */
-static void
+static gboolean
update_grid_scroll_position (GcalWeekView *self)
{
- g_autoptr(GDateTime) now, week_start, week_end;
+ g_autoptr(GDateTime) week_start = NULL;
+ g_autoptr(GDateTime) week_end = NULL;
+ g_autoptr(GDateTime) now = NULL;
GtkAdjustment *vadjustment;
gdouble minutes, real_value;
gdouble max, page, page_increment, value;
+ /* While the scrolled window is not mapped, we keep waiting */
+ if (!gtk_widget_get_mapped (self->scrolled_window))
+ return G_SOURCE_CONTINUE;
+
now = g_date_time_new_now_local ();
week_start = get_start_of_week (self->date);
week_end = get_end_of_week (self->date);
/* Don't animate when not today */
if (datetime_compare_date (now, week_start) < 0 || datetime_compare_date (now, week_end) >= 0)
- return;
-
- if (!gtk_widget_get_mapped (self->scrolled_window))
- return;
+ goto out;
vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolled_window));
minutes = g_date_time_get_hour (now) * 60 + g_date_time_get_minute (now);
@@ -168,6 +173,22 @@ update_grid_scroll_position (GcalWeekView *self)
FALSE);
gtk_adjustment_set_page_increment (vadjustment, page_increment);
+
+out:
+ self->scroll_grid_timeout_id = 0;
+ return G_SOURCE_REMOVE;
+}
+
+static void
+schedule_position_scroll (GcalWeekView *self)
+{
+ /* Nothing is scheduled, we should do it now */
+ if (self->scroll_grid_timeout_id > 0)
+ g_source_remove (self->scroll_grid_timeout_id);
+
+ self->scroll_grid_timeout_id = g_timeout_add (200,
+ (GSourceFunc) update_grid_scroll_position,
+ self);
}
/**
@@ -556,7 +577,7 @@ gcal_week_view_set_property (GObject *object,
g_clear_pointer (&self->date, g_free);
self->date = g_value_dup_boxed (value);
- update_grid_scroll_position (self);
+ schedule_position_scroll (self);
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]