diff --git a/src/bfu/dialog.c b/src/bfu/dialog.c index 8671c8179..042a172cc 100644 --- a/src/bfu/dialog.c +++ b/src/bfu/dialog.c @@ -57,7 +57,9 @@ update_all_widgets(struct dialog_data *dlg_data) { struct widget_data *widget_data; - foreach_widget(dlg_data, widget_data) { + /* Iterate backwards rather than forwards so that listboxes are drawn + * last, which means that they can grab the cursor. Yes, 'tis hacky. */ + foreach_widget_back(dlg_data, widget_data) { display_widget(dlg_data, widget_data); } } diff --git a/src/bfu/dialog.h b/src/bfu/dialog.h index 376ef701d..b0cde3bc9 100644 --- a/src/bfu/dialog.h +++ b/src/bfu/dialog.h @@ -131,6 +131,7 @@ void refresh_dialog(struct dialog_data *, dialog_refresh_handler_T handler, void void select_widget(struct dialog_data *dlg_data, struct widget_data *widget_data); struct widget_data *select_widget_by_id(struct dialog_data *dlg_data, int i); +#define before_widgets(dlg_data) (&(dlg_data)->widgets_data[-1]) #define end_of_widgets(dlg_data) (&(dlg_data)->widgets_data[(dlg_data)->number_of_widgets]) #define first_widget(dlg_data) (&(dlg_data)->widgets_data[0]) #define last_widget(dlg_data) (&(dlg_data)->widgets_data[(dlg_data)->number_of_widgets - 1]) @@ -140,6 +141,11 @@ struct widget_data *select_widget_by_id(struct dialog_data *dlg_data, int i); (widget_data) != end_of_widgets(dlg_data); \ (widget_data)++) +#define foreach_widget_back(dlg_data, widget_data) \ + for ((widget_data) = last_widget(dlg_data); \ + (widget_data) != before_widgets(dlg_data); \ + (widget_data)--) + #define is_selected_widget(dlg_data, widget_data) ((widget_data) == selected_widget(dlg_data)) #define add_dlg_end(dlg, n) \