diff options
Diffstat (limited to 'source/blender/editors/screen/area.c')
-rw-r--r-- | source/blender/editors/screen/area.c | 127 |
1 files changed, 105 insertions, 22 deletions
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 96aad89827f..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); } } } @@ -2519,6 +2559,7 @@ void ED_region_panels_layout_ex(const bContext *C, int margin_x = 0; const bool region_layout_based = region->flag & RGN_FLAG_DYNAMIC_SIZE; const bool is_context_new = (contextnr != -1) ? UI_view2d_tab_set(v2d, contextnr) : false; + bool update_tot_size = true; /* before setting the view */ if (vertical) { @@ -2536,7 +2577,6 @@ void ED_region_panels_layout_ex(const bContext *C, v2d->scroll |= (V2D_SCROLL_BOTTOM); v2d->scroll &= ~(V2D_SCROLL_RIGHT); } - const int scroll = v2d->scroll; /* collect categories */ if (use_category_tabs) { @@ -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(®ion->panels, pt); if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) { @@ -2588,7 +2635,51 @@ void ED_region_panels_layout_ex(const bContext *C, } } - ed_panel_draw(C, area, region, ®ion->panels, pt, panel, w, em, vertical); + if (panel && UI_panel_is_dragging(panel)) { + /* Prevent View2d.tot rectangle size changes while dragging panels. */ + update_tot_size = false; + } + + ed_panel_draw(C, + area, + region, + ®ion->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, ®ion->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, + ®ion->panels, + panel->type, + panel, + (panel->type->flag & PNL_DRAW_BOX) ? w_box_panel : w, + em, + vertical, + unique_panel_str); + } + } } /* align panels and return size */ @@ -2643,17 +2734,9 @@ void ED_region_panels_layout_ex(const bContext *C, y = -y; } - /* this also changes the 'cur' */ - UI_view2d_totRect_set(v2d, x, y); - - if (scroll != v2d->scroll) { - /* Note: this code scales fine, but because of rounding differences, positions of elements - * flip +1 or -1 pixel compared to redoing the entire layout again. - * Leaving in commented code for future tests */ -#if 0 - UI_panels_scale(region, BLI_rctf_size_x(&v2d->cur)); - break; -#endif + if (update_tot_size) { + /* this also changes the 'cur' */ + UI_view2d_totRect_set(v2d, x, y); } if (use_category_tabs) { |