diff --git a/src/ui/Application.cpp b/src/ui/Application.cpp index c5b186f..a55deac 100644 --- a/src/ui/Application.cpp +++ b/src/ui/Application.cpp @@ -424,11 +424,25 @@ void Application::LoadPreferences() else if (key == "OcioView") m_prefs.ocioView = val; else if (key == "OcioColorSpace") m_prefs.ocioColorSpace = val; else if (key == "OcioLook") m_prefs.ocioLook = val; + else if (key == "MaterialBrowserWidth") + m_prefs.materialBrowserWidth = [&]{ try { return std::stof(val); } catch(...){ return 220.0f; } }(); + else if (key == "MaterialPreviewWidth") + m_prefs.materialPreviewWidth = [&]{ try { return std::stof(val); } catch(...){ return 320.0f; } }(); } + + if (m_materialEditorPanel) + m_materialEditorPanel->SetColumnWidths(m_prefs.materialBrowserWidth, + m_prefs.materialPreviewWidth); } void Application::SavePreferences() { + // Pull the latest splitter positions; called from Shutdown before the + // panel is reset, and from the preferences dialog while it's alive. + if (m_materialEditorPanel) + m_materialEditorPanel->GetColumnWidths(m_prefs.materialBrowserWidth, + m_prefs.materialPreviewWidth); + std::ofstream f(m_prefsPath); if (!f) return; f << "[Preferences]\n"; @@ -438,6 +452,8 @@ void Application::SavePreferences() f << "OcioView=" << m_prefs.ocioView << "\n"; f << "OcioColorSpace=" << m_prefs.ocioColorSpace << "\n"; f << "OcioLook=" << m_prefs.ocioLook << "\n"; + f << "MaterialBrowserWidth=" << m_prefs.materialBrowserWidth << "\n"; + f << "MaterialPreviewWidth=" << m_prefs.materialPreviewWidth << "\n"; } void Application::ApplyPrefsToAllViewports() diff --git a/src/ui/Application.h b/src/ui/Application.h index 1923ff0..810f457 100644 --- a/src/ui/Application.h +++ b/src/ui/Application.h @@ -28,6 +28,8 @@ struct AppPreferences { std::string ocioView; std::string ocioColorSpace; std::string ocioLook; + float materialBrowserWidth = 220.0f; ///< Material Editor left-column width + float materialPreviewWidth = 320.0f; ///< Material Editor right-column width }; class Application { diff --git a/src/ui/MaterialEditorPanel.cpp b/src/ui/MaterialEditorPanel.cpp index 7d1d25b..daa7666 100644 --- a/src/ui/MaterialEditorPanel.cpp +++ b/src/ui/MaterialEditorPanel.cpp @@ -148,6 +148,11 @@ std::vector FilterShaderNodeTypes( return matches; } +// Clamp range shared by the column splitters and SetColumnWidths (persisted +// preferences may carry hand-edited or stale values). +constexpr float kBrowserMinWidth = 140.0f, kBrowserMaxWidth = 500.0f; +constexpr float kPreviewMinWidth = 220.0f, kPreviewMaxWidth = 640.0f; + // Vertical drag-splitter between the material editor's columns. Adjusts // *width by the mouse drag (negated for a right-hand column, which grows // when dragged left); colours match the viewport's split dividers. @@ -238,6 +243,11 @@ void MaterialEditorPanel::SetStage(pxr::UsdStageRefPtr stage) { m_browserSelection = pxr::SdfPath(); } +void MaterialEditorPanel::SetColumnWidths(float browserWidth, float previewWidth) { + m_browserWidth = std::clamp(browserWidth, kBrowserMinWidth, kBrowserMaxWidth); + m_previewWidth = std::clamp(previewWidth, kPreviewMinWidth, kPreviewMaxWidth); +} + void MaterialEditorPanel::SetColorCorrectionFromPrefs(int ccMode, const std::string& ocioDisplay, const std::string& ocioView, const std::string& ocioColorSpace, @@ -261,14 +271,14 @@ void MaterialEditorPanel::Render() { RenderMaterialBrowser(); ImGui::EndChild(); - VerticalSplitter("##MaterialSplitL", &m_browserWidth, 140.0f, 500.0f, + VerticalSplitter("##MaterialSplitL", &m_browserWidth, kBrowserMinWidth, kBrowserMaxWidth, /*rightSideColumn=*/false); ImGui::BeginChild("MaterialCanvasRegion", ImVec2(-(m_previewWidth + 6.0f), 0.0f), false); RenderNodeGraphCanvas(); ImGui::EndChild(); - VerticalSplitter("##MaterialSplitR", &m_previewWidth, 220.0f, 640.0f, + VerticalSplitter("##MaterialSplitR", &m_previewWidth, kPreviewMinWidth, kPreviewMaxWidth, /*rightSideColumn=*/true); ImGui::BeginChild("MaterialPreviewRegion", ImVec2(0.0f, 0.0f), true); diff --git a/src/ui/MaterialEditorPanel.h b/src/ui/MaterialEditorPanel.h index d0cf63c..97632c1 100644 --- a/src/ui/MaterialEditorPanel.h +++ b/src/ui/MaterialEditorPanel.h @@ -44,6 +44,14 @@ public: /// auto-loads it into the canvas. void SetTargetPrimPath(const std::string& path); + /// Splitter-adjustable column widths, persisted in preferences.ini by + /// Application. Setter clamps to the same range as the splitters. + void GetColumnWidths(float& browserWidth, float& previewWidth) const { + browserWidth = m_browserWidth; + previewWidth = m_previewWidth; + } + void SetColumnWidths(float browserWidth, float previewWidth); + void Render(); private: