LnF_V2 drawFileBrowserRow itemIndex is relative to parent item


#1

Hello, I'm trying to get the open state for folders while drawing a TreeViewComponent but itemIndex is reseted for each subfolder:

bool isOpen = (dynamic_cast <TreeView *> (&dcc))->getItemOnRow(itemIndex)->isOpen();

itemIndex example values:

directory 1 - itemIndex = 0
directory 2 - itemIndex = 1
    dir2subdir1 - itemIndex = 0 ! should be 2 in order to use it with getItemOnRow()

directory 3 - itemIndex = 2 ! should be 3 (tells me its not open since dir2subdir1 isn't open)
    dir3subdir1 - itemIndex = 0 ! should be 4

...

Did I miss something? Should it be done differently?

Thank you! =)


#2

Yes, that index value has a different meaning - it's the index of the item in the DirectoryContentsList, not the row of the tree (where the index will obviously depend on which folders are open).

To get the row of the tree would be pretty difficult in that method, because it's called by lists as well as treeviews, so doing anything treeview-specific in it would be a bit dodgy. Not sure what to suggest, it depends on what you're actually trying to achieve.


#3

Hi Jules, thanks for your reply.

My goal is just to paint a opened folder icon when it is actually open in the tree view just like I already did in a nasty way here.

So the not-so-nasty way of doing it would be subclassing FileTreeComponent and FileListTreeItem in order to overload LnF drawFileBrowserRow method with some bool isOpen parameter.

I'll leave it the nasty way for a while since this is only a small detail on a gui.

diff --git a/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp b/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp
index 45963e8..29f010e 100644
--- a/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp
+++ b/modules/juce_gui_basics/filebrowser/juce_FileTreeComponent.cpp
@@ -183,7 +183,7 @@ public:
         owner.getLookAndFeel().drawFileBrowserRow (g, width, height,
                                                    file.getFileName(),
                                                    &icon, fileSize, modTime,
-                                                   isDirectory, isSelected(),
+                                                   isDirectory, isOpen(),
                                                    indexInContentsList, owner);
     }

#4

So the not-so-nasty way of doing it would be subclassing FileTreeComponent and FileListTreeItem in order to overload LnF drawFileBrowserRow method with some bool isOpen parameter.

Well, I could, but that method isn't only used for treeviews. it's also used for plain lists, so an isOpen parameter would be superfluous in almost all cases.