Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_spreadsheet/spreadsheet_layout.cc')
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_layout.cc32
1 files changed, 26 insertions, 6 deletions
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
index e19a343335a..780dd0303cd 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc
@@ -19,6 +19,8 @@
#include "BLF_api.h"
+#include "BLT_translation.h"
+
namespace blender::ed::spreadsheet {
class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
@@ -193,7 +195,7 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
}
else if (data.type().is<ColorGeometry4b>()) {
const ColorGeometry4b value = data.get<ColorGeometry4b>(real_index);
- this->draw_int_vector(params, {value.r, value.g, value.b, value.a});
+ this->draw_byte_color(params, value);
}
else if (data.type().is<InstanceReference>()) {
const InstanceReference value = data.get<InstanceReference>(real_index);
@@ -308,13 +310,16 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
}
}
- void draw_int_vector(const CellDrawParams &params, const Span<int> values) const
+ void draw_byte_color(const CellDrawParams &params, const ColorGeometry4b color) const
{
- BLI_assert(!values.is_empty());
+ const ColorGeometry4f float_color = color.decode();
+ Span<float> values(&float_color.r, 4);
const float segment_width = (float)params.width / values.size();
for (const int i : values.index_range()) {
- const int value = values[i];
- const std::string value_str = std::to_string(value);
+ 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,
@@ -330,9 +335,24 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
0,
0,
nullptr);
- /* Right-align Ints. */
+ /* Right-align Floats. */
UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT);
UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT);
+
+ /* Tooltip showing raw byte values. Encode values in pointer to avoid memory allocation. */
+ UI_but_func_tooltip_set(
+ but,
+ [](bContext * /*C*/, void *argN, const char *UNUSED(tip)) {
+ const uint32_t uint_color = POINTER_AS_UINT(argN);
+ ColorGeometry4b color = *(ColorGeometry4b *)&uint_color;
+ return BLI_sprintfN(TIP_("Byte Color (sRGB encoded):\n%3d %3d %3d %3d"),
+ color.r,
+ color.g,
+ color.b,
+ color.a);
+ },
+ POINTER_FROM_UINT(*(uint32_t *)&color),
+ nullptr);
}
}