Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class TexturePreview : public OvUI::Plugins::IPlugin
texture = OvCore::Global::ServiceLocator::Get<OvCore::ResourceManagement::TextureManager>()[p_path];
}

virtual void Execute() override
virtual void Execute(OvUI::Plugins::EPluginExecutionContext p_context) override
{
if (ImGui::IsItemHovered())
{
Expand Down Expand Up @@ -158,10 +158,10 @@ class BrowserItemContextualMenu : public OvUI::Plugins::ContextualMenu
}
}

virtual void Execute() override
virtual void Execute(OvUI::Plugins::EPluginExecutionContext p_context) override
{
if (m_widgets.size() > 0)
OvUI::Plugins::ContextualMenu::Execute();
OvUI::Plugins::ContextualMenu::Execute(p_context);
}

virtual void DeleteItem() = 0;
Expand Down
8 changes: 5 additions & 3 deletions Sources/Overload/OvEditor/src/OvEditor/Panels/Hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ class ActorContextualMenu : public OvUI::Plugins::ContextualMenu
OvEditor::Utils::ActorCreationMenu::GenerateActorCreationMenu(createActor, m_target, std::bind(&OvUI::Widgets::Layout::TreeNode::Open, &m_treeNode));
}

virtual void Execute() override
virtual void Execute(OvUI::Plugins::EPluginExecutionContext p_context) override
{
if (m_widgets.size() > 0)
OvUI::Plugins::ContextualMenu::Execute();
OvUI::Plugins::ContextualMenu::Execute(p_context);
}

private:
Expand Down Expand Up @@ -191,7 +191,9 @@ OvEditor::Panels::Hierarchy::Hierarchy

p_element.first->DetachFromParent();
};
m_sceneRoot->AddPlugin<ActorContextualMenu>(nullptr, *m_sceneRoot);
m_sceneRoot->AddPlugin<ActorContextualMenu>(nullptr, *m_sceneRoot);

AddPlugin<ActorContextualMenu>(nullptr, *m_sceneRoot);

// TODO: This code is unsafe, if the hierarchy gets deleted before the last actor gets deleted, this might crash
EDITOR_EVENT(ActorUnselectedEvent) += std::bind(&Hierarchy::UnselectActorsWidgets, this);
Expand Down
5 changes: 3 additions & 2 deletions Sources/Overload/OvUI/include/OvUI/Panels/APanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
#include <vector>
#include <unordered_map>

#include "OvUI/Internal/WidgetContainer.h"
#include <OvUI/Internal/WidgetContainer.h>
#include <OvUI/Plugins/Pluginable.h>

