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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions include/flow/ui/widgets/Table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<std::shared_ptr<Widget>> _widgets;
};

Expand Down
6 changes: 3 additions & 3 deletions include/flow/ui/widgets/Text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 22 additions & 0 deletions include/flow/ui/windows/ShortcutsWindow.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "Core.hpp"
#include "Window.hpp"

#include <flow/core/Env.hpp>
#include <flow/core/Event.hpp>
#include <flow/core/Graph.hpp>
#include <flow/core/NodeFactory.hpp>

FLOW_UI_NAMESPACE_START

class ShortcutsWindow : public Window
{
public:
ShortcutsWindow();
virtual ~ShortcutsWindow() = default;

virtual void Draw() override;
};

FLOW_UI_NAMESPACE_END
4 changes: 3 additions & 1 deletion src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "utilities/Conversions.hpp"
#include "windows/ModuleManagerWindow.hpp"
#include "windows/NodeExplorerWindow.hpp"
#include "windows/ShortcutsWindow.hpp"

#include <flow/core/Node.hpp>
#include <flow/core/NodeFactory.hpp>
Expand Down Expand Up @@ -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<ModuleManagerWindow>(_env, default_modules_path), "PropertySubSpace");
AddWindow(std::make_shared<ModuleManagerWindow>(_env, default_modules_path), "PropertySubSpace", false);
AddWindow(std::make_shared<ShortcutsWindow>(), PropertyDockspace, false);

if (!initial_file.empty())
{
Expand Down
7 changes: 3 additions & 4 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/widgets/PropertyTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/widgets/Table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(_columns), ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg,
ImGui::GetItemRectSize() + ImVec2(1.f, 0.f));
ImVec2{static_cast<float>(_outer_width), static_cast<float>(_outer_height)});

for (const auto& widget : _widgets)
{
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
64 changes: 64 additions & 0 deletions src/windows/ShortcutsWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "ShortcutsWindow.hpp"

#include "widgets/Table.hpp"
#include "widgets/Text.hpp"

#include <imgui.h>

#include <memory>

FLOW_UI_NAMESPACE_START

std::shared_ptr<widgets::Text> ShorcutTextBuilder(std::initializer_list<ImGuiKey> 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<widgets::Text>(text);
}

void AddShortcutText(widgets::Table& table, const std::string& name, std::initializer_list<ImGuiKey> keys,
const Colour& colour = Colour())
{
table.AddEntry(std::make_shared<widgets::Text>(name, colour));
table.AddEntry(ShorcutTextBuilder(keys));
}

auto window_shortcuts = widgets::Table("Window Shortcuts", 2);
auto graph_shortcuts = widgets::Table("Graph Shortcuts", 2);

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();

widgets::Text("Graph Shortcuts")();
ImGui::Separator();
graph_shortcuts();
}

FLOW_UI_NAMESPACE_END
Loading