avoid resizing of GUI

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
murali88
In need of some credit
In need of some credit
Posts: 5
Joined: Sun May 07, 2017 7:10 am

avoid resizing of GUI

Post by murali88 »

Hi,

I have wxwidget GUI with multirow tabs. Each page has different number GUI controls (like checkbox, textbox etc). i want my frame to have fixed size
whenever i switch between any pages in tab. Currently due to sizers each page is getting its own best size and frame is resizing, and i do not want that. The requirement is that, the frame should have fixed size irrespective of contents of each page. What are best ways to do this?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: avoid resizing of GUI

Post by doublemax »

Unless you have any calls to Fit(), FitInside() or similar, it should not happen that the size of the outer frame changes.

Can you explain the window hierarchy or show some code?
Do you execute any code when a page is changed?
Use the source, Luke!
murali88
In need of some credit
In need of some credit
Posts: 5
Joined: Sun May 07, 2017 7:10 am

Re: avoid resizing of GUI

Post by murali88 »

My hierarchy is like this

wxFrame is top level window:

I have wxPanel as immediate child of frame.
Then First row of tab has many pages (each page is again a panel. panel has many controls).
When i click a tab, opens another row of tab which again has panels.

Frame -> Panel ->Tab->Panel->Tab->Panel something like this

Whenever i swicth the tab this 2 functions are called for each tab and panel.

Code: Select all

void XTab::RecalcSize()
{
  int sel = GetSelection();
  wxSize defaultsize = wxSize(0, 0);
  if (sel != -1)
  {
    XPanel * panel = wxDynamicCast(GetPage(sel), XPanel);
      defaultsize = panel->GetBestSizeCached();
      SetPageSize(wxSize(700,700));    //this is the size i want to have fixed for all pages and the frame
    m_bestSizeCache = CalcSizeFromPage(defaultsize);
  }
  else
  {
    m_bestSizeCache = wxSize(200, 100);
  }
}


void XPanel::RecalcSize()
{
  wxSize best = GetSizer()->CalcMin();
  wxSize diff = GetSize() - GetClientSize();
  best.x += wxMax(0, diff.x);
  best.y += wxMax(0, diff.y);

  if(m_minWidth!=-1)
  {
    if(best.GetWidth() < m_minWidth)
    {
      best.SetWidth(m_minWidth);
    }
  }
  if(m_minHeight!=-1)
  {
    if(best.GetHeight() < m_minHeight)
    {
      best.SetHeight(m_minHeight);
    }
  }

  CacheBestSize(best);
}
and finally i call this code before showing the frame

Code: Select all

wxSize size = wndClient_->GetBestSizeCached();  //final size

frame->SetClientSIze(size);
I understand that i cannot use best size from sizers anymore since i need fixed size. With SetPageSize(700,700), some pages are not displaying contents properly.Does SetPageSize() sets size for all pages or single page? is calling this function multiple times causes the problem? please provide me the solution as i am struggling here.
Last edited by doublemax on Fri May 12, 2017 5:56 pm, edited 1 time in total.
Reason: Added code tags
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: avoid resizing of GUI

Post by doublemax »

Are you using a wxNotebook or are you handling visibility of all the panels yourself? In the letter case, how exactly do you do it?

If you want a fixed size for the whole frame, just set its size once and never touch it again.
Use the source, Luke!
murali88
In need of some credit
In need of some credit
Posts: 5
Joined: Sun May 07, 2017 7:10 am

Re: avoid resizing of GUI

Post by murali88 »

Yes. I am using wxNotebook. So wxNotebook will handle the visibility of panels
Post Reply