Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_spreadsheet/space_spreadsheet.cc
| Show First 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | static std::unique_ptr<DataSource> get_data_source(const bContext *C) | ||||
| Object *object_eval = spreadsheet_get_object_eval(sspreadsheet, depsgraph); | Object *object_eval = spreadsheet_get_object_eval(sspreadsheet, depsgraph); | ||||
| if (object_eval) { | if (object_eval) { | ||||
| return data_source_from_geometry(C, object_eval); | return data_source_from_geometry(C, object_eval); | ||||
| } | } | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| static float get_column_width(const ColumnValues &values) | static float get_default_column_width(const ColumnValues &values) | ||||
| { | { | ||||
| if (values.default_width > 0) { | if (values.default_width > 0.0f) { | ||||
| return values.default_width; | return values.default_width; | ||||
| } | } | ||||
| static const float float_width = 3; | |||||
| switch (values.type()) { | |||||
| case SPREADSHEET_VALUE_TYPE_BOOL: | |||||
| return 2.0f; | |||||
| case SPREADSHEET_VALUE_TYPE_INT32: | |||||
| return float_width; | |||||
| case SPREADSHEET_VALUE_TYPE_FLOAT: | |||||
| return float_width; | |||||
| case SPREADSHEET_VALUE_TYPE_FLOAT2: | |||||
| return 2.0f * float_width; | |||||
| case SPREADSHEET_VALUE_TYPE_FLOAT3: | |||||
| return 3.0f * float_width; | |||||
| case SPREADSHEET_VALUE_TYPE_COLOR: | |||||
| return 4.0f * float_width; | |||||
| case SPREADSHEET_VALUE_TYPE_INSTANCES: | |||||
| return 8.0f; | |||||
| } | |||||
| return float_width; | |||||
| } | |||||
| static float get_column_width(const ColumnValues &values) | |||||
| { | |||||
| float data_width = get_default_column_width(values); | |||||
| const int fontid = UI_style_get()->widget.uifont_id; | const int fontid = UI_style_get()->widget.uifont_id; | ||||
| BLF_size(fontid, UI_DEFAULT_TEXT_POINTS, U.dpi); | BLF_size(fontid, UI_DEFAULT_TEXT_POINTS, U.dpi); | ||||
| const StringRefNull name = values.name(); | const StringRefNull name = values.name(); | ||||
| const float name_width = BLF_width(fontid, name.data(), name.size()); | const float name_width = BLF_width(fontid, name.data(), name.size()); | ||||
| return std::max<float>(name_width / UI_UNIT_X + 1.0f, 3.0f); | return std::max<float>(name_width / UI_UNIT_X + 1.0f, data_width); | ||||
| } | } | ||||
| static float get_column_width_in_pixels(const ColumnValues &values) | static float get_column_width_in_pixels(const ColumnValues &values) | ||||
| { | { | ||||
| return get_column_width(values) * SPREADSHEET_WIDTH_UNIT; | return get_column_width(values) * SPREADSHEET_WIDTH_UNIT; | ||||
| } | } | ||||
| static int get_index_column_width(const int tot_rows) | static int get_index_column_width(const int tot_rows) | ||||
| Show All 19 Lines | LISTBASE_FOREACH_MUTABLE (SpreadsheetColumn *, column, &columns) { | ||||
| if (!used_ids.add(*column->id)) { | if (!used_ids.add(*column->id)) { | ||||
| /* Remove duplicate columns for now. */ | /* Remove duplicate columns for now. */ | ||||
| BLI_remlink(&columns, column); | BLI_remlink(&columns, column); | ||||
| spreadsheet_column_free(column); | spreadsheet_column_free(column); | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| data_source.foreach_default_column_ids([&](const SpreadsheetColumnID &column_id) { | data_source.foreach_default_column_ids( | ||||
| [&](const SpreadsheetColumnID &column_id, const bool is_extra) { | |||||
| std::unique_ptr<ColumnValues> values = data_source.get_column_values(column_id); | std::unique_ptr<ColumnValues> values = data_source.get_column_values(column_id); | ||||
| if (values) { | if (values) { | ||||
| if (used_ids.add(column_id)) { | if (used_ids.add(column_id)) { | ||||
| SpreadsheetColumnID *new_id = spreadsheet_column_id_copy(&column_id); | SpreadsheetColumnID *new_id = spreadsheet_column_id_copy(&column_id); | ||||
| SpreadsheetColumn *new_column = spreadsheet_column_new(new_id); | SpreadsheetColumn *new_column = spreadsheet_column_new(new_id); | ||||
| if (is_extra) { | |||||
| BLI_addhead(&columns, new_column); | |||||
| } | |||||
| else { | |||||
| BLI_addtail(&columns, new_column); | BLI_addtail(&columns, new_column); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| }); | }); | ||||
| } | } | ||||
| static void spreadsheet_main_region_draw(const bContext *C, ARegion *region) | static void spreadsheet_main_region_draw(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C); | SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C); | ||||
| spreadsheet_update_context_path(C); | spreadsheet_update_context_path(C); | ||||
| std::unique_ptr<DataSource> data_source = get_data_source(C); | std::unique_ptr<DataSource> data_source = get_data_source(C); | ||||
| ▲ Show 20 Lines • Show All 323 Lines • Show Last 20 Lines | |||||