[Bf-blender-cvs] [5514ca58a4d] blender-v3.0-release: Fix T92313: Heading of redo panel is not aligned properly

Julian Eisel noreply at git.blender.org
Thu Nov 25 17:10:04 CET 2021


Commit: 5514ca58a4d4e03d9062bc479488faca7e577677
Author: Julian Eisel
Date:   Thu Nov 25 16:53:44 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rB5514ca58a4d4e03d9062bc479488faca7e577677

Fix T92313: Heading of redo panel is not aligned properly

This corrects some alignments issues through new margins introduced in
93544b641bd6. Basic idea of this fix is to only add the new margins when
drawing a panel with background. These margins were added specifically
for the background boxes, so that makes sense.

Alternative fix to D13199.

This also fixes some margings added unintentionally in mentioned commit.
There is a little jump of the toolbar and the tabs in the Properties
when comparing the UI without this fix to 2.93:
{F12158085} {F12158039}
The jump is gone with this fix applied (compare to the 2.93 screenshot):
{F12158064}
While not a serious issue, this confirms that this fix actually tackles
the root of the issue.

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/screen/area.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index d9f6c89e03b..f5240a2bedb 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -257,6 +257,8 @@ enum {
 
 #define UI_PANEL_CATEGORY_MARGIN_WIDTH (U.widget_unit * 1.0f)
 
+/* Both these margins should be ignored if the panel doesn't show a background (check
+ * #UI_panel_should_show_background()). */
 #define UI_PANEL_MARGIN_X (U.widget_unit * 0.4f)
 #define UI_PANEL_MARGIN_Y (U.widget_unit * 0.1f)
 
@@ -1771,6 +1773,8 @@ void UI_panel_context_pointer_set(struct Panel *panel, const char *name, struct
 bool UI_panel_is_closed(const struct Panel *panel);
 bool UI_panel_is_active(const struct Panel *panel);
 void UI_panel_label_offset(const struct uiBlock *block, int *r_x, int *r_y);
+bool UI_panel_should_show_background(const struct ARegion *region,
+                                     const struct PanelType *panel_type);
 int UI_panel_size_y(const struct Panel *panel);
 bool UI_panel_is_dragging(const struct Panel *panel);
 bool UI_panel_matches_search_filter(const struct Panel *panel);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 6ad0ef9de18..c5ccdbaac3b 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2075,24 +2075,11 @@ void UI_block_draw(const bContext *C, uiBlock *block)
     ui_draw_menu_back(&style, block, &rect);
   }
   else if (block->panel) {
-    bool show_background = region->alignment != RGN_ALIGN_FLOAT;
-    if (show_background) {
-      if (block->panel->type && (block->panel->type->flag & PANEL_TYPE_NO_HEADER)) {
-        if (region->regiontype == RGN_TYPE_TOOLS) {
-          /* We never want a background around active tools. */
-          show_background = false;
-        }
-        else {
-          /* Without a header there is no background except for region overlap. */
-          show_background = region->overlap != 0;
-        }
-      }
-    }
     ui_draw_aligned_panel(&style,
                           block,
                           &rect,
                           UI_panel_category_is_visible(region),
-                          show_background,
+                          UI_panel_should_show_background(region, block->panel->type),
                           region->flag & RGN_FLAG_SEARCH_FILTER_ACTIVE);
   }
 
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 6aa4c5bb4a7..d1daf5b48bf 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -1334,6 +1334,26 @@ void ui_draw_aligned_panel(const uiStyle *style,
   }
 }
 
+bool UI_panel_should_show_background(const ARegion *region, const PanelType *panel_type)
+{
+  if (region->alignment == RGN_ALIGN_FLOAT) {
+    return false;
+  }
+
+  if (panel_type && panel_type->flag & PANEL_TYPE_NO_HEADER) {
+    if (region->regiontype == RGN_TYPE_TOOLS) {
+      /* We never want a background around active tools. */
+      return false;
+    }
+    else {
+      /* Without a header there is no background except for region overlap. */
+      return region->overlap != 0;
+    }
+  }
+
+  return true;
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -1746,17 +1766,22 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra
   const int region_offset_x = panel_region_offset_x_get(region);
   for (int i = 0; i < active_panels_len; i++) {
     PanelSort *ps = &panel_sort[i];
-    const bool no_header = ps->panel->type->flag & PANEL_TYPE_NO_HEADER;
+    const bool show_background = UI_panel_should_show_background(region, ps->panel->type);
     ps->panel->runtime.region_ofsx = region_offset_x;
-    ps->new_offset_x = region_offset_x + (no_header ? 0 : UI_PANEL_MARGIN_X);
+    ps->new_offset_x = region_offset_x + (show_background ? UI_PANEL_MARGIN_X : 0);
   }
 
   /* Y offset. */
   for (int i = 0, y = 0; i < active_panels_len; i++) {
     PanelSort *ps = &panel_sort[i];
+    const bool show_background = UI_panel_should_show_background(region, ps->panel->type);
+
     y -= get_panel_real_size_y(ps->panel);
 
-    y -= UI_PANEL_MARGIN_Y;
+    /* Separate panel boxes a bit further (if they are drawn). */
+    if (show_background) {
+      y -= UI_PANEL_MARGIN_Y;
+    }
     ps->new_offset_y = y;
     /* The header still draws offset by the size of closed panels, so apply the offset here. */
     if (UI_panel_is_closed(ps->panel)) {
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 80c14371c16..fc839d5cd63 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2934,6 +2934,16 @@ static const char *region_panels_collect_categories(ARegion *region,
   return NULL;
 }
 
+static int panel_draw_width_from_max_width_get(const ARegion *region,
+                                               const PanelType *panel_type,
+                                               const int max_width)
+{
+  /* With a background, we want some extra padding. */
+  return UI_panel_should_show_background(region, panel_type) ?
+             max_width - UI_PANEL_MARGIN_X * 2.0f :
+             max_width;
+}
+
 /**
  * \param contexts: A NULL terminated array of context strings to match against.
  * Matching against any of these strings will draw the panel.
@@ -2982,7 +2992,6 @@ void ED_region_panels_layout_ex(const bContext *C,
   }
 
   const int width_no_header = BLI_rctf_size_x(&v2d->cur) - margin_x;
-  const int width = width_no_header - UI_PANEL_MARGIN_X * 2.0f;
   /* Works out to 10 * UI_UNIT_X or 20 * UI_UNIT_X. */
   const int em = (region->type->prefsizex) ? 10 : 20;
 
@@ -3010,6 +3019,7 @@ void ED_region_panels_layout_ex(const bContext *C,
         continue;
       }
     }
+    const int width = panel_draw_width_from_max_width_get(region, pt, width_no_header);
 
     if (panel && UI_panel_is_dragging(panel)) {
       /* Prevent View2d.tot rectangle size changes while dragging panels. */
@@ -3040,6 +3050,7 @@ void ED_region_panels_layout_ex(const bContext *C,
           !STREQ(category, panel->type->category)) {
         continue;
       }
+      const int width = panel_draw_width_from_max_width_get(region, panel->type, width_no_header);
 
       if (panel && UI_panel_is_dragging(panel)) {
         /* Prevent View2d.tot rectangle size changes while dragging panels. */



More information about the Bf-blender-cvs mailing list