wxScrolledWindow size changes after wxDialog::Fit() call

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
rudolfninja
Experienced Solver
Experienced Solver
Posts: 94
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

wxScrolledWindow size changes after wxDialog::Fit() call

Post by rudolfninja » Tue Dec 03, 2019 1:00 pm

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.
Attachments
issue_edit_0.gif

Post Reply