Skip to content

Commit

Permalink
Rename uiStorage.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Sep 24, 2024
1 parent 6ad9b3f commit 7ff4444
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
14 changes: 7 additions & 7 deletions packages/rendering/include/rendering/ui/UIContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ namespace l::ui {
UISplitMode mSplitMode;
};

class UIStorage {
class UIManager {
public:
UIStorage() = default;
~UIStorage() = default;
UIManager() = default;
~UIManager() = default;

UIHandle Add(std::unique_ptr<UIContainer> container);
void Remove(const UIHandle& handle);
Expand All @@ -426,9 +426,9 @@ namespace l::ui {
int32_t mIdCounter = 1;
};

UIHandle CreateContainer(UIStorage& uiStorage, uint32_t flags, UIRenderType renderType = UIRenderType::Rect, UIAlignH alignH = UIAlignH::Left, UIAlignV alignV = UIAlignV::Top, UILayoutH layoutH = UILayoutH::Fixed, UILayoutV layoutV = UILayoutV::Fixed);
UIHandle CreateSplit(UIStorage& uiStorage, uint32_t flags, UIRenderType renderType, UISplitMode splitMode = UISplitMode::AppendV, UILayoutH layoutH = UILayoutH::Fixed, UILayoutV layoutV = UILayoutV::Fixed);
void DeleteContainer(UIStorage& uiStorage, UIHandle handle);
void DeleteContainer(UIStorage& uiStorage, UIContainer* container);
UIHandle CreateContainer(UIManager& uiManager, uint32_t flags, UIRenderType renderType = UIRenderType::Rect, UIAlignH alignH = UIAlignH::Left, UIAlignV alignV = UIAlignV::Top, UILayoutH layoutH = UILayoutH::Fixed, UILayoutV layoutV = UILayoutV::Fixed);
UIHandle CreateSplit(UIManager& uiManager, uint32_t flags, UIRenderType renderType, UISplitMode splitMode = UISplitMode::AppendV, UILayoutH layoutH = UILayoutH::Fixed, UILayoutV layoutV = UILayoutV::Fixed);
void DeleteContainer(UIManager& uiManager, UIHandle handle);
void DeleteContainer(UIManager& uiManager, UIContainer* container);

}
2 changes: 1 addition & 1 deletion packages/rendering/include/rendering/ui/UICreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

namespace l::ui {

UIHandle CreateUINode(UIStorage& uiStorage, l::nodegraph::NodeGraphBase& node, ImVec2 p);
UIHandle CreateUINode(UIManager& uiManager, l::nodegraph::NodeGraphBase& node, ImVec2 p);
}
8 changes: 4 additions & 4 deletions packages/rendering/include/rendering/ui/UINodeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace l::ui {

class UINodeEditor : public UIBase {
public:
UINodeEditor(std::string_view editorName) : mUIWindow(editorName), mLinkIOVisitor(mUIStorage), mSelectVisitor(mUIStorage) {
mUIRoot = CreateContainer(mUIStorage, l::ui::UIContainer_DragFlag | l::ui::UIContainer_ZoomFlag);
UINodeEditor(std::string_view editorName) : mUIWindow(editorName), mLinkIOVisitor(mUIManager), mSelectVisitor(mUIManager) {
mUIRoot = CreateContainer(mUIManager, l::ui::UIContainer_DragFlag | l::ui::UIContainer_ZoomFlag);

mUIWindow.SetContentWindow([&]() {
ImGui::PushItemWidth(400);
Expand Down Expand Up @@ -57,7 +57,7 @@ namespace l::ui {
auto nodeId = mNGSchema->NewNode(it.GetId());
auto node = mNGSchema->GetNode(nodeId);
if (node != nullptr) {
auto uiNode = l::ui::CreateUINode(mUIStorage, *node, p);
auto uiNode = l::ui::CreateUINode(mUIManager, *node, p);
mUIRoot->Add(uiNode);
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ namespace l::ui {

protected:
UIWindow mUIWindow;
UIStorage mUIStorage;
UIManager mUIManager;
UIHandle mUIRoot;
InputState mUIInput;

Expand Down
8 changes: 4 additions & 4 deletions packages/rendering/include/rendering/ui/UIVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace l::ui {

class UISelect : public UIVisitor {
public:
UISelect(UIStorage& uiStorage) : mUIStorage(uiStorage) {}
UISelect(UIManager& uiManager) : mUIManager(uiManager) {}

virtual bool Visit(UIContainer& container, const InputState& input);

Expand All @@ -61,7 +61,7 @@ namespace l::ui {
}
protected:
std::unordered_set<UIContainer*> mSelectedContainers;
UIStorage& mUIStorage;
UIManager& mUIManager;
l::nodegraph::NodeGraphSchema* mNGSchema = nullptr;
};

Expand Down Expand Up @@ -102,7 +102,7 @@ namespace l::ui {
public:
using HandlerFunctionType = bool(int32_t, int32_t, int32_t, int32_t, bool);

UILinkIO(UIStorage& uiStorage) : mUIStorage(uiStorage) {}
UILinkIO(UIManager& uiManager) : mUIManager(uiManager) {}
~UILinkIO() = default;

virtual bool Active(UIContainer& container, const InputState& input);
Expand Down Expand Up @@ -131,7 +131,7 @@ namespace l::ui {
protected:
bool mDragging = false;
UIHandle mLinkContainer;
UIStorage& mUIStorage;
UIManager& mUIManager;
l::nodegraph::NodeGraphSchema* mNGSchema = nullptr;
};

Expand Down
26 changes: 13 additions & 13 deletions packages/rendering/source/common/ui/UIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,64 +280,64 @@ namespace l::ui {
return false;
}

UIHandle UIStorage::Add(std::unique_ptr<UIContainer> container) {
UIHandle UIManager::Add(std::unique_ptr<UIContainer> container) {
auto id = mIdCounter++;
auto stringId = container->GetStringId();
container->SetId(id);
mContainers.insert({ id, std::move(container) });
return UIHandle{ id, stringId, mContainers.at(id).get() };
}

void UIStorage::Remove(const UIHandle& handle) {
void UIManager::Remove(const UIHandle& handle) {
if (handle.IsValid()) {
mContainers.erase(handle.GetId());
}
}

void UIStorage::Remove(UIContainer* container) {
void UIManager::Remove(UIContainer* container) {
if (container != nullptr) {
mContainers.erase(container->GetId());
}
}

UIHandle CreateContainer(UIStorage& uiStorage, uint32_t flags, UIRenderType renderType, UIAlignH alignH, UIAlignV alignV, UILayoutH layoutH, UILayoutV layoutV) {
UIHandle CreateContainer(UIManager& uiManager, uint32_t flags, UIRenderType renderType, UIAlignH alignH, UIAlignV alignV, UILayoutH layoutH, UILayoutV layoutV) {
std::unique_ptr<UIContainer> container = std::make_unique<UIContainer>(flags, renderType, alignH, alignV, layoutH, layoutV);

auto stringId = CreateUniqueStringId<UIContainer>();
container->SetStringId(stringId);

return uiStorage.Add(std::move(container));
return uiManager.Add(std::move(container));
}

UIHandle CreateSplit(UIStorage& uiStorage, uint32_t flags, UIRenderType renderType, UISplitMode splitMode, UILayoutH layoutH, UILayoutV layoutV) {
UIHandle CreateSplit(UIManager& uiManager, uint32_t flags, UIRenderType renderType, UISplitMode splitMode, UILayoutH layoutH, UILayoutV layoutV) {
std::unique_ptr<UISplit> container = std::make_unique<UISplit>(flags, renderType, splitMode, layoutH, layoutV);

auto stringId = CreateUniqueStringId<UIContainer>();
container->SetStringId(stringId);

return uiStorage.Add(std::move(container));
return uiManager.Add(std::move(container));
}

void DeleteContainer(UIStorage& uiStorage, UIHandle handle) {
void DeleteContainer(UIManager& uiManager, UIHandle handle) {
if (handle.IsValid()) {
ASSERT(handle.Get()->GetParent() != nullptr);
handle.Get()->GetParent()->Remove(handle);
handle->ForEachChild([&](UIContainer* container) {
uiStorage.Remove(container);
uiManager.Remove(container);
});
uiStorage.Remove(handle);
uiManager.Remove(handle);
}
}

void DeleteContainer(UIStorage& uiStorage, UIContainer* container) {
void DeleteContainer(UIManager& uiManager, UIContainer* container) {
if (container != nullptr) {
ASSERT(container->GetParent() != nullptr);
container->GetParent()->Remove(container);
container->ForEachChild([&](UIContainer* c) {
uiStorage.Remove(c);
uiManager.Remove(c);
});

uiStorage.Remove(container);
uiManager.Remove(container);
}
}
}
24 changes: 12 additions & 12 deletions packages/rendering/source/common/ui/UICreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace l::ui {


UIHandle CreateUINode(UIStorage& uiStorage, l::nodegraph::NodeGraphBase& node, ImVec2 p) {
UIHandle CreateUINode(UIManager& uiManager, l::nodegraph::NodeGraphBase& node, ImVec2 p) {


auto numInputChannels = node.GetNumInputs();
auto numOutputChannels = node.GetNumOutputs();
auto numRows = numInputChannels > numOutputChannels ? numInputChannels : numOutputChannels;

auto node4 = CreateSplit(uiStorage, l::ui::UIContainer_ResizeFlag | l::ui::UIContainer_MoveFlag | l::ui::UIContainer_DrawFlag | UIContainer_SelectFlag, l::ui::UIRenderType::RectFilled, l::ui::UISplitMode::AppendV);
auto node4 = CreateSplit(uiManager, l::ui::UIContainer_ResizeFlag | l::ui::UIContainer_MoveFlag | l::ui::UIContainer_DrawFlag | UIContainer_SelectFlag, l::ui::UIRenderType::RectFilled, l::ui::UISplitMode::AppendV);
node4->SetColor(ImVec4(0.15f, 0.15f, 0.15f, 1.0f));
node4->SetPosition(p);
node4->GetContainerArea().mMargin = 0.0f;
Expand All @@ -22,20 +22,20 @@ namespace l::ui {
float ioSize = 4.0f;
float ioOffsetV = 1.6f;

auto row0 = CreateContainer(uiStorage, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::RectFilled, l::ui::UIAlignH::Left, l::ui::UIAlignV::Top, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Fixed);
auto row0 = CreateContainer(uiManager, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::RectFilled, l::ui::UIAlignH::Left, l::ui::UIAlignV::Top, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Fixed);
row0->SetSize(ImVec2(1.0f, 18.0f));
row0->GetContainerArea().mMargin = 2.0f;
node4->Add(row0);
{
auto connector1Text = CreateContainer(uiStorage, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Text, l::ui::UIAlignH::Center, l::ui::UIAlignV::Middle);
auto connector1Text = CreateContainer(uiManager, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Text, l::ui::UIAlignH::Center, l::ui::UIAlignV::Middle);
connector1Text->SetDisplayName(node.GetName());
auto textSize = ImGui::CalcTextSize(node.GetName().data());
sizeEstimate.x = sizeEstimate.x < textSize.x ? textSize.x : sizeEstimate.x;
connector1Text->GetContainerArea().mRender.mColor = ImColor(ImVec4(0.5f, 1.0f, 0.4f, 1.0f));
row0->Add(connector1Text);
}
for (int8_t i = 0; i < numInputChannels || i < numOutputChannels || i < numInputChannels || i < numOutputChannels; i++) {
auto row = CreateContainer(uiStorage, 0, l::ui::UIRenderType::Rect, l::ui::UIAlignH::Left, l::ui::UIAlignV::Top, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Fixed);
auto row = CreateContainer(uiManager, 0, l::ui::UIRenderType::Rect, l::ui::UIAlignH::Left, l::ui::UIAlignV::Top, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Fixed);
row->GetContainerArea().mMargin = ioSize;
node4->Add(row);
{
Expand All @@ -44,23 +44,23 @@ namespace l::ui {

float estimatedWidth = 0.0f;
if (showsInput && !node.IsDataConstant(i)) {
auto in = CreateContainer(uiStorage, l::ui::UIContainer_InputFlag | l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::CircleFilled, l::ui::UIAlignH::Left);
auto in = CreateContainer(uiManager, l::ui::UIContainer_InputFlag | l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::CircleFilled, l::ui::UIAlignH::Left);
in->SetPosition(ImVec2(-ioSize, ioSize * ioOffsetV));
in->SetSize(ImVec2(ioSize, ioSize));
in->GetContainerArea().mMargin = 0.0f;
in->SetNodeId(node.GetId());
in->SetChannelId(i);
estimatedWidth += ioSize;
row->Add(in);
auto inText = CreateContainer(uiStorage, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Text, l::ui::UIAlignH::Left);
auto inText = CreateContainer(uiManager, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Text, l::ui::UIAlignH::Left);
inText->SetPosition(ImVec2(0.0f, 0.0f));
inText->SetDisplayName(node.GetInputName(i));
estimatedWidth += ImGui::CalcTextSize(node.GetInputName(i).data()).x;
row->Add(inText);
}

if (node.IsDataVisible(i)) {
auto inText = CreateContainer(uiStorage, (node.IsDataEditable(i) ? l::ui::UIContainer_EditFlag : 0) | l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::NodeOutputValue, l::ui::UIAlignH::Left);
auto inText = CreateContainer(uiManager, (node.IsDataEditable(i) ? l::ui::UIContainer_EditFlag : 0) | l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::NodeOutputValue, l::ui::UIAlignH::Left);
inText->SetPosition(ImVec2(estimatedWidth, 0.0f));
inText->SetSize(ImVec2(10 * 7, 14.0f));
inText->SetNodeId(node.GetId());
Expand All @@ -70,15 +70,15 @@ namespace l::ui {
}

if (showsOutput) {
auto out = CreateContainer(uiStorage, l::ui::UIContainer_OutputFlag | l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::CircleFilled, l::ui::UIAlignH::Right);
auto out = CreateContainer(uiManager, l::ui::UIContainer_OutputFlag | l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::CircleFilled, l::ui::UIAlignH::Right);
out->SetPosition(ImVec2(ioSize * 2.0f, ioSize * ioOffsetV));
out->SetSize(ImVec2(ioSize, ioSize));
out->GetContainerArea().mMargin = 0.0f;
out->SetNodeId(node.GetId());
out->SetChannelId(i);
estimatedWidth += ioSize;
row->Add(out);
auto outText = CreateContainer(uiStorage, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Text, l::ui::UIAlignH::Right);
auto outText = CreateContainer(uiManager, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Text, l::ui::UIAlignH::Right);
outText->SetPosition(ImVec2(0.0f, 0.0f));
outText->SetDisplayName(node.GetOutputName(i));
estimatedWidth += ImGui::CalcTextSize(node.GetOutputName(i).data()).x;
Expand All @@ -89,13 +89,13 @@ namespace l::ui {
}

if (node.GetOutputType() == l::nodegraph::OutputType::ExternalVisualOutput) {
auto row = CreateContainer(uiStorage, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Rect, l::ui::UIAlignH::Left, l::ui::UIAlignV::Bottom, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Parent);
auto row = CreateContainer(uiManager, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::Rect, l::ui::UIAlignH::Left, l::ui::UIAlignV::Bottom, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Parent);
row->SetPosition(ImVec2(0.0f, 0.0f));
row->GetContainerArea().mMargin = ioSize;
node4->Add(row);

float estimatedWidth = 0.0f;
auto plot = CreateContainer(uiStorage, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::NodeOutputGraph, l::ui::UIAlignH::Center, l::ui::UIAlignV::Bottom, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Parent);
auto plot = CreateContainer(uiManager, l::ui::UIContainer_DrawFlag, l::ui::UIRenderType::NodeOutputGraph, l::ui::UIAlignH::Center, l::ui::UIAlignV::Bottom, l::ui::UILayoutH::Parent, l::ui::UILayoutV::Parent);
plot->SetPosition(ImVec2(estimatedWidth, 0.0f));
plot->SetSize(ImVec2(100, 100));
plot->SetNodeId(node.GetId());
Expand Down
6 changes: 3 additions & 3 deletions packages/rendering/source/common/ui/UIVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace l::ui {
if (mNGSchema != nullptr) {
mNGSchema->RemoveNode(it->GetNodeId());
}
DeleteContainer(mUIStorage, it);
DeleteContainer(mUIManager, it);
}
mSelectedContainers.clear();
return true;
Expand Down Expand Up @@ -435,7 +435,7 @@ namespace l::ui {
ImVec2 pT = layoutArea.Transform(pCenter);
if (OverlapCircle(input.mCurPos, pT, 2.0f * size.x * layoutArea.mScale)) {
mDragging = true;
mLinkContainer = CreateContainer(mUIStorage, UIContainer_LinkFlag | UIContainer_DrawFlag, UIRenderType::LinkH);
mLinkContainer = CreateContainer(mUIManager, UIContainer_LinkFlag | UIContainer_DrawFlag, UIRenderType::LinkH);
container.Add(mLinkContainer);
return true;
}
Expand Down Expand Up @@ -489,7 +489,7 @@ namespace l::ui {
mLinkContainer.Reset();
}
else {
DeleteContainer(mUIStorage, mLinkContainer.Get());
DeleteContainer(mUIManager, mLinkContainer.Get());
mDragging = false;
mLinkContainer.Reset();
return true;
Expand Down

0 comments on commit 7ff4444

Please sign in to comment.