diff options
author | Dave Davenport <qball@gmpclient.org> | 2017-05-31 11:05:45 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2017-05-31 11:05:45 +0200 |
commit | 4d8784cf85a5108340a2b2a684e2bd1d9f77269d (patch) | |
tree | 29e6d513c317c4b2686cb9ea27d195d074861df2 /source/widgets/textbox.c | |
parent | 8a6bdd827de065009fbc14b11dca23be61c77138 (diff) |
Port fixes from icon-cleanup branch.
- Thread for fetching icons for drun.
- Fixed placing of icons instead of adding place-holder token that can
mis-render.
- Give textbox TB_ICON flag.
Diffstat (limited to 'source/widgets/textbox.c')
-rw-r--r-- | source/widgets/textbox.c | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index ee51367a..b2fcbded 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -143,6 +143,9 @@ textbox* textbox_create_full ( WidgetType type, const char *name, TextboxFlags f tb->changed = FALSE; tb->layout = pango_layout_new ( p_context ); + if ( (tb->flags&TB_ICON) == TB_ICON) { + tb->left_offset = 1.2*textbox_get_estimated_char_height(); + } textbox_font ( tb, tbft ); tb->metrics = p_metrics; @@ -186,7 +189,6 @@ textbox* textbox_create_full ( WidgetType type, const char *name, TextboxFlags f tb->widget.trigger_action = textbox_editable_trigger_action; } - tb->icon_index = -1; //Don't draw the icon by default // Enabled by default tb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( tb ), "enabled", TRUE ); @@ -269,12 +271,6 @@ void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list ) pango_layout_set_attributes ( tb->layout, list ); } -void textbox_set_icon_index ( textbox *tb, int index ) -{ - tb->icon_index = index; - widget_queue_redraw ( WIDGET ( tb ) ); -} - // set the default text to display void textbox_text ( textbox *tb, const char *text ) { @@ -315,10 +311,9 @@ void textbox_icon ( textbox *tb, cairo_surface_t *icon ) // within the parent handled auto width/height modes void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) { - unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; + unsigned int offset = tb->left_offset + ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; 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 ) + widget_padding_get_padding_width ( WIDGET ( tb ) ) + offset; } else { @@ -371,7 +366,7 @@ static void textbox_free ( widget *wid ) static void textbox_draw ( widget *wid, cairo_t *draw ) { textbox *tb = (textbox *) wid; - unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; + unsigned int offset = tb->left_offset + (( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0); if ( tb->changed ) { __textbox_update_pango_text ( tb ); @@ -383,21 +378,22 @@ static void textbox_draw ( widget *wid, cairo_t *draw ) int y = top + ( pango_font_metrics_get_ascent ( tb->metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE; // draw Icon - int iconheight = textbox_get_font_height ( tb ); - int translatex = ( textbox_get_estimated_char_height () * tb->icon_index / 2 ); - if ( tb->icon != NULL && tb->icon_index != -1 ) { - cairo_save ( draw ); + if ( (tb->flags|TB_ICON) == TB_ICON && tb->icon != NULL ) { + int iconheight = textbox_get_font_height ( tb ); + int translatex = 0; + cairo_save(draw); /*int iconw = cairo_image_surface_get_width (tb->icon);*/ - int iconh = cairo_image_surface_get_height ( tb->icon ); - double scale = (double) iconheight / iconh; + int iconh = cairo_image_surface_get_height (tb->icon); + double scale = (double)iconheight / iconh; - cairo_translate ( draw, translatex, 0 ); - cairo_scale ( draw, scale, scale ); - cairo_set_source_surface ( draw, tb->icon, x, y ); - cairo_paint ( draw ); - cairo_restore ( draw ); + cairo_translate(draw, translatex, 0); + cairo_scale(draw, scale, scale); + cairo_set_source_surface(draw, tb->icon, x, y); + cairo_paint(draw); + cairo_restore(draw); } + x+=offset; if ( tb->flags & TB_RIGHT ) { int line_width = 0; @@ -438,7 +434,7 @@ static void textbox_draw ( widget *wid, cairo_t *draw ) pango_cairo_show_layout ( draw, tb->layout ); if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) { - cairo_arc ( draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * G_PI ); + cairo_arc ( draw, tb->left_offset + DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI ); cairo_fill ( draw ); } } @@ -852,7 +848,7 @@ int textbox_get_estimated_height ( const textbox *tb, int eh ) int textbox_get_desired_width ( widget *wid ) { textbox *tb = (textbox *) wid; - unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; + unsigned int offset = tb->left_offset + ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; if ( tb->flags & TB_AUTOWIDTH ) { return textbox_get_font_width ( tb ) + widget_padding_get_padding_width ( wid ) + offset; } |