Skip to content

Commit

Permalink
#6131: Refactor AuiLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 15, 2022
1 parent 2856b64 commit 674d415
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
34 changes: 25 additions & 9 deletions radiant/ui/mainframe/AuiLayout.cpp
Expand Up @@ -37,15 +37,15 @@ AuiLayout::AuiLayout()
{
}

void AuiLayout::addPane(wxWindow* window, const wxAuiPaneInfo& info)
void AuiLayout::addPane(const std::string& name, wxWindow* window, const wxAuiPaneInfo& info)
{
// Give the pane a deterministic name so we can restore perspective
wxAuiPaneInfo nameInfo = info;
nameInfo.Name(std::to_string(_panes.size()));

// Add and store the pane
_auiMgr.AddPane(window, nameInfo);
_panes.push_back(window);
_panes.push_back({ name, window });
}

std::string AuiLayout::getName()
Expand Down Expand Up @@ -100,23 +100,34 @@ void AuiLayout::activate()
// the 2D view on the right
wxSize size = topLevelParent->GetSize();
size.Scale(0.5, 1.0);
addPane(cameraControl->createWidget(managedArea),
addPane(cameraControl->getControlName(), cameraControl->createWidget(managedArea),
DEFAULT_PANE_INFO(_("Camera"), size).Left().Position(0));
addPane(notebookPanel,
addPane("PropertiesPanel", notebookPanel,
DEFAULT_PANE_INFO(_("Properties"), size).Left().Position(1));
addPane(orthoViewControl->createWidget(managedArea),
addPane(orthoViewControl->getControlName(), orthoViewControl->createWidget(managedArea),
DEFAULT_PANE_INFO(_("2D View"), size).CenterPane());
_auiMgr.Update();

// Nasty hack to get the panes sized properly. Since BestSize() is
// completely ignored (at least on Linux), we have to add the panes with a
// large *minimum* size and then reset this size after the initial addition.
for (wxWindow* w: _panes)
for (const auto& info : _panes)
{
_auiMgr.GetPane(w).MinSize(MIN_SIZE);
_auiMgr.GetPane(info.control).MinSize(MIN_SIZE);
}
_auiMgr.Update();

#if 0
auto controlNames = registry::getValue<std::string>(RKEY_ROOT + "/floatingControls");
std::vector<std::string> floatingControlNames;
string::split(floatingControlNames, controlNames, ";");

for (const auto& controlName : floatingControlNames)
{
createFloatingControl(controlName);
}
#endif

// If we have a stored perspective, load it
std::string storedPersp = GlobalRegistry().get(RKEY_ROOT);
if (!storedPersp.empty())
Expand All @@ -135,6 +146,10 @@ void AuiLayout::activate()

void AuiLayout::deactivate()
{
#if 0
registry::setValue(RKEY_ROOT + "/floatingControls", string::join(_floatingControlNames, ";"));
#endif

// Save all floating XYWnd states
GlobalXYWnd().saveState();

Expand Down Expand Up @@ -175,12 +190,13 @@ void AuiLayout::createFloatingControl(const std::string& controlName)

if (!control)
{
throw std::logic_error("Cannot find named control: " + controlName);
rError() << "Cannot create floating control: " << controlName << std::endl;
return;
}

auto managedWindow = _auiMgr.GetManagedWindow();

addPane(control->createWidget(managedWindow),
addPane(control->getControlName(), control->createWidget(managedWindow),
DEFAULT_PANE_INFO(controlName, wxSize(128, 128)).Float());
_auiMgr.Update();
}
Expand Down
10 changes: 8 additions & 2 deletions radiant/ui/mainframe/AuiLayout.h
Expand Up @@ -23,14 +23,20 @@ class AuiLayout: public IMainFrameLayout
// Main AUI manager
wxAuiManager _auiMgr;

struct PaneInfo
{
std::string controlName;
wxWindow* control;
};

// List of panes managed by the AUI manager
std::list<wxWindow*> _panes;
std::list<PaneInfo> _panes;

// Main constructor
AuiLayout();

// Add a pane to the wxAuiManager and store it in the list
void addPane(wxWindow* window, const wxAuiPaneInfo& info);
void addPane(const std::string& name, wxWindow* window, const wxAuiPaneInfo& info);

public:
// IMainFrameLayout implementation
Expand Down

0 comments on commit 674d415

Please sign in to comment.