View menu — panel visibility toggles for all 5 panels

Each panel (Stage Editor, Scene Hierarchy, Viewport, Property Panel,
Timeline) now has a checkable menu item under View. Closing a panel via
its X button also unchecks the entry. Stage Info and Demo Window follow
below a separator.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 22:39:50 +08:00
parent 7f0fa6a944
commit e5d7967455
5 changed files with 121 additions and 27 deletions
+74 -15
View File
@@ -7,6 +7,7 @@
#include <pxr/usd/sdf/path.h>
#include <pxr/base/tf/token.h>
#include <imgui.h>
#include <imgui_internal.h>
#include <vector>
#include <string>
#include <filesystem>
@@ -35,6 +36,11 @@ static std::string SanitizeUsdNameApp(const std::string& raw) {
Application::Application()
: m_showDemoWindow(false)
, m_showStageInfo(true)
, m_showStageEditor(true)
, m_showSceneHierarchy(true)
, m_showViewport(true)
, m_showPropertyPanel(true)
, m_showTimeline(true)
, m_running(false) {
}
@@ -195,6 +201,10 @@ void Application::Update() {
void Application::RenderUI() {
m_imguiContext->NewFrame();
// Status bar must be rendered before DockSpaceOverViewport so it
// reserves space at the bottom before the dockspace claims the rest.
RenderStatusBar();
ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport());
if (m_showDemoWindow) {
@@ -207,30 +217,73 @@ void Application::RenderUI() {
RenderStageInfo();
}
ImGui::Begin("Stage Editor", nullptr, ImGuiWindowFlags_NoCollapse);
m_stageEditorPanel->Render();
ImGui::End();
if (m_showStageEditor) {
ImGui::Begin("Stage Editor", &m_showStageEditor, ImGuiWindowFlags_NoCollapse);
m_stageEditorPanel->Render();
ImGui::End();
}
m_viewportPanel->Render();
if (m_showViewport) {
m_viewportPanel->Render(&m_showViewport);
}
// Scene Hierarchy is rendered AFTER the viewport so that viewport picks
// (OnPrimPicked / OnPrimsPickedRect) are visible to the hierarchy in the
// same frame — eliminating the one-frame-late scroll/highlight lag.
ImGui::Begin("Scene Hierarchy", nullptr, ImGuiWindowFlags_NoCollapse);
m_sceneHierarchyPanel->Render();
ImGui::End();
if (m_showSceneHierarchy) {
ImGui::Begin("Scene Hierarchy", &m_showSceneHierarchy, ImGuiWindowFlags_NoCollapse);
m_sceneHierarchyPanel->Render();
ImGui::End();
}
ImGui::Begin("Property Panel", nullptr, ImGuiWindowFlags_NoCollapse);
m_propertyPanel->Render();
ImGui::End();
if (m_showPropertyPanel) {
ImGui::Begin("Property Panel", &m_showPropertyPanel, ImGuiWindowFlags_NoCollapse);
m_propertyPanel->Render();
ImGui::End();
}
ImGui::Begin("Timeline", nullptr, ImGuiWindowFlags_NoCollapse);
m_timelinePanel->Render();
ImGui::End();
if (m_showTimeline) {
ImGui::Begin("Timeline", &m_showTimeline, ImGuiWindowFlags_NoCollapse);
m_timelinePanel->Render();
ImGui::End();
}
m_imguiContext->Render();
}
void Application::RenderStatusBar() {
ImGuiViewport* vp = ImGui::GetMainViewport();
float height = ImGui::GetFrameHeight();
ImGuiWindowFlags flags =
ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_MenuBar;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.f, 2.f));
bool open = ImGui::BeginViewportSideBar("##statusbar", vp,
ImGuiDir_Down, height, flags);
ImGui::PopStyleVar();
if (open) {
ImGui::BeginMenuBar();
// FPS
ImGuiIO& io = ImGui::GetIO();
char buf[32];
snprintf(buf, sizeof(buf), "FPS: %.1f", io.Framerate);
// Right-align: measure text, then position cursor.
float textW = ImGui::CalcTextSize(buf).x;
float avail = ImGui::GetContentRegionAvail().x;
if (avail > textW)
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + avail - textW);
ImGui::TextDisabled("%s", buf);
ImGui::EndMenuBar();
}
ImGui::End();
}
void Application::RenderMenuBar() {
if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) {
@@ -320,8 +373,14 @@ void Application::RenderMenuBar() {
}
if (ImGui::BeginMenu("View")) {
ImGui::MenuItem("Stage Info", nullptr, &m_showStageInfo);
ImGui::MenuItem("Show Demo Window", nullptr, &m_showDemoWindow);
ImGui::MenuItem("Stage Editor", nullptr, &m_showStageEditor);
ImGui::MenuItem("Scene Hierarchy", nullptr, &m_showSceneHierarchy);
ImGui::MenuItem("Viewport", nullptr, &m_showViewport);
ImGui::MenuItem("Property Panel", nullptr, &m_showPropertyPanel);
ImGui::MenuItem("Timeline", nullptr, &m_showTimeline);
ImGui::Separator();
ImGui::MenuItem("Stage Info", nullptr, &m_showStageInfo);
ImGui::MenuItem("Demo Window", nullptr, &m_showDemoWindow);
ImGui::EndMenu();
}