Skip to content

Commit

Permalink
[Listview] Add support for showing the (keybindable) index.
Browse files Browse the repository at this point in the history
fixes: #1050
  • Loading branch information
DaveDavenport committed Dec 29, 2019
1 parent afda9cb commit e6bed0e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/rofi-theme.5
Expand Up @@ -848,6 +848,8 @@ The current widgets available in \fBrofi\fP:
.IP \(bu 2
\fB\fCelement\-icon\fR: the widget in the listview's entry showing the (optional) icon
.IP \(bu 2
\fB\fCelement\-index\fR: the widget in the listview's entry keybindable index (1,2,3..0)
.IP \(bu 2
\fB\fCelement\-text\fR: the widget in the listview's entry showing the text.

.RE
Expand Down
1 change: 1 addition & 0 deletions doc/rofi-theme.5.markdown
Expand Up @@ -518,6 +518,7 @@ The current widgets available in **rofi**:
* `scrollbar`: the listview scrollbar
* `element`: a box in the listview holding the entries
* `element-icon`: the widget in the listview's entry showing the (optional) icon
* `element-index`: the widget in the listview's entry keybindable index (1,2,3..0)
* `element-text`: the widget in the listview's entry showing the text.
* `mode-switcher`: the main horizontal @box packing the buttons.
* `button`: the buttons @textbox for each mode
Expand Down
21 changes: 20 additions & 1 deletion source/widgets/listview.c
Expand Up @@ -63,6 +63,7 @@ typedef enum
typedef struct {
box *box;
textbox *textbox;
textbox *index;
icon *icon;
} _listview_row;

Expand Down Expand Up @@ -173,6 +174,7 @@ static void listview_create_row ( listview *lv, _listview_row *row )

row->textbox = NULL;
row->icon = NULL;
row->index = NULL;

for ( GList *iter = g_list_first(list); iter != NULL;iter = g_list_next(iter)){
if ( strcasecmp((char *)iter->data, "element-icon") == 0 ) {
Expand All @@ -183,6 +185,9 @@ static void listview_create_row ( listview *lv, _listview_row *row )
} else if ( strcasecmp ((char *)iter->data, "element-text") == 0 ){
row->textbox= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT|flags, NORMAL, "DDD", 0, 0 );
box_add ( row->box, WIDGET ( row->textbox ), TRUE);
} else if ( strcasecmp ( (char*)iter->data, "element-index" ) == 0 ){
row->index= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT|flags, NORMAL, " ", 0, 0 );
box_add ( row->box, WIDGET ( row->index ), FALSE);
}
}
g_list_free_full ( list, g_free );
Expand All @@ -192,7 +197,12 @@ static void listview_create_row ( listview *lv, _listview_row *row )
static void listview_set_state ( _listview_row r, TextBoxFontType type )
{
listview_set_style ( WIDGET(r.box), type);
listview_set_style ( WIDGET(r.textbox), type);
if ( r.textbox ) {
listview_set_style ( WIDGET(r.textbox), type);
}
if ( r.index ) {
listview_set_style ( WIDGET(r.index), type);
}
if ( r.icon ) {
listview_set_style ( WIDGET(r.icon), type);
}
Expand Down Expand Up @@ -278,6 +288,15 @@ static void update_element ( listview *lv, unsigned int tb, unsigned int index,
TextBoxFontType type = ( index & 1 ) == 0 ? NORMAL : ALT;
type = ( index ) == lv->selected ? HIGHLIGHT : type;

if ( lv->boxes[tb].index ) {
if ( index < 10 ) {
char str[2] = "0";
str[0] = ((index+1)%10)+'0';
textbox_text( lv->boxes[tb].index, str );
} else {
textbox_text( lv->boxes[tb].index, " " );
}
}
if ( lv->callback ) {
lv->callback ( lv->boxes[tb].textbox, lv->boxes[tb].icon, index, lv->udata, &type, full );
listview_set_state ( lv->boxes[tb], type);
Expand Down

0 comments on commit e6bed0e

Please sign in to comment.