From 52e850dc332b5628e727d5277823f505f2be4548 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 31 Dec 2016 23:00:06 +0100 Subject: Fix EM support, use char height --- source/widgets/listview.c | 7 +++++-- source/widgets/textbox.c | 20 +++++++++++++++++--- source/widgets/widget.c | 10 +++++----- 3 files changed, 27 insertions(+), 10 deletions(-) (limited to 'source/widgets') 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; } +static double char_height = -1; +double textbox_get_estimated_char_height ( void ) +{ + 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; +} + +static double char_width = -1; double textbox_get_estimated_char_width ( void ) { - int width = pango_font_metrics_get_approximate_char_width ( p_metrics ); - return ( width ) / (double) PANGO_SCALE; + 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_char_height ( const textbox *tb, int eh ) +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; } -- cgit v1.2.3