Expanding a window in same time of the contained wxTreeCtrl

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.
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by coderrc »

Maeglix wrote:
Set***Size(biggerSize);
Refresh
This seems to works. It makes the window grows when i expand an item. But how do i make the window contract when i collapse item now ?
Same way...
handle EVT_TREE_ITEM_COLAPS[ed|ing]
Set***Size(smallerSize);

choose a smallerSize based on your desires/design requirements.
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by Maeglix »

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.
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by coderrc »

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:

Seems like a lot of work though.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by doublemax »

The calculation of the best size definitely works in the code i posted. You should be able to build your code from that base.
Use the source, Luke!
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by Maeglix »

doubleMax, i am currently trying again your code. Did you test it on windows or on a Linux platform ?
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by Maeglix »

I extracted from my code the part with the tree to allow you to compile and test. It is stills not working for me. I am on Red hat 7.2.

PS: As my SlcAttrPopup.cc was not accepted, i renamed it into a .txt.
Attachments
wxTest.cpp
(1.65 KiB) Downloaded 54 times
SlcAttrPopup.txt
(2.12 KiB) Downloaded 56 times
SlcAttrPopup.h
(691 Bytes) Downloaded 54 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by ONEEYEMAN »

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.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by doublemax »

Maeglix wrote:doubleMax, i am currently trying again your code. Did you test it on windows or on a Linux platform ?
Sorry, Windows only.
Use the source, Luke!
Maeglix
Experienced Solver
Experienced Solver
Posts: 74
Joined: Thu Nov 17, 2016 8:07 am

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by Maeglix »

Ok thank you ! My bad for not telling it sooner.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Expanding a window in same time of the contained wxTreeCtrl

Post by doublemax »

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).
Use the source, Luke!
Post Reply