Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
| Show First 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | else if (cell_value.value_bool.has_value()) { | ||||
| nullptr, | nullptr, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT); | UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT); | ||||
| } | } | ||||
| else if (cell_value.value_float2.has_value()) { | |||||
| const float2 value = *cell_value.value_float2; | |||||
| this->draw_float_vector(params, Span(&value.x, 2)); | |||||
| } | |||||
| else if (cell_value.value_float3.has_value()) { | |||||
| const float3 value = *cell_value.value_float3; | |||||
| this->draw_float_vector(params, Span(&value.x, 3)); | |||||
| } | |||||
| else if (cell_value.value_color.has_value()) { | |||||
| const Color4f value = *cell_value.value_color; | |||||
| this->draw_float_vector(params, Span(&value.r, 4)); | |||||
| } | |||||
| else if (cell_value.value_object.has_value()) { | else if (cell_value.value_object.has_value()) { | ||||
| const ObjectCellValue value = *cell_value.value_object; | const ObjectCellValue value = *cell_value.value_object; | ||||
| uiDefIconTextBut(params.block, | uiDefIconTextBut(params.block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| 0, | 0, | ||||
| ICON_OBJECT_DATA, | ICON_OBJECT_DATA, | ||||
| reinterpret_cast<const ID *const>(value.object)->name + 2, | reinterpret_cast<const ID *const>(value.object)->name + 2, | ||||
| params.xmin, | params.xmin, | ||||
| Show All 22 Lines | else if (cell_value.value_collection.has_value()) { | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| nullptr); | nullptr); | ||||
| } | } | ||||
| } | } | ||||
| void draw_float_vector(const CellDrawParams ¶ms, const Span<float> values) const | |||||
| { | |||||
| BLI_assert(!values.is_empty()); | |||||
| const float segment_width = (float)params.width / values.size(); | |||||
| for (const int i : values.index_range()) { | |||||
| std::stringstream ss; | |||||
| const float value = values[i]; | |||||
| ss << std::fixed << std::setprecision(3) << value; | |||||
| const std::string value_str = ss.str(); | |||||
| uiBut *but = uiDefIconTextBut(params.block, | |||||
| UI_BTYPE_LABEL, | |||||
| 0, | |||||
| ICON_NONE, | |||||
| value_str.c_str(), | |||||
| params.xmin + i * segment_width, | |||||
| params.ymin, | |||||
| segment_width, | |||||
| params.height, | |||||
| nullptr, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| 0, | |||||
| nullptr); | |||||
| /* Right-align Floats. */ | |||||
| UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); | |||||
| UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); | |||||
| } | |||||
| } | |||||
| int column_width(int column_index) const final | int column_width(int column_index) const final | ||||
| { | { | ||||
| return spreadsheet_layout_.columns[column_index].width; | return spreadsheet_layout_.columns[column_index].width; | ||||
| } | } | ||||
| }; | }; | ||||
| std::unique_ptr<SpreadsheetDrawer> spreadsheet_drawer_from_layout( | std::unique_ptr<SpreadsheetDrawer> spreadsheet_drawer_from_layout( | ||||
| const SpreadsheetLayout &spreadsheet_layout) | const SpreadsheetLayout &spreadsheet_layout) | ||||
| { | { | ||||
| return std::make_unique<SpreadsheetLayoutDrawer>(spreadsheet_layout); | return std::make_unique<SpreadsheetLayoutDrawer>(spreadsheet_layout); | ||||
| } | } | ||||
| } // namespace blender::ed::spreadsheet | } // namespace blender::ed::spreadsheet | ||||