From 48dc788e6da21de9dd57c735d7489cdd99fe8c7f Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Fri, 17 Oct 2025 10:22:51 +0200 Subject: [PATCH] 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 --- .../editors/interface/interface_layout.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index 2bd489bc99e..57404e1899e 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -736,12 +736,15 @@ static void ui_item_array(uiLayout *layout, return; } - w /= dim_size[0]; - // h /= dim_size[1]; /* UNUSED */ + w /= dim_size[1]; + // h /= dim_size[0]; /* UNUSED */ for (int a = 0; a < len; a++) { - col = a % dim_size[0]; - row = a / dim_size[0]; + /* We are going over flat array indices (the way matrices are stored internally [also check + * 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, ptr, @@ -750,7 +753,7 @@ static void ui_item_array(uiLayout *layout, "", ICON_NONE, 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, UI_UNIT_Y); if (slider && but->type == ButType::Num) { @@ -1823,7 +1826,9 @@ static void ui_item_rna_size(uiLayout *layout, h += 2 * UI_UNIT_Y; } 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 { h += len * UI_UNIT_Y;