Supporting setting panel layout
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
#include <imgui.h>
|
||||
|
||||
void AssetBrowserPanel::onUpdate(const sophia::FrameInfo&) {
|
||||
ImGui::Begin("Asset Browser");
|
||||
|
||||
ImGui::BeginChild("Folders", ImVec2(150, 0), true);
|
||||
for (int i = 0; i < static_cast<int>(folders.size()); i++) {
|
||||
if (ImGui::Selectable(folders[static_cast<size_t>(i)].name.c_str(),
|
||||
@@ -22,6 +20,4 @@ void AssetBrowserPanel::onUpdate(const sophia::FrameInfo&) {
|
||||
ImGui::Selectable(file.c_str());
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
class AssetBrowserPanel : public sophia::Panel {
|
||||
public:
|
||||
AssetBrowserPanel() : Panel{"Asset Browser"} {}
|
||||
AssetBrowserPanel() : Panel{{.name = "Asset Browser"}} {}
|
||||
|
||||
void onUpdate(const sophia::FrameInfo& frameInfo) override;
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include <cstdio>
|
||||
|
||||
void InspectorPanel::onUpdate(const sophia::FrameInfo&) {
|
||||
ImGui::Begin("Inspector");
|
||||
|
||||
char nameBuf[128];
|
||||
std::snprintf(nameBuf, sizeof(nameBuf), "%s", name.c_str());
|
||||
if (ImGui::InputText("Name", nameBuf, sizeof(nameBuf))) {
|
||||
@@ -31,6 +29,4 @@ void InspectorPanel::onUpdate(const sophia::FrameInfo&) {
|
||||
if (ImGui::CollapsingHeader("Script", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::Text("%s", scriptName.c_str());
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
class InspectorPanel : public sophia::Panel {
|
||||
public:
|
||||
InspectorPanel() : Panel{"Inspector"} {}
|
||||
InspectorPanel() : Panel{{.name = "Inspector"}} {}
|
||||
|
||||
void onUpdate(const sophia::FrameInfo& frameInfo) override;
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ void SceneHierarchyPanel::drawNode(const Node& node) {
|
||||
}
|
||||
|
||||
void SceneHierarchyPanel::onUpdate(const sophia::FrameInfo&) {
|
||||
ImGui::Begin("Scene Hierarchy");
|
||||
for (const Node& node : nodes) {
|
||||
drawNode(node);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
class SceneHierarchyPanel : public sophia::Panel {
|
||||
public:
|
||||
SceneHierarchyPanel() : Panel{"Scene Hierarchy"} {}
|
||||
SceneHierarchyPanel() : Panel{{.name = "Scene Hierarchy"}} {}
|
||||
|
||||
void onUpdate(const sophia::FrameInfo& frameInfo) override;
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "viewport_panel.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
void ViewportPanel::onUpdate(const sophia::FrameInfo&) {
|
||||
const struct {
|
||||
const char* label;
|
||||
GizmoMode mode;
|
||||
} modes[] = {{"Move", GizmoMode::Move},
|
||||
{"Rotate", GizmoMode::Rotate},
|
||||
{"Scale", GizmoMode::Scale}};
|
||||
|
||||
for (const auto& entry : modes) {
|
||||
if (ImGui::RadioButton(entry.label, gizmoMode == entry.mode)) {
|
||||
gizmoMode = entry.mode;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::Checkbox("Grid", &showGrid);
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
const ImVec2 origin = ImGui::GetCursorScreenPos();
|
||||
const ImVec2 size = ImGui::GetContentRegionAvail();
|
||||
const ImVec2 end(origin.x + size.x, origin.y + size.y);
|
||||
|
||||
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
||||
drawList->AddRectFilled(origin, end, IM_COL32(24, 26, 32, 255));
|
||||
|
||||
if (showGrid) {
|
||||
constexpr float GRID_STEP = 40.0f;
|
||||
const ImU32 gridColor = IM_COL32(255, 255, 255, 18);
|
||||
for (float x = GRID_STEP; x < size.x; x += GRID_STEP) {
|
||||
drawList->AddLine(ImVec2(origin.x + x, origin.y),
|
||||
ImVec2(origin.x + x, end.y), gridColor);
|
||||
}
|
||||
for (float y = GRID_STEP; y < size.y; y += GRID_STEP) {
|
||||
drawList->AddLine(ImVec2(origin.x, origin.y + y),
|
||||
ImVec2(end.x, origin.y + y), gridColor);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SetCursorScreenPos(ImVec2(origin.x + 8.0f, origin.y + 8.0f));
|
||||
ImGui::TextDisabled("%.0f x %.0f", size.x, size.y);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <sophia/frame_info.hpp>
|
||||
#include <sophia/ui/panel.hpp>
|
||||
|
||||
class ViewportPanel : public sophia::Panel {
|
||||
public:
|
||||
ViewportPanel() : Panel{{.name = "Viewport"}} {}
|
||||
|
||||
void onUpdate(const sophia::FrameInfo& frameInfo) override;
|
||||
|
||||
private:
|
||||
enum class GizmoMode { Move, Rotate, Scale };
|
||||
|
||||
GizmoMode gizmoMode = GizmoMode::Move;
|
||||
bool showGrid = true;
|
||||
};
|
||||
Reference in New Issue
Block a user