From bedd78b3db0e875152d7fb494ad7921f97f2b1a0 Mon Sep 17 00:00:00 2001 From: trigaux Date: Fri, 17 Jan 2025 16:46:12 -0700 Subject: [PATCH 1/2] Add shortcuts window. --- CMakeLists.txt | 1 + include/flow/ui/widgets/Table.hpp | 6 +- include/flow/ui/widgets/Text.hpp | 6 +- include/flow/ui/windows/ShortcutsWindow.hpp | 22 ++++++ src/Editor.cpp | 4 +- src/Window.cpp | 7 +- src/widgets/PropertyTree.cpp | 2 +- src/widgets/Table.cpp | 7 +- src/widgets/Text.cpp | 2 +- src/windows/ShortcutsWindow.cpp | 79 +++++++++++++++++++++ 10 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 include/flow/ui/windows/ShortcutsWindow.hpp create mode 100644 src/windows/ShortcutsWindow.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ef0e0a0..336a364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,7 @@ add_library(${PROJECT_NAME} SHARED src/windows/GraphWindow.cpp src/windows/ModuleManagerWindow.cpp src/windows/NodeExplorerWindow.cpp + src/windows/ShortcutsWindow.cpp # Widget source files src/widgets/InputField.cpp diff --git a/include/flow/ui/widgets/Table.hpp b/include/flow/ui/widgets/Table.hpp index 0baea73..e55fe50 100644 --- a/include/flow/ui/widgets/Table.hpp +++ b/include/flow/ui/widgets/Table.hpp @@ -21,7 +21,7 @@ class Table : public Widget * @param name The name of the table. * @param columns The number of columns. */ - Table(const std::string& name, std::size_t columns); + Table(const std::string& name, std::size_t columns, std::size_t outer_width = 0, std::size_t outer_height = 0); virtual ~Table() = default; @@ -38,7 +38,9 @@ class Table : public Widget private: std::string _name; - std::size_t _columns = 0; + std::size_t _columns = 0; + std::size_t _outer_width = 0; + std::size_t _outer_height = 0; std::vector> _widgets; }; diff --git a/include/flow/ui/widgets/Text.hpp b/include/flow/ui/widgets/Text.hpp index 31119b3..01b0dfa 100644 --- a/include/flow/ui/widgets/Text.hpp +++ b/include/flow/ui/widgets/Text.hpp @@ -48,11 +48,11 @@ class Text : public Widget /** * @brief Constructs a text widget. * @param text The text to display. - * @param align The alignment of the text in the window. * @param colour The colour of the displayed text. + * @param align The alignment of the text in the window. */ - Text(const std::string& text, const Alignment& align = {HorizontalAlignment::Left, VerticalAlignment::Top}, - const Colour& colour = Colour()); + Text(const std::string& text, const Colour& colour = Colour(), + const Alignment& align = {HorizontalAlignment::Left, VerticalAlignment::Top}); virtual ~Text() = default; diff --git a/include/flow/ui/windows/ShortcutsWindow.hpp b/include/flow/ui/windows/ShortcutsWindow.hpp new file mode 100644 index 0000000..7552f0e --- /dev/null +++ b/include/flow/ui/windows/ShortcutsWindow.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "Core.hpp" +#include "Window.hpp" + +#include +#include +#include +#include + +FLOW_UI_NAMESPACE_START + +class ShortcutsWindow : public Window +{ + public: + ShortcutsWindow(); + virtual ~ShortcutsWindow() = default; + + virtual void Draw() override; +}; + +FLOW_UI_NAMESPACE_END diff --git a/src/Editor.cpp b/src/Editor.cpp index 174be06..489f315 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -10,6 +10,7 @@ #include "utilities/Conversions.hpp" #include "windows/ModuleManagerWindow.hpp" #include "windows/NodeExplorerWindow.hpp" +#include "windows/ShortcutsWindow.hpp" #include #include @@ -154,7 +155,8 @@ void Editor::Init(const std::string& initial_file) AddDockspace("PropertySubSpace", PropertyDockspace, 0.5f, DockspaceSplitDirection::Down); AddWindow(std::move(node_explorer), "PropertySubSpace"); - AddWindow(std::make_shared(_env, default_modules_path), "PropertySubSpace"); + AddWindow(std::make_shared(_env, default_modules_path), "PropertySubSpace", false); + AddWindow(std::make_shared(), PropertyDockspace, false); if (!initial_file.empty()) { diff --git a/src/Window.cpp b/src/Window.cpp index 7d31420..e46b518 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -13,10 +13,9 @@ Window::Window(std::string name) : _name{std::move(name)} {} void Window::Draw() { - widgets::Text( - "Nothing to show", - widgets::Text::Alignment{widgets::Text::HorizontalAlignment::Centre, widgets::Text::VerticalAlignment::Centre}, - Colour(175, 175, 175))(); + widgets::Text("Nothing to show", Colour(175, 175, 175), + widgets::Text::Alignment{widgets::Text::HorizontalAlignment::Centre, + widgets::Text::VerticalAlignment::Centre})(); } FLOW_UI_NAMESPACE_END diff --git a/src/widgets/PropertyTree.cpp b/src/widgets/PropertyTree.cpp index 2e5c960..cdadb5f 100644 --- a/src/widgets/PropertyTree.cpp +++ b/src/widgets/PropertyTree.cpp @@ -65,7 +65,7 @@ void PropertyTree::operator()() noexcept continue; } - auto property_table = Table(category_name + "##table", _columns); + auto property_table = Table(category_name + "##table", _columns, ImGui::GetItemRectSize().x + 1.f); for (const auto& widget : widgets) { property_table.AddEntry(widget); diff --git a/src/widgets/Table.cpp b/src/widgets/Table.cpp index 4e66036..e769ae3 100644 --- a/src/widgets/Table.cpp +++ b/src/widgets/Table.cpp @@ -4,13 +4,16 @@ FLOW_UI_SUBNAMESPACE_START(widgets) -Table::Table(const std::string& name, std::size_t columns) : _name(name), _columns(columns) {} +Table::Table(const std::string& name, std::size_t columns, std::size_t outer_width, std::size_t outer_height) + : _name(name), _columns(columns), _outer_width(outer_width), _outer_height(outer_height) +{ +} void Table::operator()() noexcept { ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(15.f, 5.f)); ImGui::BeginTable(_name.c_str(), static_cast(_columns), ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg, - ImGui::GetItemRectSize() + ImVec2(1.f, 0.f)); + ImVec2{static_cast(_outer_width), static_cast(_outer_height)}); for (const auto& widget : _widgets) { diff --git a/src/widgets/Text.cpp b/src/widgets/Text.cpp index e69ab96..c75bb6b 100644 --- a/src/widgets/Text.cpp +++ b/src/widgets/Text.cpp @@ -3,7 +3,7 @@ FLOW_UI_SUBNAMESPACE_START(widgets) -Text::Text(const std::string& text, const Alignment& align, const Colour& colour) +Text::Text(const std::string& text, const Colour& colour, const Alignment& align) : _text(text), _colour(colour), _align(align) { } diff --git a/src/windows/ShortcutsWindow.cpp b/src/windows/ShortcutsWindow.cpp new file mode 100644 index 0000000..b11b9a6 --- /dev/null +++ b/src/windows/ShortcutsWindow.cpp @@ -0,0 +1,79 @@ +#include "ShortcutsWindow.hpp" + +#include "widgets/Table.hpp" +#include "widgets/Text.hpp" + +#include + +#include + +FLOW_UI_NAMESPACE_START + +ShortcutsWindow::ShortcutsWindow() : Window("Shortcuts") {} + +#ifdef FLOW_APPLE +const std::string ctrl_key_str = "Cmd"; +const std::string alt_key_str = "Option"; +#else +const std::string ctrl_key_str = "Ctrl"; +const std::string alt_key_str = "Alt"; +#endif + +std::shared_ptr ShorcutTextBuilder(std::initializer_list keys) +{ + std::string text = ""; + for (auto it = keys.begin(); it != std::prev(keys.end()); ++it) + { + text += std::string(ImGui::GetKeyName(*it)) + " + "; + } + text += ImGui::GetKeyName(*std::prev(keys.end())); + + return std::make_shared(text); +} + +void AddShortcutText(widgets::Table& table, const std::string& name, std::initializer_list keys, + const Colour& colour = Colour()) +{ + table.AddEntry(std::make_shared(name, colour)); + table.AddEntry(ShorcutTextBuilder(keys)); +} + +void ShortcutsWindow::Draw() +{ + auto window_shortcuts_table = widgets::Table("Shortcuts", 2); + + AddShortcutText(window_shortcuts_table, "New Window", {ImGuiKey_LeftCtrl, ImGuiKey_N}); + AddShortcutText(window_shortcuts_table, "Close Window", {ImGuiKey_LeftCtrl, ImGuiKey_W}); + + auto graph_shortcuts_table = widgets::Table("Shortcuts", 2); + + AddShortcutText(graph_shortcuts_table, "Break Link", {ImGuiKey_LeftAlt, ImGuiKey_MouseLeft}); + + AddShortcutText(graph_shortcuts_table, "Copy", {ImGuiKey_LeftCtrl, ImGuiKey_C}); + + AddShortcutText(graph_shortcuts_table, "Cut (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_X}, Colour(244, 129, 36)); + + AddShortcutText(graph_shortcuts_table, "Paste", {ImGuiKey_LeftCtrl, ImGuiKey_V}); + + AddShortcutText(graph_shortcuts_table, "Duplicate", {ImGuiKey_LeftCtrl, ImGuiKey_D}); + + AddShortcutText(graph_shortcuts_table, "Undo (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_Z}, + Colour(244, 129, 36)); + + AddShortcutText(graph_shortcuts_table, "Redo (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_Y}, + Colour(244, 129, 36)); + + AddShortcutText(graph_shortcuts_table, "Delete Selection", {ImGuiKey_Delete}); + + AddShortcutText(graph_shortcuts_table, "Focus", {ImGuiKey_F}); + + widgets::Text("Window Shortcuts")(); + ImGui::Separator(); + window_shortcuts_table(); + + widgets::Text("Graph Shortcuts")(); + ImGui::Separator(); + graph_shortcuts_table(); +} + +FLOW_UI_NAMESPACE_END From 1e7ddb4bf474027b4d175916dd8323eb88ea5eb0 Mon Sep 17 00:00:00 2001 From: trigaux Date: Fri, 17 Jan 2025 17:02:04 -0700 Subject: [PATCH 2/2] Cleaning up and reducing draw time calculations. --- src/windows/ShortcutsWindow.cpp | 63 +++++++++++++-------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/src/windows/ShortcutsWindow.cpp b/src/windows/ShortcutsWindow.cpp index b11b9a6..b66f1f3 100644 --- a/src/windows/ShortcutsWindow.cpp +++ b/src/windows/ShortcutsWindow.cpp @@ -9,16 +9,6 @@ FLOW_UI_NAMESPACE_START -ShortcutsWindow::ShortcutsWindow() : Window("Shortcuts") {} - -#ifdef FLOW_APPLE -const std::string ctrl_key_str = "Cmd"; -const std::string alt_key_str = "Option"; -#else -const std::string ctrl_key_str = "Ctrl"; -const std::string alt_key_str = "Alt"; -#endif - std::shared_ptr ShorcutTextBuilder(std::initializer_list keys) { std::string text = ""; @@ -38,42 +28,37 @@ void AddShortcutText(widgets::Table& table, const std::string& name, std::initia table.AddEntry(ShorcutTextBuilder(keys)); } -void ShortcutsWindow::Draw() -{ - auto window_shortcuts_table = widgets::Table("Shortcuts", 2); - - AddShortcutText(window_shortcuts_table, "New Window", {ImGuiKey_LeftCtrl, ImGuiKey_N}); - AddShortcutText(window_shortcuts_table, "Close Window", {ImGuiKey_LeftCtrl, ImGuiKey_W}); - - auto graph_shortcuts_table = widgets::Table("Shortcuts", 2); - - AddShortcutText(graph_shortcuts_table, "Break Link", {ImGuiKey_LeftAlt, ImGuiKey_MouseLeft}); - - AddShortcutText(graph_shortcuts_table, "Copy", {ImGuiKey_LeftCtrl, ImGuiKey_C}); - - AddShortcutText(graph_shortcuts_table, "Cut (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_X}, Colour(244, 129, 36)); +auto window_shortcuts = widgets::Table("Window Shortcuts", 2); +auto graph_shortcuts = widgets::Table("Graph Shortcuts", 2); - AddShortcutText(graph_shortcuts_table, "Paste", {ImGuiKey_LeftCtrl, ImGuiKey_V}); - - AddShortcutText(graph_shortcuts_table, "Duplicate", {ImGuiKey_LeftCtrl, ImGuiKey_D}); - - AddShortcutText(graph_shortcuts_table, "Undo (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_Z}, - Colour(244, 129, 36)); - - AddShortcutText(graph_shortcuts_table, "Redo (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_Y}, - Colour(244, 129, 36)); - - AddShortcutText(graph_shortcuts_table, "Delete Selection", {ImGuiKey_Delete}); - - AddShortcutText(graph_shortcuts_table, "Focus", {ImGuiKey_F}); +ShortcutsWindow::ShortcutsWindow() : Window("Shortcuts") +{ + AddShortcutText(window_shortcuts, "New Flow", {ImGuiKey_LeftCtrl, ImGuiKey_N}); + AddShortcutText(window_shortcuts, "Open Flow", {ImGuiKey_LeftCtrl, ImGuiKey_O}); + AddShortcutText(window_shortcuts, "Save Flow", {ImGuiKey_LeftCtrl, ImGuiKey_S}); + AddShortcutText(window_shortcuts, "Save Flow As", {ImGuiKey_LeftCtrl, ImGuiKey_LeftAlt, ImGuiKey_S}); + AddShortcutText(window_shortcuts, "Close Flow", {ImGuiKey_LeftCtrl, ImGuiKey_W}); + + AddShortcutText(graph_shortcuts, "Break Link", {ImGuiKey_LeftAlt, ImGuiKey_MouseLeft}); + AddShortcutText(graph_shortcuts, "Copy", {ImGuiKey_LeftCtrl, ImGuiKey_C}); + AddShortcutText(graph_shortcuts, "Cut (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_X}, Colour(244, 129, 36)); + AddShortcutText(graph_shortcuts, "Duplicate", {ImGuiKey_LeftCtrl, ImGuiKey_D}); + AddShortcutText(graph_shortcuts, "Paste", {ImGuiKey_LeftCtrl, ImGuiKey_V}); + AddShortcutText(graph_shortcuts, "Delete Selection", {ImGuiKey_Delete}); + AddShortcutText(graph_shortcuts, "Focus", {ImGuiKey_F}); + AddShortcutText(graph_shortcuts, "Undo (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_Z}, Colour(244, 129, 36)); + AddShortcutText(graph_shortcuts, "Redo (Experimental)", {ImGuiKey_LeftCtrl, ImGuiKey_Y}, Colour(244, 129, 36)); +} +void ShortcutsWindow::Draw() +{ widgets::Text("Window Shortcuts")(); ImGui::Separator(); - window_shortcuts_table(); + window_shortcuts(); widgets::Text("Graph Shortcuts")(); ImGui::Separator(); - graph_shortcuts_table(); + graph_shortcuts(); } FLOW_UI_NAMESPACE_END