From 8eeebdaf982dce42cbf27e27576aab5a9a6d5eb2 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Fri, 25 Nov 2016 17:17:16 +0100 Subject: [PATCH] T: add function label_set_text --- common/utils/T/tracer/gui/gui.h | 1 + common/utils/T/tracer/gui/gui_defs.h | 2 +- common/utils/T/tracer/gui/label.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/common/utils/T/tracer/gui/gui.h b/common/utils/T/tracer/gui/gui.h index 27e6603042..0eebae91ba 100644 --- a/common/utils/T/tracer/gui/gui.h +++ b/common/utils/T/tracer/gui/gui.h @@ -39,6 +39,7 @@ widget *new_space(gui *gui, int width, int height); widget *new_image(gui *gui, unsigned char *data, int length); void label_set_clickable(gui *gui, widget *label, int clickable); +void label_set_text(gui *gui, widget *label, char *text); void container_set_child_growable(gui *_gui, widget *_this, widget *child, int growable); diff --git a/common/utils/T/tracer/gui/gui_defs.h b/common/utils/T/tracer/gui/gui_defs.h index ec72bb0e2b..938641178c 100644 --- a/common/utils/T/tracer/gui/gui_defs.h +++ b/common/utils/T/tracer/gui/gui_defs.h @@ -141,7 +141,7 @@ struct button_widget { struct label_widget { struct widget common; - const char *t; + char *t; int color; int width; /* as given by the graphic's backend */ int height; /* as given by the graphic's backend */ diff --git a/common/utils/T/tracer/gui/label.c b/common/utils/T/tracer/gui/label.c index f649fa5201..02efabfaf3 100644 --- a/common/utils/T/tracer/gui/label.c +++ b/common/utils/T/tracer/gui/label.c @@ -81,3 +81,21 @@ void label_set_clickable(gui *_g, widget *_this, int clickable) gunlock(g); } + +void label_set_text(gui *_g, widget *_this, char *text) +{ + struct gui *g = _g; + struct label_widget *this = _this; + + glock(g); + + free(this->t); + this->t = strdup(text); if (this->t == NULL) OOM; + + x_text_get_dimensions(g->x, DEFAULT_FONT, text, + &this->width, &this->height, &this->baseline); + + send_event(g, REPACK, this->common.id); + + gunlock(g); +} -- GitLab