Skip to content

Commit

Permalink
Adde details pannel
Browse files Browse the repository at this point in the history
  • Loading branch information
muit committed Jun 30, 2022
1 parent 9a8ed83 commit 9a36fa9
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 46 deletions.
11 changes: 8 additions & 3 deletions Libs/Editor/Include/Components/CTypeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ namespace rift
{
STRUCT(CTypeEditor, p::Struct, p::Struct_NotSerialized)

static const Name rightNode;
static const Name rightTopNode;
static const Name rightBottomNode;
static const Name centralNode;

ImGuiID dockspaceID = 0;
DockSpaceLayout layout;

bool pendingFocus = false;
bool showGraph = true;
bool showElements = true;
bool showDetails = true;

AST::Id selectedPropertyId = AST::NoId;
AST::Id pendingDeletePropertyId = AST::NoId;

Nodes::EditorContext nodesEditor;
ImGuiTextFilter propertiesFilter;
ImGuiTextFilter elementsFilter;
};

inline const Name CTypeEditor::rightNode{"rightNode"};
inline const Name CTypeEditor::rightTopNode{"rightTopNode"};
inline const Name CTypeEditor::rightBottomNode{"rightBottomNode"};
inline const Name CTypeEditor::centralNode{"centralNode"};
} // namespace rift
24 changes: 24 additions & 0 deletions Libs/Editor/Include/Utils/DetailsPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2015-2022 Piperift - All rights reserved

#pragma once

#include <AST/Components/CDeclClass.h>
#include <AST/Components/CDeclFunction.h>
#include <AST/Components/CDeclFunctionLibrary.h>
#include <AST/Components/CDeclNative.h>
#include <AST/Components/CDeclStruct.h>
#include <AST/Components/CDeclVariable.h>
#include <AST/Components/CExprType.h>
#include <AST/Components/CIdentifier.h>
#include <AST/Components/CParent.h>
#include <AST/Components/CType.h>
#include <AST/Tree.h>
#include <AST/Utils/TransactionUtils.h>
#include <Pipe/Core/StringView.h>
#include <Pipe/ECS/Filtering.h>


namespace rift
{
void DrawDetailsPanel(AST::Tree& ast, AST::Id typeId);
} // namespace rift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,5 @@ namespace rift
void DrawVariable(TVariableAccessRef access, CTypeEditor& editor, AST::Id variableId);
void DrawFunction(AST::Tree& ast, CTypeEditor& editor, AST::Id functionId);

void DrawVariables(TVariableAccessRef access, TransactionAccess transAccess,
CTypeEditor& editor, AST::Id typeId);
void DrawFunctions(AST::Tree& ast, CTypeEditor& editor, AST::Id typeId);

void DrawProperties(AST::Tree& ast, AST::Id typeId);
void DrawElementsPanel(AST::Tree& ast, AST::Id typeId);
} // namespace rift
2 changes: 1 addition & 1 deletion Libs/Editor/Include/Utils/ProjectManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2015-2022 Piperift - All rights reserved

#include "Utils/Properties.h"
#include "Utils/ElementsPanel.h"

#include <UI/UI.h>

Expand Down
66 changes: 41 additions & 25 deletions Libs/Editor/Src/Systems/EditorSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "Components/CTypeEditor.h"
#include "DockSpaceLayout.h"
#include "Editor.h"
#include "imgui.h"
#include "imgui_internal.h"
#include "Statics/SEditor.h"
#include "Utils/DetailsPanel.h"
#include "Utils/ElementsPanel.h"
#include "Utils/FunctionGraph.h"
#include "Utils/ModuleUtils.h"
#include "Utils/ProjectManager.h"
#include "Utils/Properties.h"
#include "Utils/TypeUtils.h"

