Page 1 of 1

wxScrolledWindow size changes after wxDialog::Fit() call

Posted: Tue Dec 03, 2019 1:00 pm
by rudolfninja
Greetings,
I have dialog class (derived from wxDialog) with fixed min size. The dialog class has wxCustomPanel* member (derived from wxPanel) also some collapsible panels are present on dialog. wxCustomPanel* member is used as a template type for wxScrolled<>:

Code: Select all

wxCustomPanel* wxRTSharesManagerDialog::CreateContent()
{
    wxScrolled<wxCustomPanel> *contentPanel = new wxScrolled<wxCustomPanel>(m_dialogContent);
    auto contentSizer = new wxBoxSizer(wxVERTICAL);
    SetMinSize(FromDIP(wxSize(-1, minHeight)));
    // more controls are created here
    m_usersPane = new wxRTUsersPane(contentPanel, wxID_ANY, wxEmptyString, m_usedShares, true); // collapsible pain
    m_usersSizer = m_usersPane->CreateContent(contentPanel);
    m_usersSizer->SetSizeHints(m_usersPane);
    
    contentSizer->Add(m_usersSizer, wxSizerFlags(0).Align(wxALIGN_LEFT).Expand());

    contentPanel->SetSizer(contentSizer);
    contentPanel->SetAutoLayout(true);
    contentPanel->SetScrollRate(0, 16);
    contentSizer->Fit(m_dialogContent);
    return contentPanel;
}
On collapsible pane collapse this function is called:

Code: Select all

void wxCustomDialog::UpdateLayout()
{
    m_dialogContent->GetSizer()->SetSizeHints(m_dialogContent);

    Fit();
    Layout();
    Refresh();
}
void wxCustomDialog::Fit()
{
    m_dialogContent->Fit(); // m_dialogContent has wxCustomPanel type. This is the object that is used as wxScrolled base
    m_dialogContent->Layout();

    wxDialog::Fit();
}
The problem is following: when I resize dialog to fit collapsible panel in it and the expand collapsible panel (Fit function is called at this moment) the dialog's size is set to minsize and scroll bar appears.
Here is code for resize:

Code: Select all

void wxRTSharesManagerDialog::OnMouseMove(wxMouseEvent& event)
{
    wxPoint pt = event.GetPosition();
    wxRect windowRect = this->GetRect();
    bool isInResizePos = false;
    if (windowRect.GetHeight() - pt.y < 5)
    {
        SetCursor(wxCURSOR_SIZENS);
        m_isResizePos = true;
    }
    else
    {
        SetCursor(wxCURSOR_DEFAULT);
        m_isResizePos = false;
    }
    if (m_isResizeMode)
    {
        if (event.Dragging() && event.LeftIsDown())
        {
            wxPoint pos = ClientToScreen(pt);
            wxSize sz = GetSize();
            sz.y += pos.y - windowRect.GetBottom();
            if (sz.y > minHeight)
            {
                SetSize(sz);              
            }
        }
    }
}
I added gif file on which the problem is shown.