diff --git a/include/widgets/listview.h b/include/widgets/listview.h index f20cf18a..cdefaa51 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -75,15 +75,6 @@ void listview_set_selected ( listview *lv, unsigned int selected ); */ unsigned int listview_get_selected ( listview *lv ); -/** - * @param lv The listview handle - * - * Get the desired height of the listview widget. - * - * @returns the desired height. - */ -unsigned int listview_get_desired_height ( listview *lv ); - /** * @param lv The listview handle * diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h index b445f28c..15d2ef5d 100644 --- a/include/widgets/textbox.h +++ b/include/widgets/textbox.h @@ -196,6 +196,7 @@ int textbox_get_font_width ( const textbox *tb ); * @returns the width of a character in pixels. */ double textbox_get_estimated_char_width ( void ); +double textbox_get_estimated_char_height ( void ); /** * @param tb Handle to the textbox @@ -217,13 +218,14 @@ void textbox_delete ( textbox *tb, int pos, int dlen ); * TODO remove for #widget_resize and #widget_move */ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ); + /** * @param tb Handle to the textbox * Get the (estimated) with of a character, can be used to calculate window width. * * @returns the estimated width of a character. */ -int textbox_get_estimated_char_height ( const textbox *tb, int eh ); +int textbox_get_estimated_height ( const textbox *tb, int eh ); /** * @param p The new default PangoContext * diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 7bfd47d0..210f6f0e 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -77,6 +77,8 @@ struct _listview void *mouse_activated_data; }; +static int listview_get_desired_height ( widget *wid ); + static void listview_free ( widget *wid ) { listview *lv = (listview *) wid; @@ -340,7 +342,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void // char *tb_name = g_strjoin (".", lv->widget.name,"element", NULL); textbox *tb = textbox_create ( tb_name, 0, NORMAL, "" ); - lv->element_height = textbox_get_estimated_char_height (tb, lv->eh); + lv->element_height = textbox_get_estimated_height (tb, lv->eh); g_free(tb_name); lv->callback = cb; @@ -452,8 +454,9 @@ void listview_nav_page_next ( listview *lv ) widget_queue_redraw ( WIDGET ( lv ) ); } -unsigned int listview_get_desired_height ( listview *lv ) +static int listview_get_desired_height ( widget *wid ) { + listview *lv = (listview *)wid; if ( lv == NULL || lv->widget.enabled == FALSE ) { return 0; } diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 87d90767..778b9a41 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -757,13 +757,27 @@ int textbox_get_font_width ( const textbox *tb ) return width; } -double textbox_get_estimated_char_width ( void ) +static double char_height = -1; +double textbox_get_estimated_char_height ( void ) { - int width = pango_font_metrics_get_approximate_char_width ( p_metrics ); - return ( width ) / (double) PANGO_SCALE; + if ( char_height < 0 ){ + int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics ); + char_height = ( height ) / (double) PANGO_SCALE; + } + return char_height; } -int textbox_get_estimated_char_height ( const textbox *tb, int eh ) +static double char_width = -1; +double textbox_get_estimated_char_width ( void ) +{ + if ( char_width < 0 ){ + int width = pango_font_metrics_get_approximate_char_width ( p_metrics ); + char_width = ( width ) / (double) PANGO_SCALE; + } + return char_width; +} + +int textbox_get_estimated_height ( const textbox *tb, int eh ) { int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics ); return ( eh*height ) / PANGO_SCALE + widget_padding_get_padding_height ( WIDGET ( tb ) ); diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 81ed45f1..77c4cf2e 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -212,32 +212,32 @@ void widget_set_name ( widget *wid, const char *name ) } // External -double textbox_get_estimated_char_width ( void ); +double textbox_get_estimated_char_height ( void ); int widget_padding_get_left ( const widget *wid ) { if ( wid->pad.left.type == PW_EM ){ - return wid->pad.left.distance*textbox_get_estimated_char_width(); + return wid->pad.left.distance*textbox_get_estimated_char_height(); } return wid->pad.left.distance; } int widget_padding_get_right ( const widget *wid ) { if ( wid->pad.right.type == PW_EM ){ - return wid->pad.right.distance*textbox_get_estimated_char_width(); + return wid->pad.right.distance*textbox_get_estimated_char_height(); } return wid->pad.right.distance; } int widget_padding_get_top ( const widget *wid ) { if ( wid->pad.top.type == PW_EM ){ - return wid->pad.top.distance*textbox_get_estimated_char_width(); + return wid->pad.top.distance*textbox_get_estimated_char_height(); } return wid->pad.top.distance; } int widget_padding_get_bottom ( const widget *wid ) { if ( wid->pad.bottom.type == PW_EM ){ - return wid->pad.bottom.distance*textbox_get_estimated_char_width(); + return wid->pad.bottom.distance*textbox_get_estimated_char_height(); } return wid->pad.bottom.distance; }