通知 wxSizer 动态布局变化

Notifying wxSizer of dynamic layout changes

我有以下布局层次结构:

wxMDIChildFrame -> wxNotebook -> wxScrolledWindow -> wxBoxSizer -> wxStyledTextCtrl

目标: wxStyledTextCtrl (CScriptWnd) 在用户添加或删除一行或按 Shift+Enter 添加另一个 CScriptWnd 时调整自身大小wxScrolledWindow.

下面的代码是添加一行的时候:

void CScriptWnd::OnNewLineAdded(wxStyledTextEvent& event)
{
    long col, line;
    PositionToXY(GetInsertionPoint(), &col, &line);

    auto ClientSize = GetClientSize();
    int Height = ClientSize.GetHeight();

    Height += TextHeight(line);

    SetClientSize(ClientSize.GetWidth(), Height);
    SetMinSize(wxSize(ClientSize.GetWidth(), Height));


    Refresh();
    
    //m_ParentWindow->FitInside(); //CScriptWnd gets smaller rather than larger
    //m_ParentWindow->Layout(); //CScriptWnd gets smaller rather than larger
    //m_ParentWindow->GetGrandParent()->Layout(); //No effect


    event.Skip();
}

大多数工作正常,例如 CScriptWnd 自行调整大小,新脚本 window 添加到 wxScrolledWindow 等...

问题是只有在使用鼠标调整 wxMDIChildFrame 大小时才会正确更新用户界面。 例如,如果有两个 CScriptWnd 并且顶部的调整自身大小,它与底部的重叠 直到使用鼠标调整 wxMDIChildFrame 的大小。滚动条的可见性也会发生类似情况,因此当 CScriptWnd 客户端大小变大时,滚动条仅在使用鼠标调整顶级 window 大小时才可见。

不确定我错过了什么。

你可能需要

SetMinSize(GetSize());
GetParent()->Layout();