From 601d8f44d523a1f687393339f5767589ec84b682 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Fri, 21 Dec 2018 15:59:08 +0100
Subject: Improved graph view content centering.

---
 src/gtkext/gtkgraphdisplay.c | 43 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/src/gtkext/gtkgraphdisplay.c b/src/gtkext/gtkgraphdisplay.c
index a991ace..4475c08 100644
--- a/src/gtkext/gtkgraphdisplay.c
+++ b/src/gtkext/gtkgraphdisplay.c
@@ -93,6 +93,9 @@ static void gtk_graph_display_finalize(GtkGraphDisplay *);
 /* S'adapte à la surface concédée par le composant parent. */
 static void gtk_graph_display_size_allocate(GtkWidget *, GtkAllocation *);
 
+/* Centre si possible le contenu du panneau d'affichage. */
+static void gtk_graph_display_update_support_margins(GtkGraphDisplay *, const GtkAllocation *);
+
 /* Indique les dimensions de travail du composant d'affichage. */
 static void gtk_graph_display_compute_requested_size(GtkGraphDisplay *, gint *, gint *);
 
@@ -291,15 +294,36 @@ static void gtk_graph_display_finalize(GtkGraphDisplay *display)
 static void gtk_graph_display_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
 {
     GtkGraphDisplay *display;                     /* Autre version du composant  */
-    gint width;                             /* Largeur totale du support   */
-    gint height;                            /* Hauteur totale du support   */
-    gint start;                             /* Bordure horizontale         */
-    gint top;                               /* Bordure verticale           */
 
     GTK_WIDGET_CLASS(gtk_graph_display_parent_class)->size_allocate(widget, allocation);
 
     display = GTK_GRAPH_DISPLAY(widget);
 
+    gtk_graph_display_update_support_margins(display, allocation);
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : display    = panneau dont le contenu est à déplacer.         *
+*                allocation = étendue accordée à la vue.                      *
+*                                                                             *
+*  Description : Centre si possible le contenu du panneau d'affichage.        *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void gtk_graph_display_update_support_margins(GtkGraphDisplay *display, const GtkAllocation *allocation)
+{
+    gint width;                             /* Largeur totale du support   */
+    gint height;                            /* Hauteur totale du support   */
+    gint start;                             /* Bordure horizontale         */
+    gint top;                               /* Bordure verticale           */
+
     gtk_graph_display_compute_requested_size(display, &width, &height);
 
     if (width > allocation->width)
@@ -315,6 +339,8 @@ static void gtk_graph_display_size_allocate(GtkWidget *widget, GtkAllocation *al
     gtk_widget_set_margin_start(display->support, start);
     gtk_widget_set_margin_top(display->support, top);
 
+    gtk_widget_queue_resize(GTK_WIDGET(display));
+
 }
 
 
@@ -605,6 +631,7 @@ static void gtk_graph_display_prepare_for_cursor(GtkGraphDisplay *display, const
     GBlockList *list;                       /* Liste de blocs basiques     */
     gint right;                             /* Abscisse du coin droit      */
     gint bottom;                            /* Ordonnée du coin inférieur  */
+    GtkAllocation allocation;               /* Espace alloué au panneau    */
     GtkWidget *child;                       /* Composant sélectionné       */
 
     assert(G_IS_BINARY_CURSOR(cursor));
@@ -660,6 +687,14 @@ static void gtk_graph_display_prepare_for_cursor(GtkGraphDisplay *display, const
         gtk_fixed_move(GTK_FIXED(display->support), display->extender, right - 1, bottom - 1);
 
         /**
+         * Si possible, on centre le contenu obtenu.
+         */
+
+        gtk_widget_get_allocation(GTK_WIDGET(display), &allocation);
+
+        gtk_graph_display_update_support_margins(display, &allocation);
+
+        /**
          * Première sélection...
          */
 
-- 
cgit v0.11.2-87-g4458