[Bf-blender-cvs] [1a4d0fa72d8] master: Spreadsheet: add spreadsheet width unit

Jacques Lucke noreply at git.blender.org
Mon Apr 12 09:14:50 CEST 2021


Commit: 1a4d0fa72d83bf6c7413d70172766801976c1671
Author: Jacques Lucke
Date:   Mon Apr 12 09:14:41 2021 +0200
Branches: master
https://developer.blender.org/rB1a4d0fa72d83bf6c7413d70172766801976c1671

Spreadsheet: add spreadsheet width unit

This also fixes the issue that the width of the "Name" column
when viewing instances does not resize correctly.

Differential Revision: https://developer.blender.org/D10926

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

M	source/blender/editors/space_spreadsheet/space_spreadsheet.cc
M	source/blender/makesdna/DNA_space_types.h

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

diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index d34b625293c..9d79e7abcc5 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -175,14 +175,18 @@ static std::unique_ptr<DataSource> get_data_source(const bContext *C)
 static float get_column_width(const ColumnValues &values)
 {
   if (values.default_width > 0) {
-    return values.default_width * UI_UNIT_X;
+    return values.default_width;
   }
   const int fontid = UI_style_get()->widget.uifont_id;
-  const int widget_points = UI_style_get_dpi()->widget.points;
-  BLF_size(fontid, widget_points * U.pixelsize, U.dpi);
+  BLF_size(fontid, UI_DEFAULT_TEXT_POINTS, U.dpi);
   const StringRefNull name = values.name();
   const float name_width = BLF_width(fontid, name.data(), name.size());
-  return std::max<float>(name_width + UI_UNIT_X, 3 * UI_UNIT_X);
+  return std::max<float>(name_width / UI_UNIT_X + 1.0f, 3.0f);
+}
+
+static float get_column_width_in_pixels(const ColumnValues &values)
+{
+  return get_column_width(values) * SPREADSHEET_WIDTH_UNIT;
 }
 
 static int get_index_column_width(const int tot_rows)
@@ -239,7 +243,7 @@ static void spreadsheet_main_region_draw(const bContext *C, ARegion *region)
     /* Should have been removed before if it does not exist anymore. */
     BLI_assert(values_ptr);
     const ColumnValues *values = scope.add(std::move(values_ptr), __func__);
-    const int width = get_column_width(*values);
+    const int width = get_column_width_in_pixels(*values);
     spreadsheet_layout.columns.append({values, width});
   }
 
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index a90047b9daa..747e392b529 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1909,6 +1909,13 @@ typedef enum eSpaceSpreadsheet_ObjectEvalState {
   SPREADSHEET_OBJECT_EVAL_STATE_NODE = 2,
 } eSpaceSpreadsheet_Context;
 
+/**
+ * We can't just use UI_UNIT_X, because it does not take `widget.points` into account, which
+ * modifies the width of text as well.
+ */
+#define SPREADSHEET_WIDTH_UNIT \
+  (UI_UNIT_X * UI_style_get_dpi()->widget.points / (float)UI_DEFAULT_TEXT_POINTS)
+
 /** \} */
 
 /* -------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list