diff options
author | Dave Davenport <qball@gmpclient.org> | 2019-05-04 11:01:09 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2019-05-04 11:04:54 +0200 |
commit | 52c5592a6f6d55897a03bb9691031c3cf8c71b46 (patch) | |
tree | 5340e54fd1cf64608301f8228def4c141540a890 /source/widgets | |
parent | e7da00dbff338327c5beb8ced42ab84016a18ed7 (diff) |
[ListView|Textbox] Add user-settable ellipsize mode.
Fixes: #917
Diffstat (limited to 'source/widgets')
-rw-r--r-- | source/widgets/listview.c | 21 | ||||
-rw-r--r-- | source/widgets/textbox.c | 19 |
2 files changed, 39 insertions, 1 deletions
diff --git a/source/widgets/listview.c b/source/widgets/listview.c index b194ced6..cb7f0628 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -109,6 +109,8 @@ struct _listview char *listview_name; + + PangoEllipsizeMode emode; /** Barview */ struct { @@ -532,6 +534,7 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca lv->widget.get_desired_height = listview_get_desired_height; lv->eh = eh; + lv->emode = PANGO_ELLIPSIZE_END; lv->scrollbar = scrollbar_create ( WIDGET ( lv ), "scrollbar" ); // Calculate height of an element. // @@ -830,3 +833,21 @@ void listview_set_fixed_num_lines ( listview *lv ) lv->fixed_num_lines = TRUE; } } + +void listview_toggle_ellipsizing ( listview *lv ) +{ + if ( lv ) { + PangoEllipsizeMode mode = lv->emode; + if ( mode == PANGO_ELLIPSIZE_START ) { + mode = PANGO_ELLIPSIZE_MIDDLE; + } else if ( mode == PANGO_ELLIPSIZE_MIDDLE ) { + mode = PANGO_ELLIPSIZE_END; + } else if ( mode == PANGO_ELLIPSIZE_END ) { + mode = PANGO_ELLIPSIZE_START; + } + lv->emode = mode; + for ( unsigned int i = 0; i < lv->cur_elements; i++ ) { + textbox_set_ellipsize ( lv->boxes[i], mode ); + } + } +} diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 70c29b10..1adf9fd3 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -177,6 +177,7 @@ textbox* textbox_create ( widget *parent, WidgetType type, const char *name, Tex tb->widget.get_desired_height = textbox_get_desired_height; tb->widget.get_desired_width = textbox_get_desired_width; tb->flags = flags; + tb->emode = PANGO_ELLIPSIZE_END; tb->changed = FALSE; @@ -362,7 +363,9 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_MIDDLE ); } else if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { - pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_END ); + pango_layout_set_ellipsize ( tb->layout, tb->emode ); + } else { + pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_NONE ); } } @@ -950,3 +953,17 @@ int textbox_get_desired_width ( widget *wid ) pango_layout_set_width ( tb->layout, old_width ); return width + padding + offset; } + + +void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode ) +{ + if ( tb ) + { + tb->emode = mode; + if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { + // Store the mode. + pango_layout_set_ellipsize ( tb->layout, tb->emode ); + widget_queue_redraw ( WIDGET ( tb ) ); + } + } +} |