[Bf-blender-cvs] [ae51cde3d78] temp-spreadsheet-instances: Larger width for name column, use values for object and collection specifically
Hans Goudey
noreply at git.blender.org
Fri Mar 19 17:44:46 CET 2021
Commit: ae51cde3d783b1cec848dd8f78f3b91d85e90d8d
Author: Hans Goudey
Date: Fri Mar 19 12:38:35 2021 -0400
Branches: temp-spreadsheet-instances
https://developer.blender.org/rBae51cde3d783b1cec848dd8f78f3b91d85e90d8d
Larger width for name column, use values for object and collection specifically
===================================================================
M source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc
M source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh
M source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
===================================================================
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc
index acd6330de41..00724ffd4b0 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc
@@ -52,10 +52,15 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer {
const int minimum_column_width = 3 * UI_UNIT_X;
const int header_name_padding = UI_UNIT_X;
for (const SpreadsheetColumn *column : column_layout_.columns) {
- StringRefNull name = column->name();
- const int name_width = BLF_width(fontid, name.data(), name.size());
- const int width = std::max(name_width + header_name_padding, minimum_column_width);
- column_widths_.append(width);
+ if (column->default_width == 0.0f) {
+ StringRefNull name = column->name();
+ const int name_width = BLF_width(fontid, name.data(), name.size());
+ const int width = std::max(name_width + header_name_padding, minimum_column_width);
+ column_widths_.append(width);
+ }
+ else {
+ column_widths_.append(column->default_width * UI_UNIT_X);
+ }
}
}
@@ -172,13 +177,31 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer {
0,
nullptr);
}
- else if (std::holds_alternative<IconText>(cell_value.value)) {
- const IconText value = *std::get_if<IconText>(&cell_value.value);
+ else if (std::holds_alternative<ObjectCellValue>(cell_value.value)) {
+ const ObjectCellValue value = *std::get_if<ObjectCellValue>(&cell_value.value);
uiDefIconTextBut(params.block,
UI_BTYPE_LABEL,
0,
- value.icon_id,
- value.string.data(),
+ ICON_OBJECT_DATA,
+ reinterpret_cast<const ID *const>(value.object)->name + 2,
+ params.xmin,
+ params.ymin,
+ params.width,
+ params.height,
+ nullptr,
+ 0,
+ 0,
+ 0,
+ 0,
+ nullptr);
+ }
+ else if (std::holds_alternative<CollectionCellValue>(cell_value.value)) {
+ const CollectionCellValue value = *std::get_if<CollectionCellValue>(&cell_value.value);
+ uiDefIconTextBut(params.block,
+ UI_BTYPE_LABEL,
+ 0,
+ ICON_OUTLINER_COLLECTION,
+ reinterpret_cast<const ID *const>(value.collection)->name + 2,
params.xmin,
params.ymin,
params.width,
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh
index b36689760ed..85217d35289 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh
@@ -20,11 +20,19 @@
#include "spreadsheet_draw.hh"
+// struct Object;
+// struct Collection;
+#include "DNA_collection_types.h"
+#include "DNA_object_types.h"
+
namespace blender::ed::spreadsheet {
-struct IconText {
- int icon_id;
- StringRefNull string;
+struct ObjectCellValue {
+ const Object *object;
+};
+
+struct CollectionCellValue {
+ const Collection *collection;
};
/**
@@ -35,7 +43,8 @@ class CellValue {
public:
/* The implementation just uses a `std::variant` for simplicity. It can be encapsulated better,
* but it's not really worth the complixity for now. */
- using VariantType = std::variant<std::monostate, int, float, bool, IconText>;
+ using VariantType =
+ std::variant<std::monostate, int, float, bool, ObjectCellValue, CollectionCellValue>;
VariantType value;
};
@@ -61,6 +70,9 @@ class SpreadsheetColumn {
{
return name_;
}
+
+ /* The default width of newly created columns, in UI units. */
+ float default_width = 0.0f;
};
/* Utility class for the function below. */
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
index e6ee0ce0432..0937e81c309 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
@@ -29,8 +29,6 @@
#include "DEG_depsgraph_query.h"
-#include "UI_resources.h"
-
#include "bmesh.h"
#include "spreadsheet_from_geometry.hh"
@@ -41,34 +39,6 @@ namespace blender::ed::spreadsheet {
using blender::bke::ReadAttribute;
using blender::bke::ReadAttributePtr;
-static StringRefNull instance_data_name(const InstancedData &data)
-{
- switch (data.type) {
- case INSTANCE_DATA_TYPE_OBJECT: {
- const ID *id = reinterpret_cast<const ID *>(data.data.object);
- return id->name + 2;
- }
- case INSTANCE_DATA_TYPE_COLLECTION: {
- const ID *id = reinterpret_cast<const ID *>(data.data.object);
- return id->name + 2;
- }
- }
- return nullptr;
-}
-
-static int instance_data_icon_id(const InstancedData &data)
-{
- switch (data.type) {
- case INSTANCE_DATA_TYPE_OBJECT: {
- return ICON_OBJECT_DATA;
- }
- case INSTANCE_DATA_TYPE_COLLECTION: {
- return ICON_OUTLINER_COLLECTION;
- }
- }
- return ICON_BLANK1;
-}
-
static void add_columns_for_instances(const InstancesComponent &instances_component,
SpreadsheetColumnLayout &column_layout,
ResourceCollector &resources)
@@ -82,9 +52,20 @@ static void add_columns_for_instances(const InstancesComponent &instances_compon
columns.append(spreadsheet_column_from_function(
"Name", [instance_data](int index, CellValue &r_cell_value) {
const InstancedData &data = instance_data[index];
- r_cell_value.value = IconText{instance_data_icon_id(data), instance_data_name(data)};
+ if (data.type == INSTANCE_DATA_TYPE_OBJECT) {
+ if (data.data.object != nullptr) {
+ r_cell_value.value = ObjectCellValue{data.data.object};
+ }
+ }
+ else if (data.type == INSTANCE_DATA_TYPE_COLLECTION) {
+ if (data.data.collection != nullptr) {
+ r_cell_value.value = CollectionCellValue{data.data.collection};
+ }
+ }
}));
+ columns.last().get()->default_width = 8.0f;
+
static std::array<char, 3> axis_char = {'X', 'Y', 'Z'};
for (const int i : {0, 1, 2}) {
std::string name = std::string("Position ") + axis_char[i];
More information about the Bf-blender-cvs
mailing list