summaryrefslogtreecommitdiffstats
path: root/source/widgets
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-12-31 23:00:06 +0100
committerDave Davenport <qball@gmpclient.org>2016-12-31 23:00:06 +0100
commit52e850dc332b5628e727d5277823f505f2be4548 (patch)
treef42e3a6ae7c557c3a8791fb40a4d6d73dfbbabd7 /source/widgets
parent068592414e6993274c37e894acaf4d371600ddaf (diff)
Fix EM support, use char height
Diffstat (limited to 'source/widgets')
-rw-r--r--source/widgets/listview.c7
-rw-r--r--source/widgets/textbox.c20
-rw-r--r--source/widgets/widget.c10
3 files changed, 27 insertions, 10 deletions
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;
}