[Bf-blender-cvs] [2011d1f6d0d] asset-browser-grid-view: Various GUI tweaks

Julian Eisel noreply at git.blender.org
Wed Feb 9 18:05:24 CET 2022


Commit: 2011d1f6d0d583a647d3a68403b900796895f552
Author: Julian Eisel
Date:   Wed Feb 9 17:59:01 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rB2011d1f6d0d583a647d3a68403b900796895f552

Various GUI tweaks

- Tweak tile size to match previous Asset Browser better
- Reduce margins between preview tiles (grid view was ignoring `align`
  parameter).
- Improve placement of text below previews (allowing previews to be
  slightly bigger).
- Tweak margins of main asset browser layout.

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

M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_assets/asset_browser_draw.cc

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 4838bb1fa8c..59a184a5a01 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -4929,21 +4929,33 @@ int UI_autocomplete_end(AutoComplete *autocpl, char *autoname)
   return match;
 }
 
+#define PREVIEW_TILE_PAD (0.15f * UI_UNIT_X)
+
 int UI_preview_tile_size_x(void)
 {
-  return round_fl_to_int((96.0f / 20.0f) * UI_UNIT_X);
+  const float pad = PREVIEW_TILE_PAD;
+  return round_fl_to_int((96.0f / 20.0f) * UI_UNIT_X + 2.0f * pad);
 }
 
 int UI_preview_tile_size_y(void)
 {
-  return round_fl_to_int((96.0f / 20.0f) * UI_UNIT_Y);
+  const uiStyle *style = UI_style_get();
+  const float font_height = style->widget.points * UI_DPI_FAC;
+  const float pad = PREVIEW_TILE_PAD;
+
+  return round_fl_to_int(UI_preview_tile_size_y_no_label() + font_height +
+                         /* Add some extra padding to make things less tight vertically. */
+                         pad);
 }
 
 int UI_preview_tile_size_y_no_label(void)
 {
-  return round_fl_to_int((96.0f / 20.0f) * UI_UNIT_Y - UI_UNIT_Y);
+  const float pad = PREVIEW_TILE_PAD;
+  return round_fl_to_int((96.0f / 20.0f) * UI_UNIT_Y + 2.0f * pad);
 }
 
+#undef PREVIEW_TILE_PAD
+
 static void ui_but_update_and_icon_set(uiBut *but, int icon)
 {
   if (icon) {
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 98fcb36b778..43cd3bb7175 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -4444,8 +4444,8 @@ static void ui_litem_layout_grid_flow(uiLayout *litem)
   BLI_assert(gflow->tot_columns > 0);
   BLI_assert(gflow->tot_rows > 0);
 
-  const int space_x = style->columnspace;
-  const int space_y = style->buttonspacey;
+  const int space_x = litem->align ? 0 : style->columnspace;
+  const int space_y = litem->align ? 0 : style->buttonspacey;
 
   int *widths = BLI_array_alloca(widths, gflow->tot_columns);
   int *heights = BLI_array_alloca(heights, gflow->tot_rows);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 3668435c642..0df81e06721 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -5506,13 +5506,17 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
                                     eFontStyle_Align text_align)
 {
   rcti trect = *rect;
-  const float text_size = UI_UNIT_Y;
   float font_dims[2] = {0.0f, 0.0f};
   const bool has_text = name && name[0];
+  const float padding = PREVIEW_PAD;
 
   if (has_text) {
+    UI_fontstyle_set(fstyle);
+    BLF_width_and_height(
+        fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
+
     /* draw icon in rect above the space reserved for the label */
-    rect->ymin += text_size;
+    rect->ymin += round_fl_to_int(font_dims[1] + 2 * padding);
   }
   GPU_blend(GPU_BLEND_ALPHA);
   widget_draw_preview(iconid, 1.0f, rect);
@@ -5522,15 +5526,9 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
     return;
   }
 
-  BLF_width_and_height(
-      fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
-
   /* text rect */
-  trect.ymin += U.widget_unit / 2;
-  trect.ymax = trect.ymin + font_dims[1];
-  if (trect.xmax > rect->xmax - PREVIEW_PAD) {
-    trect.xmax = rect->xmax - PREVIEW_PAD;
-  }
+  BLI_rcti_pad(&trect, -padding * 2, -padding * 2);
+  trect.ymax = round_fl_to_int(trect.ymin + font_dims[1]);
 
   {
     char drawstr[UI_MAX_DRAW_STR];
diff --git a/source/blender/editors/space_assets/asset_browser_draw.cc b/source/blender/editors/space_assets/asset_browser_draw.cc
index a602f810de0..09cd0a7b311 100644
--- a/source/blender/editors/space_assets/asset_browser_draw.cc
+++ b/source/blender/editors/space_assets/asset_browser_draw.cc
@@ -46,9 +46,19 @@ void asset_browser_main_region_draw(const bContext *C, ARegion *region)
   UI_view2d_view_ortho(v2d);
 
   const uiStyle *style = UI_style_get_dpi();
+  const float padding = style->panelouter;
   uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS);
   uiLayout *layout = UI_block_layout(
-      block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, style->panelspace, 0, region->winx, 1, 0, style);
+      block,
+      UI_LAYOUT_VERTICAL,
+      UI_LAYOUT_PANEL,
+      padding,
+      -padding,
+      /* 3x (instead of 2x) padding to add extra space for the scrollbar on the right. */
+      region->winx - 3 * padding,
+      1,
+      0,
+      style);
 
   asset_view_create_in_layout(
       *C, asset_space->asset_library_ref, asset_space->catalog_filter, *layout);



More information about the Bf-blender-cvs mailing list