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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-06-30 08:18:11 -04:00
parent 1e59968154
commit cbb9631877
4 changed files with 11 additions and 2 deletions

View File

@ -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);

View File

@ -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()
{

View File

@ -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 */

View File

@ -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);