From cbb9631877f1ff147671901d2644e428aea50d63 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 30 Jun 2016 08:18:11 -0400 Subject: [PATCH] gui: Add a function for determining the height of widgets It's eaiser to do it in the builder code, rather than repeating this code in several places. Signed-off-by: Anna Schumaker --- gui/audio.c | 3 +-- gui/builder.c | 5 +++++ include/gui/builder.h | 3 +++ tests/gui/builder.c | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gui/audio.c b/gui/audio.c index e193880c..298a896c 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -31,8 +31,7 @@ static inline void __audio_set_time_label(const gchar *label, unsigned int time) static void __audio_set_cover(gchar *path) { GtkImage *image = GTK_IMAGE(gui_builder_widget("o_cover")); - GtkWidget *tags = gui_builder_widget("o_tags"); - int height = gtk_widget_get_allocated_height(tags); + int height = gui_builder_widget_height("o_tags"); GdkPixbuf *pix = gdk_pixbuf_new_from_file_at_size(path, height, height, NULL); diff --git a/gui/builder.c b/gui/builder.c index 5457de76..a0c22db1 100644 --- a/gui/builder.c +++ b/gui/builder.c @@ -29,6 +29,11 @@ GtkWidget *gui_builder_widget(const char *name) return GTK_WIDGET(gui_builder_object(name)); } +int gui_builder_widget_height(const char *name) +{ + return gtk_widget_get_allocated_height(gui_builder_widget(name)); +} + #ifdef CONFIG_TESTING GtkBuilder *test_get_gui_builder() { diff --git a/include/gui/builder.h b/include/gui/builder.h index 6b3cd3af..0ec466cb 100644 --- a/include/gui/builder.h +++ b/include/gui/builder.h @@ -17,6 +17,9 @@ GObject *gui_builder_object(const char *); /* Called to get a widget from the GTK builder. */ GtkWidget *gui_builder_widget(const char *); +/* Called to find the height of a GTK builder widget. */ +int gui_builder_widget_height(const char *); + #ifdef CONFIG_TESTING GtkBuilder *test_get_gui_builder(); #endif /* CONFIG_TESTING */ diff --git a/tests/gui/builder.c b/tests/gui/builder.c index 892e3e1c..adb075ad 100644 --- a/tests/gui/builder.c +++ b/tests/gui/builder.c @@ -33,9 +33,11 @@ static void test_builder() test_not_equal((void *)widget, NULL); test_equal(GTK_IS_WIDGET(widget), true); test_equal(GTK_IS_BUTTON(widget), true); + test_equal(gui_builder_widget_height("button1") > 0, true); gtk_button_clicked(GTK_BUTTON(widget)); test_equal(gui_clicked, 1); + gtk_widget_destroy(gui_builder_widget("window1")); gui_builder_deinit(); test_equal((void *)test_get_gui_builder(), NULL);