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

[View] Add icon-current-entry widget.

This commit is contained in:
Dave Davenport 2022-06-27 17:09:21 +02:00
parent 8ee05a718e
commit 9c18aaef22
5 changed files with 41 additions and 14 deletions

View file

@ -1246,6 +1246,8 @@ The current widgets available in \fBrofi\fP:
\fB\fCnum-filtered-rows\fR: Shows the total number of rows after filtering. \fB\fCnum-filtered-rows\fR: Shows the total number of rows after filtering.
.IP \(bu 2 .IP \(bu 2
\fB\fCtextbox-current-entry\fR: Shows the text of the currently selected entry. \fB\fCtextbox-current-entry\fR: Shows the text of the currently selected entry.
.IP \(bu 2
\fB\fCicon-current-entry\fR: Shows the icon of the currently selected entry.
.RE .RE

View file

@ -774,6 +774,7 @@ The current widgets available in **rofi**:
* `num-rows`: Shows the total number of rows. * `num-rows`: Shows the total number of rows.
* `num-filtered-rows`: Shows the total number of rows after filtering. * `num-filtered-rows`: Shows the total number of rows after filtering.
* `textbox-current-entry`: Shows the text of the currently selected entry. * `textbox-current-entry`: Shows the text of the currently selected entry.
* `icon-current-entry`: Shows the icon of the currently selected entry.
* `listview`: The listview. * `listview`: The listview.
* `scrollbar`: the listview scrollbar * `scrollbar`: the listview scrollbar
* `element`: a box in the listview holding the entries * `element`: a box in the listview holding the entries

View file

@ -108,6 +108,7 @@ struct RofiViewState {
textbox *tb_filtered_rows; textbox *tb_filtered_rows;
textbox *tb_current_entry; textbox *tb_current_entry;
icon *icon_current_entry;
/** Settings of the menu */ /** Settings of the menu */
MenuFlags menu_flags; MenuFlags menu_flags;

View file

@ -1010,18 +1010,29 @@ inline static void rofi_view_nav_last(RofiViewState *state) {
static void selection_changed_callback(listview *lv, unsigned int index, static void selection_changed_callback(listview *lv, unsigned int index,
void *udata) { void *udata) {
RofiViewState *state = (RofiViewState *)udata; RofiViewState *state = (RofiViewState *)udata;
if (state->tb_current_entry == NULL) { if (state->tb_current_entry) {
return; if (index < state->filtered_lines) {
} int fstate = 0;
if (index < state->filtered_lines) { char *text = mode_get_display_value(state->sw, state->line_map[index],
int fstate = 0; &fstate, NULL, TRUE);
char *text = mode_get_display_value(state->sw, state->line_map[index], textbox_text(state->tb_current_entry, text);
&fstate, NULL, TRUE); g_free(text);
textbox_text(state->tb_current_entry, text);
g_free(text);
} else { } else {
textbox_text(state->tb_current_entry, ""); textbox_text(state->tb_current_entry, "");
}
}
if (state->icon_current_entry) {
if (index < state->filtered_lines) {
int icon_height =
widget_get_desired_height(WIDGET(state->icon_current_entry),
WIDGET(state->icon_current_entry)->w);
cairo_surface_t *icon =
mode_get_icon(state->sw, state->line_map[index], icon_height);
icon_set_surface(state->icon_current_entry, icon);
} else {
icon_set_surface(state->icon_current_entry, NULL);
}
} }
} }
static void update_callback(textbox *t, icon *ico, unsigned int index, static void update_callback(textbox *t, icon *ico, unsigned int index,
@ -1898,6 +1909,10 @@ static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget,
TB_MARKUP | TB_AUTOHEIGHT, NORMAL, "", 0, 0); TB_MARKUP | TB_AUTOHEIGHT, NORMAL, "", 0, 0);
box_add((box *)parent_widget, WIDGET(state->tb_current_entry), FALSE); box_add((box *)parent_widget, WIDGET(state->tb_current_entry), FALSE);
defaults = NULL; defaults = NULL;
} else if (strcmp(name, "icon-current-entry") == 0) {
state->icon_current_entry = icon_create(parent_widget, name);
box_add((box *)parent_widget, WIDGET(state->icon_current_entry), FALSE);
defaults = NULL;
} }
/** /**
* CASE INDICATOR * CASE INDICATOR

View file

@ -63,7 +63,7 @@ textbox-current-entry {
} }
element-icon { element-icon {
expand: true; expand: true;
size: 20mm; size: 10mm;
vertial-align: 0.5; vertial-align: 0.5;
horizontal-align: 0.5; horizontal-align: 0.5;
padding: 2mm; padding: 2mm;
@ -74,13 +74,21 @@ mainbox {
expand: true; expand: true;
background-color: transparent; background-color: transparent;
spacing: 5mm; spacing: 5mm;
children: [ inputbar,textbox-current-entry, listview ]; children: [
inputbar,
listview,
icon-current-entry,
textbox-current-entry
];
} }
icon-current-entry {
size: 100mm;
}
listview { listview {
padding: 0em; padding: 0em;
dynamic: false; dynamic: false;
lines: 0; lines: 0;
columns: 5; columns: 8;
flow: horizontal; flow: horizontal;
} }
element selected normal { element selected normal {