Page MenuHome
Paste P2100

UI: Move list filtering to the top
ActivePublic

Authored by Julian Eisel (Severin) on Apr 30 2021, 5:09 PM.
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index bffb2c7c518..b0a323ea0bc 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -6263,6 +6263,62 @@ static uiList *ui_list_ensure(bContext *C,
return ui_list;
}
+static void template_list_filter_buttons(bContext *C,
+ uiList *ui_list,
+ uiLayout *layout,
+ const TemplateListLayoutDrawData *layout_data)
+{
+ uiBlock *block = uiLayoutGetBlock(layout);
+
+ uiLayoutRow(layout, true);
+ UI_block_emboss_set(block, UI_EMBOSS_NONE);
+
+ if (ui_list->filter_flag & UILST_FLT_SHOW) {
+ uiBut *but = uiDefIconButBitI(block,
+ UI_BTYPE_TOGGLE,
+ UILST_FLT_SHOW,
+ 0,
+ ICON_DISCLOSURE_TRI_DOWN,
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y * 0.5f,
+ &(ui_list->filter_flag),
+ 0,
+ 0,
+ 0,
+ 0,
+ TIP_("Hide filtering options"));
+ UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
+
+ UI_block_emboss_set(block, UI_EMBOSS);
+
+ uiLayout *col = uiLayoutColumn(layout, false);
+ layout_data->draw_filter(ui_list, C, col);
+ uiItemS(layout);
+ }
+ else {
+ uiBut *but = uiDefIconButBitI(block,
+ UI_BTYPE_TOGGLE,
+ UILST_FLT_SHOW,
+ 0,
+ ICON_DISCLOSURE_TRI_RIGHT,
+ 0,
+ 0,
+ UI_UNIT_X,
+ UI_UNIT_Y * 0.5f,
+ &(ui_list->filter_flag),
+ 0,
+ 0,
+ 0,
+ 0,
+ TIP_("Show filtering options"));
+ UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
+ }
+
+ UI_block_emboss_set(block, UI_EMBOSS);
+}
+
static void ui_template_list_layout_draw(bContext *C,
uiList *ui_list,
uiLayout *layout,
@@ -6274,12 +6330,8 @@ static void ui_template_list_layout_draw(bContext *C,
uiListDyn *dyn_data = ui_list->dyn_data;
const char *active_propname = RNA_property_identifier(input_data->activeprop);
- uiLayout *glob = NULL, *box, *row, *col, *subrow, *sub, *overlap;
char numstr[32];
int rnaicon = ICON_NONE, icon = ICON_NONE;
- uiBut *but;
-
- uiBlock *block = uiLayoutGetBlock(layout);
/* get icon */
if (input_data->dataptr.data && input_data->prop) {
@@ -6287,14 +6339,30 @@ static void ui_template_list_layout_draw(bContext *C,
rnaicon = RNA_struct_ui_icon(ptype);
}
+ uiBlock *block = uiLayoutGetBlock(layout);
+ uiBut *but;
+
+ uiLayout *box_col = NULL, *box, *scrollable_row, *col, *subrow, *sub, *overlap;
+ const bool use_box = ELEM(ui_list->layout_type,
+ UILST_LAYOUT_DEFAULT,
+ UILST_LAYOUT_GRID,
+ UILST_LAYOUT_BIG_PREVIEW_GRID);
+ if (use_box) {
+ box = uiLayoutListBox(layout, ui_list, &input_data->active_dataptr, input_data->activeprop);
+ /* The main layout of the list box. */
+ box_col = uiLayoutColumn(box, true);
+
+ template_list_filter_buttons(C, ui_list, box_col, layout_data);
+
+ /* The layout to place the scrollbar in. Everything added to it will scroll (except of the
+ * scrollbar itself). */
+ scrollable_row = uiLayoutRow(box_col, false);
+ }
+
TemplateListVisualInfo visual_info;
switch (ui_list->layout_type) {
case UILST_LAYOUT_DEFAULT: {
- /* layout */
- box = uiLayoutListBox(layout, ui_list, &input_data->active_dataptr, input_data->activeprop);
- glob = uiLayoutColumn(box, true);
- row = uiLayoutRow(glob, false);
- col = uiLayoutColumn(row, true);
+ col = uiLayoutColumn(scrollable_row, true);
TemplateListLayoutDrawData adjusted_layout_data = *layout_data;
adjusted_layout_data.columns = 1;
@@ -6376,7 +6444,7 @@ static void ui_template_list_layout_draw(bContext *C,
/* add scrollbar */
if (items->tot_items > visual_info.visual_items) {
- uiLayoutColumn(row, false);
+ uiLayoutColumn(scrollable_row, false);
uiDefButI(block,
UI_BTYPE_SCROLL,
0,
@@ -6393,8 +6461,8 @@ static void ui_template_list_layout_draw(bContext *C,
"");
}
} break;
- case UILST_LAYOUT_COMPACT:
- row = uiLayoutRow(layout, true);
+ case UILST_LAYOUT_COMPACT: {
+ uiLayout *row = uiLayoutRow(layout, true);
if ((input_data->dataptr.data && input_data->prop) && (dyn_data->items_shown > 0) &&
(items->active_item_idx >= 0) && (items->active_item_idx < dyn_data->items_shown)) {
@@ -6444,11 +6512,9 @@ static void ui_template_list_layout_draw(bContext *C,
UI_but_flag_enable(but, UI_BUT_DISABLED);
}
break;
+ }
case UILST_LAYOUT_GRID: {
- box = uiLayoutListBox(layout, ui_list, &input_data->active_dataptr, input_data->activeprop);
- glob = uiLayoutColumn(box, true);
- row = uiLayoutRow(glob, false);
- col = uiLayoutColumn(row, true);
+ col = uiLayoutColumn(scrollable_row, true);
subrow = NULL; /* Quite gcc warning! */
uilist_prepare(ui_list, items, layout_data, &visual_info);
@@ -6525,7 +6591,7 @@ static void ui_template_list_layout_draw(bContext *C,
/* add scrollbar */
if (items->tot_items > visual_info.visual_items) {
- /* col = */ uiLayoutColumn(row, false);
+ /* col = */ uiLayoutColumn(scrollable_row, false);
uiDefButI(block,
UI_BTYPE_SCROLL,
0,
@@ -6543,19 +6609,13 @@ static void ui_template_list_layout_draw(bContext *C,
}
break;
}
- case UILST_LAYOUT_BIG_PREVIEW_GRID:
- box = uiLayoutListBox(layout, ui_list, &input_data->active_dataptr, input_data->activeprop);
- /* For grip button. */
- glob = uiLayoutColumn(box, true);
- /* For scrollbar. */
- row = uiLayoutRow(glob, false);
-
+ case UILST_LAYOUT_BIG_PREVIEW_GRID: {
/* TODO ED_fileselect_init_layout(). Share somehow? */
float size_x = (96.0f / 20.0f) * UI_UNIT_X;
float size_y = (96.0f / 20.0f) * UI_UNIT_Y;
const int cols_per_row = MAX2((uiLayoutGetWidth(box) - V2D_SCROLL_WIDTH) / size_x, 1);
- uiLayout *grid = uiLayoutGridFlow(row, true, cols_per_row, true, true, true);
+ uiLayout *grid = uiLayoutGridFlow(scrollable_row, true, cols_per_row, true, true, true);
TemplateListLayoutDrawData adjusted_layout_data = *layout_data;
adjusted_layout_data.columns = cols_per_row;
@@ -6620,7 +6680,7 @@ static void ui_template_list_layout_draw(bContext *C,
}
if (items->tot_items > visual_info.visual_items) {
- /* col = */ uiLayoutColumn(row, false);
+ /* col = */ uiLayoutColumn(scrollable_row, false);
uiDefButI(block,
UI_BTYPE_SCROLL,
0,
@@ -6637,9 +6697,10 @@ static void ui_template_list_layout_draw(bContext *C,
"");
}
break;
+ }
}
- if (glob) {
+ if (box_col) {
const bool add_grip_but = (flags & UI_TEMPLATE_LIST_NO_GRIP) == 0;
/* About #UI_BTYPE_GRIP drag-resize:
@@ -6658,104 +6719,24 @@ static void ui_template_list_layout_draw(bContext *C,
dyn_data->resize = dyn_data->resize_prev +
(dyn_data->visual_height - ui_list->list_grip) * UI_UNIT_Y;
- row = uiLayoutRow(glob, true);
- uiBlock *subblock = uiLayoutGetBlock(row);
- UI_block_emboss_set(subblock, UI_EMBOSS_NONE);
-
- if (ui_list->filter_flag & UILST_FLT_SHOW) {
- but = uiDefIconButBitI(subblock,
- UI_BTYPE_TOGGLE,
- UILST_FLT_SHOW,
- 0,
- ICON_DISCLOSURE_TRI_DOWN,
- 0,
- 0,
- UI_UNIT_X,
- UI_UNIT_Y * 0.5f,
- &(ui_list->filter_flag),
- 0,
- 0,
- 0,
- 0,
- TIP_("Hide filtering options"));
- UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
-
- if (add_grip_but) {
- but = uiDefIconButI(subblock,
- UI_BTYPE_GRIP,
- 0,
- ICON_GRIP,
- 0,
- 0,
- UI_UNIT_X * 10.0f,
- UI_UNIT_Y * 0.5f,
- &dyn_data->resize,
- 0.0,
- 0.0,
- 0,
- 0,
- "");
- UI_but_func_set(but, uilist_resize_update_cb, ui_list, NULL);
- }
-
- UI_block_emboss_set(subblock, UI_EMBOSS);
-
- col = uiLayoutColumn(glob, false);
- subblock = uiLayoutGetBlock(col);
- uiDefBut(subblock,
- UI_BTYPE_SEPR,
- 0,
- "",
- 0,
- 0,
- UI_UNIT_X,
- UI_UNIT_Y * 0.05f,
- NULL,
- 0.0,
- 0.0,
- 0,
- 0,
- "");
-
- layout_data->draw_filter(ui_list, C, col);
- }
- else {
- but = uiDefIconButBitI(subblock,
- UI_BTYPE_TOGGLE,
- UILST_FLT_SHOW,
- 0,
- ICON_DISCLOSURE_TRI_RIGHT,
- 0,
- 0,
- UI_UNIT_X,
- UI_UNIT_Y * 0.5f,
- &(ui_list->filter_flag),
- 0,
- 0,
- 0,
- 0,
- TIP_("Show filtering options"));
- UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */
-
- if (add_grip_but) {
- but = uiDefIconButI(subblock,
- UI_BTYPE_GRIP,
- 0,
- ICON_GRIP,
- 0,
- 0,
- UI_UNIT_X * 10.0f,
- UI_UNIT_Y * 0.5f,
- &dyn_data->resize,
- 0.0,
- 0.0,
- 0,
- 0,
- "");
- UI_but_func_set(but, uilist_resize_update_cb, ui_list, NULL);
- }
-
- UI_block_emboss_set(subblock, UI_EMBOSS);
+ if (add_grip_but) {
+ uiLayoutRow(box_col, true);
+ but = uiDefIconButI(block,
+ UI_BTYPE_GRIP,
+ 0,
+ ICON_GRIP,
+ 0,
+ 0,
+ UI_UNIT_X * 10.0f,
+ UI_UNIT_Y * 0.5f,
+ &dyn_data->resize,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+ UI_but_func_set(but, uilist_resize_update_cb, ui_list, NULL);
+ but->emboss = UI_EMBOSS_NONE;
}
}
}

Event Timeline

Note that this is based on the asset-browser-poselib branch, for which I refactored much of the UI list drawing code.