Fix #145488: UI: Flipped rows/columns in custom matrix property

Since matrices are usually indexed **row first**, displaying matrices in
the UI seems flipped.
They are stored as flat arrays.
When `matrix[1][0]` is accessed via python, the logic from
`pyrna_py_from_array_index` will actually look up index 2 in the flat
array (rightfully so).

But UI code was flipped in that regard.
The second value in the flat array **should** show at row 1 column 0,
but it currently doesnt.

Now (hopefully) handled properly (not only in `ui_item_array` but also
made code in `ui_item_rna_size` detect proper row count for a `height`)

Pull Request: https://projects.blender.org/blender/blender/pulls/148197
This commit is contained in:
Philipp Oeser
2025-10-17 10:22:51 +02:00
committed by Philipp Oeser
parent fca5bcbe46
commit 48dc788e6d

View File

@@ -736,12 +736,15 @@ static void ui_item_array(uiLayout *layout,
return; return;
} }
w /= dim_size[0]; w /= dim_size[1];
// h /= dim_size[1]; /* UNUSED */ // h /= dim_size[0]; /* UNUSED */
for (int a = 0; a < len; a++) { for (int a = 0; a < len; a++) {
col = a % dim_size[0]; /* We are going over flat array indices (the way matrices are stored internally [also check
row = a / dim_size[0]; * logic in #pyrna_py_from_array_index()]) -- and they are not ordered "row first" -- , so
* map these to rows/colums. */
col = a % dim_size[1];
row = a / dim_size[1];
uiBut *but = uiDefAutoButR(block, uiBut *but = uiDefAutoButR(block,
ptr, ptr,
@@ -750,7 +753,7 @@ static void ui_item_array(uiLayout *layout,
"", "",
ICON_NONE, ICON_NONE,
x + w * col, x + w * col,
y + (dim_size[1] * UI_UNIT_Y) - (row * UI_UNIT_Y), y + (dim_size[0] * UI_UNIT_Y) - (row * UI_UNIT_Y),
w, w,
UI_UNIT_Y); UI_UNIT_Y);
if (slider && but->type == ButType::Num) { if (slider && but->type == ButType::Num) {
@@ -1823,7 +1826,9 @@ static void ui_item_rna_size(uiLayout *layout,
h += 2 * UI_UNIT_Y; h += 2 * UI_UNIT_Y;
} }
else if (subtype == PROP_MATRIX) { else if (subtype == PROP_MATRIX) {
h += ceilf(sqrtf(len)) * UI_UNIT_Y; int dim_size[/*RNA_MAX_ARRAY_DIMENSION*/ 3];
RNA_property_array_dimension(ptr, prop, dim_size);
h += dim_size[0] * UI_UNIT_Y;
} }
else { else {
h += len * UI_UNIT_Y; h += len * UI_UNIT_Y;