summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-12-28 13:46:53 +0100
committerDave Davenport <qball@gmpclient.org>2016-12-28 13:46:53 +0100
commitd63b9cb15e6947335a66278a205c2a6a8495ff86 (patch)
tree62a0474e76750b37ebb1f9801bb6e819838bd7fa
parent5dfddf8840b9da1234ea0a9bba66b65b92d1095d (diff)
Padding to textbox. remove config.line_padding
-rw-r--r--include/widgets/textbox.h3
-rw-r--r--source/widgets/listview.c8
-rw-r--r--source/widgets/textbox.c22
3 files changed, 20 insertions, 13 deletions
diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h
index ae31f6e7..b445f28c 100644
--- a/include/widgets/textbox.h
+++ b/include/widgets/textbox.h
@@ -218,11 +218,12 @@ void textbox_delete ( textbox *tb, int pos, int dlen );
*/
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 ( void );
+int textbox_get_estimated_char_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 933ae130..2ec40c80 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -58,6 +58,7 @@ struct _listview
unsigned int menu_lines;
unsigned int menu_columns;
unsigned int fixed_num_lines;
+ unsigned int eh;
gboolean cycle;
gboolean multi_select;
@@ -325,6 +326,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->widget.clicked = listview_clicked;
lv->widget.motion_notify = listview_motion_notify;
lv->widget.enabled = TRUE;
+ lv->eh = eh;
char *n = g_strjoin(".", lv->widget.name,"scrollbar", NULL);
lv->scrollbar = scrollbar_create ( n, 4);
@@ -332,7 +334,11 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
widget_set_clicked_handler ( WIDGET ( lv->scrollbar ), listview_scrollbar_clicked, lv );
lv->scrollbar->widget.parent = WIDGET ( lv );
// Calculate height of an element.
- lv->element_height = textbox_get_estimated_char_height () * eh;
+ //
+ 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);
+ g_free(tb_name);
lv->callback = cb;
lv->udata = udata;
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index 1ee5ca4b..a2397f4b 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -226,7 +226,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOWIDTH ) {
pango_layout_set_width ( tb->layout, -1 );
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
- w = textbox_get_font_width ( tb ) + 2 * config.line_padding + offset;
+ w = textbox_get_font_width ( tb ) + tb->widget.pad.left+tb->widget.pad.right + offset;
}
else {
// set ellipsize
@@ -241,7 +241,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOHEIGHT ) {
// Width determines height!
int tw = MAX ( 1, w );
- pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - 2 * config.line_padding - offset ) );
+ pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - tb->widget.pad.left-tb->widget.pad.right - offset ) );
h = textbox_get_height ( tb );
}
@@ -253,7 +253,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
}
// We always want to update this
- pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - 2 * config.line_padding - offset ) );
+ pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - tb->widget.pad.left-tb->widget.pad.right - offset ) );
tb->update = TRUE;
widget_queue_redraw ( WIDGET ( tb ) );
}
@@ -320,20 +320,20 @@ static void texbox_update ( textbox *tb )
}
// Skip the side MARGIN on the X axis.
- int x = config.line_padding + offset;
+ int x = tb->widget.pad.left + offset;
int y = 0;
if ( tb->flags & TB_RIGHT ) {
int line_width = 0;
// Get actual width.
pango_layout_get_pixel_size ( tb->layout, &line_width, NULL );
- x = ( tb->widget.w - line_width - config.line_padding - offset );
+ x = ( tb->widget.w - line_width - tb->widget.pad.right- offset );
}
else if ( tb->flags & TB_CENTER ) {
int tw = textbox_get_font_width ( tb );
- x = ( ( tb->widget.w - tw - 2 * config.line_padding - offset ) ) / 2;
+ x = ( ( tb->widget.w - tw - tb->widget.pad.left-tb->widget.pad.right - offset ) ) / 2;
}
- y = config.line_padding + ( pango_font_metrics_get_ascent ( p_metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
+ y = tb->widget.pad.top + ( pango_font_metrics_get_ascent ( p_metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
// Set background transparency
cairo_set_source_rgba ( tb->main_draw, 0,0,0,0.0);
@@ -715,7 +715,7 @@ int textbox_get_width ( widget *wid )
textbox *tb = (textbox *) wid;
if ( tb->flags & TB_AUTOWIDTH ) {
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
- return textbox_get_font_width ( tb ) + 2 * config.line_padding + offset;
+ return textbox_get_font_width ( tb ) + wid->pad.left+wid->pad.right+ offset;
}
return tb->widget.w;
}
@@ -730,7 +730,7 @@ int _textbox_get_height ( widget *wid )
}
int textbox_get_height ( const textbox *tb )
{
- return textbox_get_font_height ( tb ) + 2 * config.line_padding;
+ return textbox_get_font_height ( tb ) + tb->widget.pad.top+tb->widget.pad.bottom;
}
int textbox_get_font_height ( const textbox *tb )
@@ -753,8 +753,8 @@ double textbox_get_estimated_char_width ( void )
return ( width ) / (double) PANGO_SCALE;
}
-int textbox_get_estimated_char_height ( void )
+int textbox_get_estimated_char_height ( const textbox *tb, int eh )
{
int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics );
- return ( height ) / PANGO_SCALE + 2 * config.line_padding;
+ return ( eh*height ) / PANGO_SCALE + tb->widget.pad.top+tb->widget.pad.bottom;
}