If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Yeah but that's exactly what i don't know how to do. How do i get the size needed by the tree after a collapse since GetBestSize() always return the same thing even after collapse / expand items.
if you're super into it, I am sure you can figure out the client area of a single node, (how many pixels tall and wide a node is)
then traverse the tree from t he root and count every node thats displayed, and store the width of the widest one as you go (including horizontal offset).
then once the traversal is complete, multiply the node count by the node height and add a few pixels of "margin". That value will be your height.
your new width will be the widest node + some "margin"
dont be tempted to just count the root nodes' children, since any node could be expanded and have more children that are expanded...
youll need a full traversal.
:shrug:
Hi,
You can try the simpler solution.
When you program opens and the Layout() is called you have an initial layout.
Call GetSize() on the tree and cache it somewhere (probably in the main frame).
Then the user will try to expand a node - you do your own thing.
When the user tries to collapse the node - in the appropriate event handler you call SetSize with the appropriate size as a parameter.
Thank you.
P.S.: But I would find the behavior you want very confusing and non-intuitive. Why do you want expand/shrink the nain window when the tree control expands/shrinks. The user of you program will have their had rolling if they have to do a lot of this.
Did you try the unmodified code i posted? Did that work?
Or maybe we were talking about different things. The demo code i posted only adjusts the size of the wxTreeCtrl, not the outer frame (but that could be easily added).