aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorSergio Vieira <sergiosvieira@gmail.com>2020-10-08 13:04:54 -0300
committerLeandro Pereira <leandro@hardinfo.org>2020-10-09 18:25:13 -0700
commit4d8e68f34fabd3e387df3246cfc69425cea65eed (patch)
tree151db0b2df500adf284059fe86b26fce3f3df9df /shell
parent7665215da2cb168631938465550220be9349bf3a (diff)
Show graph's title at selecting sensor item
Diffstat (limited to 'shell')
-rw-r--r--shell/loadgraph.c29
-rw-r--r--shell/shell.c2
2 files changed, 31 insertions, 0 deletions
diff --git a/shell/loadgraph.c b/shell/loadgraph.c
index ceb91720..36334718 100644
--- a/shell/loadgraph.c
+++ b/shell/loadgraph.c
@@ -43,6 +43,7 @@ struct _LoadGraph {
PangoLayout *layout;
gchar *suffix;
+ gchar *title;
};
static void _draw(LoadGraph * lg);
@@ -56,6 +57,7 @@ LoadGraph *load_graph_new(gint size)
size++;
lg->suffix = g_strdup("");
+ lg->title = g_strdup("");
lg->area = gtk_drawing_area_new();
lg->size = (size * 3) / 2;
lg->data = g_new0(gint, lg->size);
@@ -87,6 +89,18 @@ gchar *load_graph_get_data_suffix(LoadGraph * lg)
return lg->suffix;
}
+void load_graph_set_title(LoadGraph * lg, gchar * title)
+{
+ g_free(lg->title);
+ lg->title = g_strdup(title);
+}
+
+gchar *load_graph_get_title(LoadGraph *lg)
+{
+ if (lg != NULL) return lg->title;
+ return NULL;
+}
+
GtkWidget *load_graph_get_framed(LoadGraph * lg)
{
GtkWidget *align, *frame;
@@ -179,6 +193,18 @@ void load_graph_configure_expose(LoadGraph * lg)
(GCallback) _expose, lg);
}
+static void _draw_title(LoadGraph * lg, const char* title) {
+ gchar *tmp = g_strdup_printf("<span size=\"x-small\">%s</span>", title);
+ pango_layout_set_markup(lg->layout, tmp, -1);
+ int width = 0;
+ int height = 0;
+ pango_layout_get_pixel_size(lg->layout, &width, &height);
+ gint position = (lg->width / 2) - (width / 2);
+ gdk_draw_layout(GDK_DRAWABLE(lg->buf), lg->trace, position, 2,
+ lg->layout);
+ g_free(tmp);
+}
+
static void _draw_label_and_line(LoadGraph * lg, gint position, gint value)
{
gchar *tmp;
@@ -242,6 +268,9 @@ static void _draw(LoadGraph * lg)
_draw_label_and_line(lg, lg->height / 2, lg->max_value / 2);
_draw_label_and_line(lg, 3 * (lg->height / 4), lg->max_value / 4);
+ /* graph title */
+ _draw_title(lg, lg->title);
+
gtk_widget_queue_draw(lg->area);
}
diff --git a/shell/shell.c b/shell/shell.c
index 1bcdb714..bfa5dc8c 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -844,6 +844,8 @@ static gboolean update_field(gpointer data)
if (shell->view_type == SHELL_VIEW_LOAD_GRAPH &&
gtk_tree_selection_iter_is_selected(shell->info_tree->selection,
item->iter)) {
+
+ load_graph_set_title(shell->loadgraph, fu->field_name);
load_graph_update(shell->loadgraph, atof(value));
}