Using TableMatrixAttribute, how can I display the table flipped vertically?

Issue #753 new
Michael Ryan created an issue

The standard table orientation places [0,0] at the UPPER-LEFT.

I have a dataset that, when drawn, should be oriented with columns drawn left-to-right and rows drawn bottom-to-top. Element [0,0] should be that the LOWER-LEFT of the table. This orientation is like what a bitmap would use with the first row being at the bottom and the last row at the top. This orientation also coincides with Unity’s standard 2D Cartesian coordinate system with +X flowing to the right and +Y flowing up.

I am requesting a flag that allows the table to be drawn with the first row at the bottom (i.e., FlipVertical = true), although a solution that would allow other orientations may also be useful for other cases. For example, adding FlipHorizontal = true to reverse the columns, or perhaps an Origin or Orientation parameter that takes an enum.

Origin Columns Rows
UpperLeft Left-to-Right Top-to-Bottom Current behavior
UpperRight Right-to-Left Top-to-Bottom
LowerLeft Left-to-Right Bottom-to-Top My need
LowerRight Right-to-Left Bottom-to-Top

I would assume that a table could be both transposed and still have one or both axes flipped, since they really do separate things.

Note: This very request was made a while ago, and it was marked “resolved”, but it was never actually addressed. I assume there was a misunderstanding regarding the original request and the reporter never followed up.

https://bitbucket.org/sirenix/odin-inspector/issues/235/how-do-i-invert-the-display-of-the-second

Comments (4)

  1. Nick Karamousadakis

    I agree that transpose seems to have a very weird and useless effect. I was looking for a way to do this. Have you come up with a solution?

  2. Antonio Rafael Antunes Miranda

    This is a highly requested feature so I’m positive that this will be implemented some day, however it might take a while. Odin will transition to Unity’s new UIElements system in the future which will mean that there is going to be a lot of drawers which will have to be rewritten and changed. Making bigger changes to the current drawers before the switch would mean that the work will basically be thrown away as soon as the UIElements transition happens.

    In the meantime, there is a solution to do this yourself, although It’s by no means perfect. You can use the TableMatrix’s DrawElementMethod parameter to draw the cells yourself. This will allow you to draw them in reversed order by calculating the reversed y index of the cell before you draw it. Drawing the cells yourself, however, will mean that you have to draw the field manually using Unity’s/Odin’s GUI calls, which can be quite tedious depending on the drawers complexity, but for simple drawers it should be relatively easy and fast to implement. Additionally all the index labels will then be in the wrong order since you cannot change them, which means that you will probably want to disable them. As I said this is by no means perfect but it may be viable for some use cases until this gets implemented natively. I hope this sheds some light on the current situation.

    Here is an example of the workaround I described:

    [TableMatrix(DrawElementMethod = nameof(DrawYReversed))]
    public bool[,] Matrix = new bool[5, 5];
    
    private bool DrawYReversed(Rect rect, bool value, int x, int y)
    {
        var reversedY = Matrix.GetLength(1) - y - 1;
    
        // If y and reservedY are the same we have to change the value directly
        if (y == reversedY)
        {
            value = EditorGUI.Toggle(rect, value);
        }
        else
        {
            Matrix[x, reversedY] = EditorGUI.Toggle(rect, Matrix[x, reversedY]);
        }
    
        return value;
    }
    

  3. Log in to comment