namespace OvUI::Panels
{
/**
* A Panel is a component of a canvas. It is a sort of window in the UI
*/
class APanel : public API::IDrawable, public Internal::WidgetContainer
class APanel : public API::IDrawable, public Plugins::Pluginable, public Internal::WidgetContainer
{
public:
/**
Expand Down
3 changes: 2 additions & 1 deletion Sources/Overload/OvUI/include/OvUI/Plugins/ContextualMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ namespace OvUI::Plugins
public:
/**
* Execute the plugin
* @param p_context
*/
void Execute();
void Execute(EPluginExecutionContext p_context);

/**
* Force close the contextual menu
Expand Down
3 changes: 2 additions & 1 deletion Sources/Overload/OvUI/include/OvUI/Plugins/DDSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ namespace OvUI::Plugins

/**
* Execute the behaviour of the drag and drop source
* @param p_context
*/
virtual void Execute() override
virtual void Execute(EPluginExecutionContext p_context) override
{
ImGuiDragDropFlags src_flags = 0;
src_flags |= ImGuiDragDropFlags_SourceNoDisableHover; // Keep the source displayed as hovered
Expand Down
4 changes: 2 additions & 2 deletions Sources/Overload/OvUI/include/OvUI/Plugins/DDTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace OvUI::Plugins

/**
* Execute the drag and drop target behaviour
* @param p_identifier
* @param p_context
*/
virtual void Execute() override
virtual void Execute(EPluginExecutionContext p_context) override
{
if (ImGui::BeginDragDropTarget())
{
Expand Down
3 changes: 2 additions & 1 deletion Sources/Overload/OvUI/include/OvUI/Plugins/DataDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ namespace OvUI::Plugins

/**
* Execute the data dispatcher behaviour (No effect)
* @param p_context
*/
virtual void Execute() override {}
virtual void Execute(EPluginExecutionContext p_context) override {}

private:
bool m_valueChanged = false;
Expand Down
13 changes: 11 additions & 2 deletions Sources/Overload/OvUI/include/OvUI/Plugins/IPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

#pragma once


namespace OvUI::Plugins
{
/**
* Context of execution for a plugin
*/
enum class EPluginExecutionContext
{
WIDGET,
PANEL
};

/**
* Interface to any plugin of OvUI.
* A plugin is basically a behaviour that you can plug to a widget
Expand All @@ -18,8 +26,9 @@ namespace OvUI::Plugins
public:
/**
* Execute the plugin behaviour
* @param p_context
*/
virtual void Execute() = 0;
virtual void Execute(EPluginExecutionContext p_context) = 0;

/* Feel free to store any data you want here */
void* userData = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions Sources/Overload/OvUI/include/OvUI/Plugins/Pluginable.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OvUI::Plugins
/**
* Destructor (Destroys every plugins)
*/
~Pluginable()
virtual ~Pluginable()
{
RemoveAllPlugins();
}
Expand Down Expand Up @@ -61,10 +61,10 @@ namespace OvUI::Plugins
/**
* Execute every plugins
*/
void ExecutePlugins()
void ExecutePlugins(EPluginExecutionContext p_context)
{
for (auto& plugin : m_plugins)
plugin->Execute();
plugin->Execute(p_context);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Sources/Overload/OvUI/src/OvUI/Panels/APanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ OvUI::Panels::APanel::APanel()
void OvUI::Panels::APanel::Draw()
{
if (enabled)
{
_Draw_Impl();
}
}

const std::string & OvUI::Panels::APanel::GetPanelID() const
Expand Down
1 change: 1 addition & 0 deletions Sources/Overload/OvUI/src/OvUI/Panels/PanelWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void OvUI::Panels::PanelWindow::_Draw_Impl()
m_mustScrollToTop = false;
}

ExecutePlugins(Plugins::EPluginExecutionContext::PANEL);
DrawWidgets();
}

Expand Down
7 changes: 4 additions & 3 deletions Sources/Overload/OvUI/src/OvUI/Plugins/ContextualMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* @licence: MIT
*/

#include "OvUI/Plugins/ContextualMenu.h"
#include <OvUI/Panels/APanel.h>
#include <OvUI/Plugins/ContextualMenu.h>

void OvUI::Plugins::ContextualMenu::Execute()
void OvUI::Plugins::ContextualMenu::Execute(EPluginExecutionContext p_context)
{
if (ImGui::BeginPopupContextItem())
if (p_context == EPluginExecutionContext::PANEL ? ImGui::BeginPopupContextWindow() : ImGui::BeginPopupContextItem())
{
DrawWidgets();
ImGui::EndPopup();
Expand Down
2 changes: 1 addition & 1 deletion Sources/Overload/OvUI/src/OvUI/Widgets/AWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void OvUI::Widgets::AWidget::Draw()
_Draw_Impl();

if (m_autoExecutePlugins)
ExecutePlugins();
ExecutePlugins(Plugins::EPluginExecutionContext::WIDGET);

if (!lineBreak)
ImGui::SameLine();
Expand Down
4 changes: 2 additions & 2 deletions Sources/Overload/OvUI/src/OvUI/Widgets/Layout/TreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void OvUI::Widgets::Layout::TreeNode::_Draw_Impl()

m_opened = true;

ExecutePlugins(); // Manually execute plugins to make plugins considering the TreeNode and no childs
ExecutePlugins(Plugins::EPluginExecutionContext::WIDGET); // Manually execute plugins to make plugins considering the TreeNode and no childs

DrawWidgets();

Expand All @@ -83,6 +83,6 @@ void OvUI::Widgets::Layout::TreeNode::_Draw_Impl()

m_opened = false;

ExecutePlugins(); // Manually execute plugins to make plugins considering the TreeNode and no childs
ExecutePlugins(Plugins::EPluginExecutionContext::WIDGET); // Manually execute plugins to make plugins considering the TreeNode and no childs
}
}