[Bf-blender-cvs] [a977ed19200] temp-spreadsheet-editor: automatically adapt index column width

Jacques Lucke noreply at git.blender.org
Thu Feb 25 13:33:58 CET 2021


Commit: a977ed19200a06f8cae0c120dc9fe901d561ace9
Author: Jacques Lucke
Date:   Thu Feb 25 13:30:35 2021 +0100
Branches: temp-spreadsheet-editor
https://developer.blender.org/rBa977ed19200a06f8cae0c120dc9fe901d561ace9

automatically adapt index column width

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

M	source/blender/editors/space_spreadsheet/space_spreadsheet.cc

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

diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
index 027c67697e2..1e8b3ab1ded 100644
--- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
+++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc
@@ -776,11 +776,14 @@ static void spreadsheet_main_region_draw(const bContext *C, ARegion *region)
   ResourceCollector resources;
 
   SpreadsheetLayout spreadsheet_layout;
-  spreadsheet_layout.index_column_width = 2 * UI_UNIT_X;
-  spreadsheet_layout.row_height = UI_UNIT_Y;
-  spreadsheet_layout.title_row_height = 1.25 * UI_UNIT_Y;
   int row_amount;
   gather_spreadsheet_data(C, spreadsheet_layout, resources, &row_amount);
+  const std::string last_index_str = std::to_string(row_amount - 1);
+  const int fontid = UI_style_get()->widget.uifont_id;
+  spreadsheet_layout.index_column_width = last_index_str.size() * BLF_width(fontid, "0", 1) +
+                                          UI_UNIT_X * 0.75;
+  spreadsheet_layout.row_height = UI_UNIT_Y;
+  spreadsheet_layout.title_row_height = 1.25 * UI_UNIT_Y;
 
   draw_spreadsheet(C, spreadsheet_layout, region, IndexRange(row_amount).as_span());
   update_view2d_tot_rect(spreadsheet_layout, region, row_amount);



More information about the Bf-blender-cvs mailing list