From 091773be1b8dfeef3456d1ec20e890b66808d366 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Sun, 15 Oct 2023 13:15:31 -0400 Subject: [PATCH] add icon to menu entries --- include/NazaraEditor/Core/UI/Window.hpp | 3 ++- src/NazaraEditor/Core/UI/Window.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/NazaraEditor/Core/UI/Window.hpp b/include/NazaraEditor/Core/UI/Window.hpp index 374bf5d..a234acd 100644 --- a/include/NazaraEditor/Core/UI/Window.hpp +++ b/include/NazaraEditor/Core/UI/Window.hpp @@ -22,7 +22,7 @@ namespace Nz virtual void OnRenderImgui() override; - void AddMenuAction(const std::string& path, const std::string& shortcut, ActionCallback callback); + void AddMenuAction(const std::string& path, const std::string& shortcut, ActionCallback callback, const std::shared_ptr& icon = {}); void AddMenuSeparator(const std::string& path); EditorBaseApplication* GetApplication() { return m_application; } @@ -44,6 +44,7 @@ namespace Nz { std::string label; std::string shortcut; + std::shared_ptr icon; ActionCallback callback; }; diff --git a/src/NazaraEditor/Core/UI/Window.cpp b/src/NazaraEditor/Core/UI/Window.cpp index 3fea116..873d311 100644 --- a/src/NazaraEditor/Core/UI/Window.cpp +++ b/src/NazaraEditor/Core/UI/Window.cpp @@ -34,7 +34,7 @@ namespace Nz } } - void EditorWindow::AddMenuAction(const std::string& path, const std::string& shortcut, ActionCallback callback) + void EditorWindow::AddMenuAction(const std::string& path, const std::string& shortcut, ActionCallback callback, const std::shared_ptr& icon) { std::vector v; Nz::SplitString(path, "|", [&](std::string_view str) { v.push_back(str); return true; }); @@ -45,7 +45,7 @@ namespace Nz MenuList& parent = GetOrCreateMenuHierarchy(v); - parent.entries.push_back(MenuAction{ leaf, shortcut, callback}); + parent.entries.push_back(MenuAction{ leaf, shortcut, icon, callback}); } void EditorWindow::AddMenuSeparator(const std::string& path) @@ -77,6 +77,11 @@ namespace Nz ImGui::Separator(); }, [](const MenuAction& arg) { + if (arg.icon) + { + ImGui::Image(arg.icon.get(), Nz::Vector2{ 14, 14 }); + ImGui::SameLine(); + } if (ImGui::MenuItem(arg.label.c_str(), arg.shortcut.c_str())) arg.callback(); },