[gnome-calendar/wip/pandusonu/week-view: 21/21] week-view: center grid on date change
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/pandusonu/week-view: 21/21] week-view: center grid on date change
- Date: Thu, 8 Dec 2016 20:56:30 +0000 (UTC)
commit b340bd02a3006e91d1e8591a92af2cc87c7b48bf
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Dec 8 18:54:01 2016 -0200
week-view: center grid on date change
src/views/gcal-week-view.c | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 0f2fb52..00e6f9d 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -49,6 +49,7 @@ struct _GcalWeekView
GtkWidget *header;
GtkWidget *hours_bar;
+ GtkWidget *scrolled_window;
GtkWidget *week_grid;
/*
@@ -130,6 +131,25 @@ on_event_activated (GcalWeekView *self,
g_signal_emit (self, signals[EVENT_ACTIVATED], 0, widget);
}
+/* Auxiliary methods */
+static void
+update_grid_scroll_position (GcalWeekView *self)
+{
+ g_autoptr(GDateTime) now;
+ GtkAdjustment *vadjustment;
+ gdouble minutes;
+ gdouble max, page;
+
+ now = g_date_time_new_now_local ();
+ 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);
+ page = gtk_adjustment_get_page_size (vadjustment);
+ max = gtk_adjustment_get_upper (vadjustment);
+
+ gtk_adjustment_set_value (vadjustment,
+ max / MINUTES_PER_DAY * minutes - (page / 2.0));
+}
+
/**
* gcal_week_view_get_initial_date:
*
@@ -431,6 +451,7 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, header);
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, hours_bar);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekView, scrolled_window);
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, week_grid);
gtk_widget_class_bind_template_callback (widget_class, gcal_week_view_draw_hours);
@@ -495,6 +516,9 @@ gcal_week_view_set_property (GObject *object,
case PROP_DATE:
g_clear_pointer (&self->date, g_free);
self->date = g_value_dup_boxed (value);
+
+ update_grid_scroll_position (self);
+
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]