ocarina: Improved label setting function

I created a single function to escape the text and set it in the label.
I don't know why I didn't do this from the beginning!
This commit is contained in:
Bryan Schumaker 2011-11-07 19:22:46 -05:00
parent 5ae5174536
commit 30246df924
1 changed files with 11 additions and 7 deletions

View File

@ -8,28 +8,32 @@ static GtkWidget *title = NULL;
static GtkWidget *artist = NULL;
static GtkWidget *album = NULL;
static void set_label(GtkWidget *label, string text, string size)
{
string escaped = g_markup_escape_text(text.c_str(), -1);
string markup = "<span size='" + size + "'>" + escaped + "</span>";
gtk_label_set_markup(GTK_LABEL(label), markup.c_str());
}
static void set_title(string new_title)
{
string markup = "<span size='xx-large'>" + new_title + "</span>";
gtk_label_set_markup(GTK_LABEL(title), markup.c_str());
set_label(title, new_title, "xx-large");
}
static void set_artist(string new_artist)
{
string markup = "<span size='x-large'>" + new_artist + "</span>";
gtk_label_set_markup(GTK_LABEL(artist), markup.c_str());
set_label(artist, new_artist, "x-large");
}
static void set_album(string new_album)
{
string markup = "<span size='x-large'>" + new_album + "</span>";
gtk_label_set_markup(GTK_LABEL(album), markup.c_str());
set_label(album, new_album, "x-large");
}
static GtkWidget *align(GtkWidget *label)
{
GtkWidget *alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
gtk_container_add(GTK_CONTAINER(alignment), label);
container_add(alignment, label);
return alignment;
}