#include <AST/Components/CFileRef.h>
Expand Down Expand Up @@ -62,18 +64,21 @@ namespace rift::EditorSystem
{
auto& typeEditor = ast.Get<CTypeEditor>(typeId);
typeEditor.layout.OnBuild([](auto& builder) {
// =================================== //
// | //
// | //
// Central | Right //
// (Graph) |(Details)//
// | //
// | //
// =================================== //
builder.Split(builder.GetRootNode(), ImGuiDir_Right, 0.2f, CTypeEditor::rightNode,
CTypeEditor::centralNode);

builder.GetNodeLocalFlags(CTypeEditor::rightNode) |= ImGuiDockNodeFlags_AutoHideTabBar;
// ==================================== //
// | //
// | Elements //
// Graph | //
// |----------//
// | Details //
// | //
// ==================================== //
Name rightNode{"rightNode"};
builder.Split(
builder.GetRootNode(), ImGuiDir_Right, 0.25f, rightNode, CTypeEditor::centralNode);

builder.Split(rightNode, ImGuiDir_Up, 0.4f, CTypeEditor::rightTopNode,
CTypeEditor::rightBottomNode);

builder.GetNodeLocalFlags(CTypeEditor::centralNode) |=
ImGuiDockNodeFlags_CentralNode | i32(ImGuiDockNodeFlags_AutoHideTabBar);
});
Expand Down Expand Up @@ -454,6 +459,7 @@ namespace rift::EditorSystem

void DrawTypeMenuBar(AST::Tree& ast, AST::Id typeId)
{
auto& typeEditor = ast.Get<CTypeEditor>(typeId);
if (UI::BeginMenuBar())
{
if (UI::MenuItem(ICON_FA_SAVE, "CTRL+S"))
Expand All @@ -470,8 +476,12 @@ namespace rift::EditorSystem
}
if (UI::BeginMenu("View"))
{
if (Types::CanContainFunctions(ast, typeId) && UI::MenuItem("Graph")) {}
if (UI::MenuItem("Properties")) {}
if (Types::CanContainFunctions(ast, typeId))
{
UI::MenuItem("Graph", nullptr, &typeEditor.showGraph);
}
UI::MenuItem("Elements", nullptr, &typeEditor.showElements);
UI::MenuItem("Details", nullptr, &typeEditor.showDetails);
UI::EndMenu();
}
UI::EndMenuBar();
Expand All @@ -482,13 +492,13 @@ namespace rift::EditorSystem
{
ZoneScoped;

TAccess<TWrite<CTypeEditor>, CType, CFileRef> typeEditors{ast};
for (AST::Id typeId : ecs::ListAll<CType, CTypeEditor, CFileRef>(typeEditors))
TAccess<TWrite<CTypeEditor>, CType, CFileRef> access{ast};
for (AST::Id typeId : ecs::ListAll<CType, CTypeEditor, CFileRef>(access))
{
ZoneScopedN("Draw Type");

auto& typeEditor = typeEditors.Get<CTypeEditor>(typeId);
const auto& file = typeEditors.Get<const CFileRef>(typeId);
auto& typeEditor = access.Get<CTypeEditor>(typeId);
const auto& file = access.Get<const CFileRef>(typeId);

bool isOpen = true;
const String path = p::ToString(file.path);
Expand Down Expand Up @@ -518,15 +528,21 @@ namespace rift::EditorSystem
if (Types::CanContainFunctions(ast, typeId))
{
Graph::DrawTypeGraph(ast, typeId, typeEditor);
}

Name propertiesNode = CTypeEditor::rightNode;
if (!Types::CanContainFunctions(ast, typeId))
typeEditor.layout.BindNextWindowToNode(
CTypeEditor::rightBottomNode, ImGuiCond_Appearing);
DrawDetailsPanel(ast, typeId);

typeEditor.layout.BindNextWindowToNode(
CTypeEditor::rightTopNode, ImGuiCond_Appearing);
DrawElementsPanel(ast, typeId);
}
else
{
propertiesNode = DockSpaceLayout::rootNodeId;
typeEditor.layout.BindNextWindowToNode(
DockSpaceLayout::rootNodeId, ImGuiCond_Appearing);
DrawElementsPanel(ast, typeId);
}
typeEditor.layout.BindNextWindowToNode(propertiesNode, ImGuiCond_Appearing);
DrawProperties(ast, typeId);
}
else
{
Expand Down
40 changes: 40 additions & 0 deletions Libs/Editor/Src/Utils/DetailsPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2015-2022 Piperift - All rights reserved

#include "AST/Id.h"
#include "Components/CTypeEditor.h"
#include "DockSpaceLayout.h"
#include "imgui.h"
#include "UI/Style.h"
#include "UI/Widgets.h"
#include "Utils/EditorStyle.h"
#include "Utils/ElementsPanel.h"
#include "Utils/FunctionGraphContextMenu.h"
#include "Utils/Nodes.h"
#include "Utils/Widgets.h"

#include <AST/Utils/Expressions.h>
#include <AST/Utils/Hierarchy.h>
#include <AST/Utils/TypeUtils.h>
#include <GLFW/glfw3.h>
#include <IconsFontAwesome5.h>
#include <Pipe/Core/EnumFlags.h>
#include <Pipe/ECS/Filtering.h>
#include <UI/UI.h>


namespace rift
{
void DrawDetailsPanel(AST::Tree& ast, AST::Id typeId)
{
auto& editor = ast.Get<CTypeEditor>(typeId);

if (!editor.showDetails)
{
return;
}

const String windowName = Strings::Format("Details##{}", typeId);
if (UI::Begin(windowName.c_str(), &editor.showDetails)) {}
UI::End();
}
} // namespace rift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2015-2022 Piperift - All rights reserved

#include "Utils/Properties.h"
#include "Utils/ElementsPanel.h"

#include "AST/Id.h"
#include "Components/CTypeEditor.h"
Expand All @@ -27,7 +27,6 @@ namespace rift
{
// using namespace EnumOperators;


void DrawVariable(TVariableAccessRef access, CTypeEditor& editor, AST::Id variableId)
{
auto* identifier = access.TryGet<CIdentifier>(variableId);
Expand All @@ -37,7 +36,7 @@ namespace rift
return;
}
String name = identifier->name.ToString();
if (!editor.propertiesFilter.PassFilter(name.data(), name.data() + name.size()))
if (!editor.elementsFilter.PassFilter(name.data(), name.data() + name.size()))
{
return;
}
Expand Down Expand Up @@ -137,7 +136,7 @@ namespace rift
return;
}
String name = identifier->name.ToString();
if (!editor.propertiesFilter.PassFilter(name.data(), name.data() + name.size()))
if (!editor.elementsFilter.PassFilter(name.data(), name.data() + name.size()))
{
return;
}
Expand Down Expand Up @@ -237,15 +236,20 @@ namespace rift
}
}

void DrawProperties(AST::Tree& ast, AST::Id typeId)
void DrawElementsPanel(AST::Tree& ast, AST::Id typeId)
{
auto& editor = ast.Get<CTypeEditor>(typeId);

const String windowName = Strings::Format("Properties##{}", typeId);
if (UI::Begin(windowName.c_str()))
if (!editor.showElements)
{
return;
}

const String windowName = Strings::Format("Elements##{}", typeId);
if (UI::Begin(windowName.c_str(), &editor.showElements))
{
UI::SetNextItemWidth(UI::GetContentRegionAvailWidth());
editor.propertiesFilter.Draw("##filter");
editor.elementsFilter.Draw("##filter");

if (Types::CanContainVariables(ast, typeId))
{
Expand Down
11 changes: 8 additions & 3 deletions Libs/Editor/Src/Utils/FunctionGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,13 +847,18 @@ namespace rift::Graph

void DrawTypeGraph(AST::Tree& ast, AST::Id typeId, CTypeEditor& typeEditor)
{
typeEditor.layout.BindNextWindowToNode(CTypeEditor::centralNode, ImGuiCond_Appearing);
if (!typeEditor.showGraph)
{
return;
}

static String graphId;
graphId.clear();
Strings::FormatTo(graphId, "Graph##{}", typeId);

bool wantsToOpenContextMenu = false;
UI::Begin(graphId.c_str(), nullptr, ImGuiWindowFlags_NoCollapse);
typeEditor.layout.BindNextWindowToNode(CTypeEditor::centralNode, ImGuiCond_Appearing);
if (UI::Begin(graphId.c_str(), &typeEditor.showGraph, ImGuiWindowFlags_NoCollapse))
{
Nodes::SetEditorContext(&typeEditor.nodesEditor);
Nodes::GetCurrentContext()->canCreateLinks = Types::CanEditFunctionBodies(ast, typeId);
Expand Down Expand Up @@ -920,8 +925,8 @@ namespace rift::Graph
ImGui::OpenPopup("ContextMenu", ImGuiPopupFlags_AnyPopup);
}
DrawContextMenu(ast, typeId, hoveredNodeId, hoveredLinkId);
UI::End();
}
UI::End();
}

void SetNodePosition(AST::Id id, v2 position)
Expand Down
2 changes: 1 addition & 1 deletion Libs/Editor/Src/Utils/ProjectManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2015-2022 Piperift - All rights reserved

#include "Editor.h"
#include "Utils/Properties.h"
#include "Utils/ElementsPanel.h"

#include <Pipe/Files/FileDialog.h>
#include <UI/Notify.h>
Expand Down

0 comments on commit 9a36fa9

Please sign in to comment.