1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00

Padding to textbox. remove config.line_padding

This commit is contained in:
Dave Davenport 2016-12-28 13:46:53 +01:00
parent 5dfddf8840
commit d63b9cb15e
3 changed files with 20 additions and 13 deletions

View file

@ -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 ); 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. * Get the (estimated) with of a character, can be used to calculate window width.
* *
* @returns the estimated width of a character. * @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 * @param p The new default PangoContext
* *

View file

@ -58,6 +58,7 @@ struct _listview
unsigned int menu_lines; unsigned int menu_lines;
unsigned int menu_columns; unsigned int menu_columns;
unsigned int fixed_num_lines; unsigned int fixed_num_lines;
unsigned int eh;
gboolean cycle; gboolean cycle;
gboolean multi_select; 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.clicked = listview_clicked;
lv->widget.motion_notify = listview_motion_notify; lv->widget.motion_notify = listview_motion_notify;
lv->widget.enabled = TRUE; lv->widget.enabled = TRUE;
lv->eh = eh;
char *n = g_strjoin(".", lv->widget.name,"scrollbar", NULL); char *n = g_strjoin(".", lv->widget.name,"scrollbar", NULL);
lv->scrollbar = scrollbar_create ( n, 4); 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 ); widget_set_clicked_handler ( WIDGET ( lv->scrollbar ), listview_scrollbar_clicked, lv );
lv->scrollbar->widget.parent = WIDGET ( lv ); lv->scrollbar->widget.parent = WIDGET ( lv );
// Calculate height of an element. // 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->callback = cb;
lv->udata = udata; lv->udata = udata;

View file

@ -226,7 +226,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOWIDTH ) { if ( tb->flags & TB_AUTOWIDTH ) {
pango_layout_set_width ( tb->layout, -1 ); pango_layout_set_width ( tb->layout, -1 );
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; 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 { else {
// set ellipsize // set ellipsize
@ -241,7 +241,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOHEIGHT ) { if ( tb->flags & TB_AUTOHEIGHT ) {
// Width determines height! // Width determines height!
int tw = MAX ( 1, w ); 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 ); 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 // 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; tb->update = TRUE;
widget_queue_redraw ( WIDGET ( tb ) ); widget_queue_redraw ( WIDGET ( tb ) );
} }
@ -320,20 +320,20 @@ static void texbox_update ( textbox *tb )
} }
// Skip the side MARGIN on the X axis. // Skip the side MARGIN on the X axis.
int x = config.line_padding + offset; int x = tb->widget.pad.left + offset;
int y = 0; int y = 0;
if ( tb->flags & TB_RIGHT ) { if ( tb->flags & TB_RIGHT ) {
int line_width = 0; int line_width = 0;
// Get actual width. // Get actual width.
pango_layout_get_pixel_size ( tb->layout, &line_width, NULL ); 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 ) { else if ( tb->flags & TB_CENTER ) {
int tw = textbox_get_font_width ( tb ); 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 // Set background transparency
cairo_set_source_rgba ( tb->main_draw, 0,0,0,0.0); 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; textbox *tb = (textbox *) wid;
if ( tb->flags & TB_AUTOWIDTH ) { if ( tb->flags & TB_AUTOWIDTH ) {
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; 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; return tb->widget.w;
} }
@ -730,7 +730,7 @@ int _textbox_get_height ( widget *wid )
} }
int textbox_get_height ( const textbox *tb ) 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 ) int textbox_get_font_height ( const textbox *tb )
@ -753,8 +753,8 @@ double textbox_get_estimated_char_width ( void )
return ( width ) / (double) PANGO_SCALE; 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 ); 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;
} }