How to resize all netsted sizers

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.
Post Reply
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

How to resize all netsted sizers

Post by briceandre »

Hello,

I have an application which constructs its GUI dynamically. It is thus composed of differents nested wxWindow derived classes, and nested derived wxSizer classes to organise children windows.

On some user actions, I can add of suppress some wxWindows (for example, a wxTextCtrl). I would want, directly from the parent wxPanel to trigger a full resize of everything, so that the full display is correct. Because today, for example, when I add an element, the parent may not resize properly, not letting enough space for the display of the added element.

But I do not find exaclly which command to emit to do this. I tried the followings, but none of them worked properly :

Code: Select all

            top_window->Layout();
            top_window->Refresh();
            top_window->Fit();
What works perfectly is to resize manually the window : if I do it, all the display is properly recomputed and all GUI elements have proper size and place (but it's not convenient to ask the user to resize its window when not properly displayed...).

Many thanks in advance,
Brice
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to resize all netsted sizers

Post by doublemax »

Code: Select all

top_window->Layout();
Should work.

If not, try storing the pointer to the topmost sizer and call Layout() on that.

Last resort: top_window->SendSizeEvent()
Use the source, Luke!
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: How to resize all netsted sizers

Post by briceandre »

Hello,

Thanks for answer, but unfortunately, none of them worked.

I finished by solving my issue by writing recursive functions which perform Layout on all sizers included in my top level window (see code below). But honestly, I am a bit puzzled : I tought calling Layout on top sizer would be enough.

I fear this hides another bug in my application.

Nobody has anly clue on what would cause a difference between

Code: Select all

top_window->Layout(); 
and

Code: Select all

r_w(top_window);
Thanks in advance,
Brice

PS : code of r_w function :

Code: Select all

static void r_w(wxWindow* ptr);
static void r_s (wxSizer* ptr)
{
   wxSizerItemList& sizers = ptr->GetChildren();
   wxSizerItemList::compatibility_iterator node = sizers.GetFirst();
   while (node)
   {
      wxSizerItem* item = node->GetData();
      wxSizer* s = item->GetSizer();
      if (s)
      {
         r_s(s);
      }
      node = node->GetNext();
   }
   ptr->Layout();
}
static void r_w(wxWindow* ptr)
{
   /* Resize all children */
   wxWindowList& windows = ptr->GetChildren();
   wxWindowList::compatibility_iterator node = windows.GetFirst();
   while (node)
   {
      wxWindow *win = node->GetData();
      r_w(win);
      node = node->GetNext();
  }

   /* Resize the sizer */
   wxSizer* s = ptr->GetSizer();
   if (s)
   {
      r_s(s);
   }
}
Post Reply