From 484cad24311b324d1dffe2c883e84b47638ac21b Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Fri, 25 Nov 2016 17:17:39 +0100
Subject: [PATCH] T: add function xy_plot_set_title

---
 common/utils/T/tracer/gui/gui.h     |  1 +
 common/utils/T/tracer/gui/xy_plot.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/common/utils/T/tracer/gui/gui.h b/common/utils/T/tracer/gui/gui.h
index 0eebae91ba..c61c2dc6c0 100644
--- a/common/utils/T/tracer/gui/gui.h
+++ b/common/utils/T/tracer/gui/gui.h
@@ -50,6 +50,7 @@ void xy_plot_set_range(gui *gui, widget *this,
 void xy_plot_set_points(gui *gui, widget *this,
     int plot, int npoints, float *x, float *y);
 void xy_plot_get_dimensions(gui *gui, widget *this, int *width, int *height);
+void xy_plot_set_title(gui *gui, widget *this, char *label);
 
 void textlist_add(gui *gui, widget *this, const char *text, int position,
     int color);
diff --git a/common/utils/T/tracer/gui/xy_plot.c b/common/utils/T/tracer/gui/xy_plot.c
index 7d20a027a1..9342a5a464 100644
--- a/common/utils/T/tracer/gui/xy_plot.c
+++ b/common/utils/T/tracer/gui/xy_plot.c
@@ -290,3 +290,22 @@ void xy_plot_get_dimensions(gui *_gui, widget *_this, int *width, int *height)
 
   gunlock(g);
 }
+
+void xy_plot_set_title(gui *_gui, widget *_this, char *label)
+{
+  struct gui *g = _gui;
+  struct xy_plot_widget *this = _this;
+
+  glock(g);
+
+  free(this->label);
+  this->label = strdup(label); if (this->label == NULL) OOM;
+  /* TODO: be sure calling X there is valid wrt "global model" (we are
+   * not in the "gui thread") */
+  x_text_get_dimensions(g->x, DEFAULT_FONT, label,
+      &this->label_width, &this->label_height, &this->label_baseline);
+
+  send_event(g, REPACK, this->common.id);
+
+  gunlock(g);
+}
-- 
GitLab