Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2020-05-26 22:39:49 +0300
committerHans Goudey <h.goudey@me.com>2020-05-26 22:39:49 +0300
commit5171d86806a338aa885cdddf3ad83dfcf15c40aa (patch)
tree00fd7c3fc9c245485f742c73a175cf6c9a0adb30 /source/blender/editors/screen
parentde257b6366455ba6a3604c0830a92245df11f7bc (diff)
UI: List Panel System
This implements a general system to implement drag and drop, subpanels, and UI animation for the stack UIs in Blender. There are NO functional changes in this patch, but it makes it relatively trivial to implement these features for stacks. The biggest complication to using panels to implement the UI for lists is that there can be multiple modifiers of the same type. Currently there is an assumed 1 to 1 relationship between every panel and its type, but there can be multiple list items of the same type, so we have to break this relationship. The mapping between panels and their data is stored with an index in the panel's runtime struct. To make use the system for a list like modifiers, four components must be added: 1. A panel type defined and registered for each list data type, with a known mapping between list data types and panel idnames. 1. A function called by interface code to build the add the panel layouts with the provided helper functions. - UI_panel_list_matches_data will check if the panel list needs to be rebuilt. - UI_panels_free_instanced will remove the existing list panels - UI_panel_add_instanced adds a list panel of a given type. 3. An expand flag for the list data and implementations of get_list_data_expand_flag and set_list_data_expand_flag. 4. For reordering, the panel type's reorder callback. This is called when the instanced panels are drag-dropped. This requires implementing a "move to index" operator for the list data. Reviewed By: Severin, brecht Differential Revision: https://developer.blender.org/D7490
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r--source/blender/editors/screen/area.c106
1 files changed, 96 insertions, 10 deletions
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 48b54ddcea3..c04122edd36 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2345,6 +2345,15 @@ BLI_INLINE bool streq_array_any(const char *s, const char *arr[])
return false;
}
+/**
+ * Builds the panel layout for the input \a panel or type \a pt.
+ *
+ * \param panel The panel to draw. Can be null, in which case a panel with the type of \a pt will
+ * be created.
+ * \param unique_panel_str A unique identifier for the name of the \a uiBlock associated with the
+ * panel. Used when the panel is an instanced panel so a unique identifier is needed to find the
+ * correct old \a uiBlock, and NULL otherwise.
+ */
static void ed_panel_draw(const bContext *C,
ScrArea *area,
ARegion *region,
@@ -2353,18 +2362,27 @@ static void ed_panel_draw(const bContext *C,
Panel *panel,
int w,
int em,
- bool vertical)
+ bool vertical,
+ char *unique_panel_str)
{
const uiStyle *style = UI_style_get_dpi();
- /* draw panel */
- uiBlock *block = UI_block_begin(C, region, pt->idname, UI_EMBOSS);
+ /* Draw panel. */
+
+ char block_name[BKE_ST_MAXNAME + LIST_PANEL_UNIQUE_STR_LEN];
+ strncpy(block_name, pt->idname, BKE_ST_MAXNAME);
+ if (unique_panel_str != NULL) {
+ /* Instanced panels should have already been added at this point. */
+ strncat(block_name, unique_panel_str, LIST_PANEL_UNIQUE_STR_LEN);
+ }
+ uiBlock *block = UI_block_begin(C, region, block_name, UI_EMBOSS);
bool open;
panel = UI_panel_begin(area, region, lb, block, pt, panel, &open);
/* bad fixed values */
int xco, yco, h = 0;
+ int headerend = w - UI_UNIT_X;
if (pt->draw_header_preset && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
/* for preset menu */
@@ -2380,8 +2398,6 @@ static void ed_panel_draw(const bContext *C,
pt->draw_header_preset(C, panel);
- int headerend = w - UI_UNIT_X;
-
UI_block_layout_resolve(block, &xco, &yco);
UI_block_translate(block, headerend - xco, 0);
panel->layout = NULL;
@@ -2391,9 +2407,24 @@ static void ed_panel_draw(const bContext *C,
int labelx, labely;
UI_panel_label_offset(block, &labelx, &labely);
- /* for enabled buttons */
- panel->layout = UI_block_layout(
- block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, labelx, labely, UI_UNIT_Y, 1, 0, style);
+ /* Unusual case: Use expanding layout (buttons stretch to available width). */
+ if (pt->flag & PNL_LAYOUT_HEADER_EXPAND) {
+ uiLayout *layout = UI_block_layout(block,
+ UI_LAYOUT_VERTICAL,
+ UI_LAYOUT_PANEL,
+ labelx,
+ labely,
+ headerend - 2 * style->panelspace,
+ 1,
+ 0,
+ style);
+ panel->layout = uiLayoutRow(layout, false);
+ }
+ /* Regular case: Normal panel with fixed size buttons. */
+ else {
+ panel->layout = UI_block_layout(
+ block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, labelx, labely, UI_UNIT_Y, 1, 0, style);
+ }
pt->draw_header(C, panel);
@@ -2449,7 +2480,16 @@ static void ed_panel_draw(const bContext *C,
Panel *child_panel = UI_panel_find_by_type(&panel->children, child_pt);
if (child_pt->draw && (!child_pt->poll || child_pt->poll(C, child_pt))) {
- ed_panel_draw(C, area, region, &panel->children, child_pt, child_panel, w, em, vertical);
+ ed_panel_draw(C,
+ area,
+ region,
+ &panel->children,
+ child_pt,
+ child_panel,
+ w,
+ em,
+ vertical,
+ unique_panel_str);
}
}
}
@@ -2571,6 +2611,7 @@ void ED_region_panels_layout_ex(const bContext *C,
}
w -= margin_x;
+ int w_box_panel = w - UI_PANEL_BOX_STYLE_MARGIN * 2.0f;
/* create panels */
UI_panels_begin(C, region);
@@ -2578,8 +2619,14 @@ void ED_region_panels_layout_ex(const bContext *C,
/* set view2d view matrix - UI_block_begin() stores it */
UI_view2d_view_ortho(v2d);
+ bool has_instanced_panel = false;
for (LinkNode *pt_link = panel_types_stack; pt_link; pt_link = pt_link->next) {
PanelType *pt = pt_link->link;
+
+ if (pt->flag & PNL_INSTANCED) {
+ has_instanced_panel = true;
+ continue;
+ }
Panel *panel = UI_panel_find_by_type(&region->panels, pt);
if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) {
@@ -2593,7 +2640,46 @@ void ED_region_panels_layout_ex(const bContext *C,
update_tot_size = false;
}
- ed_panel_draw(C, area, region, &region->panels, pt, panel, w, em, vertical);
+ ed_panel_draw(C,
+ area,
+ region,
+ &region->panels,
+ pt,
+ panel,
+ (pt->flag & PNL_DRAW_BOX) ? w_box_panel : w,
+ em,
+ vertical,
+ NULL);
+ }
+
+ /* Draw "polyinstantaited" panels that don't have a 1 to 1 correspondence with their types. */
+ if (has_instanced_panel) {
+ LISTBASE_FOREACH (Panel *, panel, &region->panels) {
+ if (panel->type == NULL) {
+ continue; /* Some panels don't have a type.. */
+ }
+ if (panel->type->flag & PNL_INSTANCED) {
+ if (panel && UI_panel_is_dragging(panel)) {
+ /* Prevent View2d.tot rectangle size changes while dragging panels. */
+ update_tot_size = false;
+ }
+
+ /* Use a unique identifier for instanced panels, otherwise an old block for a different
+ * panel of the same type might be found. */
+ char unique_panel_str[8];
+ UI_list_panel_unique_str(panel, unique_panel_str);
+ ed_panel_draw(C,
+ area,
+ region,
+ &region->panels,
+ panel->type,
+ panel,
+ (panel->type->flag & PNL_DRAW_BOX) ? w_box_panel : w,
+ em,
+ vertical,
+ unique_panel_str);
+ }
+ }
}
/* align panels and return size */