Skip to content

Commit

Permalink
Merge branch 'Areas-and-comments-part-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
qoala101 committed Jul 6, 2023
2 parents 119a13d + 415a3b3 commit 0a3e439
Show file tree
Hide file tree
Showing 47 changed files with 824 additions and 280 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(
"ponc"
VERSION 0.5.2
VERSION 0.5.3
LANGUAGES CXX
)

Expand Down
5 changes: 4 additions & 1 deletion include/core/core_area.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
namespace ne = ax::NodeEditor;

namespace vh::ponc::core {
///
using AreaId = ne::NodeId;

///
struct Area {
///
ne::NodeId id{};
AreaId id{};
///
std::string name{};
///
Expand Down
9 changes: 5 additions & 4 deletions include/core/core_diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Diagram {
///
explicit Diagram(std::string name = {},
std::vector<std::unique_ptr<INode>> nodes = {},
std::vector<Link> links = {});
std::vector<Link> links = {}, std::vector<Area> areas = {});

///
static auto GetIds(Diagram &diagram) -> std::vector<IdPtr>;
Expand All @@ -45,8 +45,9 @@ class Diagram {
///
static auto HasLink(const Diagram &diagram, ne::PinId pin_id) -> bool;
///
static auto FindArea(const Diagram &diagram, ne::NodeId node_id)
-> const Area &;
static auto FindArea(const Diagram &diagram, AreaId area_id) -> const Area &;
///
static auto FindArea(Diagram &diagram, AreaId area_id) -> Area &;

///
auto GetName() const -> const std::string &;
Expand All @@ -71,7 +72,7 @@ class Diagram {
///
auto EmplaceArea(const Area &area) -> Area &;
///
void DeleteArea(ne::NodeId node_id);
void DeleteArea(AreaId area_id);

private:
///
Expand Down
62 changes: 62 additions & 0 deletions include/coreui/coreui_area_creator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* PONC @link https://github.com/qoala101/ponc @endlink
* @author Volodymyr Hromakov (4y5t6r@gmail.com)
* @copyright Copyright (c) 2023, MIT License
*/

#ifndef VH_PONC_COREUI_AREA_CREATOR_H_
#define VH_PONC_COREUI_AREA_CREATOR_H_

#include <imgui.h>
#include <imgui_node_editor.h>

#include <optional>

#include "core_area.h"
#include "core_id_generator.h"
#include "coreui_event.h"
#include "cpp_safe_ptr.h"

namespace vh::ponc::coreui {
///
class Diagram;

///
class AreaCreator {
public:
///
AreaCreator(cpp::SafePtr<Diagram> parent_diagram,
cpp::SafePtr<core::IdGenerator> id_generator);

///
auto IsCreating() const -> bool;
///
auto StartCreateAreaAt(const ImVec2 &start_pos) -> Event &;
///
void ResizeAreaTo(const ImVec2 &pos);
///
void AcceptCreateArea();
///
auto DiscardCreateArea() -> Event &;

private:
///
struct Area {
///
core::AreaId id{};
///
ImVec2 start_pos{};
};

///
cpp::SafePtr<Diagram> parent_diagram_;
///
cpp::SafePtr<core::IdGenerator> id_generator_;
///
cpp::SafeOwner safe_owner_{};
///
std::optional<Area> area_{};
};
} // namespace vh::ponc::coreui

#endif // VH_PONC_COREUI_AREA_CREATOR_H_
11 changes: 8 additions & 3 deletions include/coreui/coreui_diagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
#include <imgui_node_editor.h>

#include <memory>
#include <string>
#include <vector>

#include "core_area.h"
#include "core_diagram.h"
#include "core_i_family.h"
#include "core_i_node.h"
#include "core_link.h"
#include "coreui_area_creator.h"
#include "coreui_event.h"
#include "coreui_family.h"
#include "coreui_flow_tree_node.h"
Expand Down Expand Up @@ -64,6 +65,8 @@ class Diagram {
///
auto GetLinker() -> Linker &;
///
auto GetAreaCreator() -> AreaCreator &;
///
auto GetFamilyGroups() const -> const std::vector<FamilyGroup> &;
///
auto GetNodes() const -> const std::vector<Node> &;
Expand Down Expand Up @@ -92,9 +95,9 @@ class Diagram {
///
auto GetNodeTrees() const -> const std::vector<TreeNode> &;
///
auto CreateArea(std::string name, const ImVec2 &pos) -> Event &;
auto AddArea(const core::Area &area) -> Event &;
///
auto DeleteArea(ne::NodeId node_id) -> Event &;
auto DeleteArea(core::AreaId area_id) -> Event &;

private:
///
Expand Down Expand Up @@ -151,6 +154,8 @@ class Diagram {
///
Linker linker_;
///
AreaCreator area_creator_;
///
std::vector<FamilyGroup> family_groups_{};
///
std::vector<Node> nodes_{};
Expand Down
8 changes: 7 additions & 1 deletion include/coreui/coreui_native_facade.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
#ifndef VH_PONC_COREUI_NATIVE_FACADE_H_
#define VH_PONC_COREUI_NATIVE_FACADE_H_

#include <imgui.h>
#include <imgui_node_editor.h>

#include <utility>
#include <vector>

#include "core_area.h"
#include "cpp_static_api.h"

namespace ne = ax::NodeEditor;

namespace vh::ponc::coreui {
///
struct NativeFacade : public cpp::StaticApi {
///
static auto IsArea(ne::NodeId node_id) -> bool;
///
static auto GetAreaSize(core::AreaId area_id) -> ImVec2;
///
static auto GetSelectedNodes() -> std::vector<ne::NodeId>;
///
static auto GetSelectedNodesAndAreas()
-> std::pair<std::vector<ne::NodeId>, std::vector<ne::NodeId>>;
-> std::pair<std::vector<ne::NodeId>, std::vector<core::AreaId>>;
///
static auto GetSelectedLinks() -> std::vector<ne::LinkId>;
///
Expand Down
9 changes: 7 additions & 2 deletions include/coreui/coreui_node_mover.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <unordered_set>
#include <vector>

#include "core_area.h"
#include "core_i_node.h"
#include "core_id_value.h"
#include "core_settings.h"
Expand All @@ -36,6 +37,9 @@ class NodeMover {
///
void MoveNodeTo(ne::NodeId node_id, const ImVec2 &pos);
///
void MoveAreaTo(core::AreaId area_id, const ImVec2 &start_pos,
const ImVec2 &end_pos);
///
void ArrangeVerticallyAt(const std::vector<ne::NodeId> &node_ids,
const ImVec2 &pos);
///
Expand Down Expand Up @@ -65,7 +69,7 @@ class NodeMover {
///
void MarkNodeToMove(ne::NodeId node_id);
///
void MarkAreaToMove(ne::NodeId node_id);
void MarkAreaToMove(core::AreaId area_id);
///
void MarkNewItemsToMove();
///
Expand Down Expand Up @@ -108,8 +112,9 @@ class NodeMover {
///
std::unordered_set<core::IdValue<ne::NodeId>> nodes_to_move_{};
///
std::unordered_set<core::IdValue<ne::NodeId>> areas_to_move_{};
std::unordered_set<core::IdValue<core::AreaId>> areas_to_move_{};
///
// TODO(vh): Those are never cleared.
std::unordered_map<core::IdValue<ne::NodeId>, ImVec2> item_sizes_{};
///
std::unordered_map<core::IdValue<ne::PinId>, ImVec2> pin_poses_{};
Expand Down
30 changes: 30 additions & 0 deletions include/draw/diagram/draw_area_creator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* PONC @link https://github.com/qoala101/ponc @endlink
* @author Volodymyr Hromakov (4y5t6r@gmail.com)
* @copyright Copyright (c) 2023, MIT License
*/

#ifndef VH_PONC_DRAW_AREA_CREATOR_H_
#define VH_PONC_DRAW_AREA_CREATOR_H_

#include "coreui_area_creator.h"

namespace vh::ponc::draw {
///
class AreaCreator {
public:
///
void Draw(coreui::AreaCreator &area_creator);

private:
///
void Reset();

///
bool right_mouse_clicked_{};
///
bool right_mouse_dragged_{};
};
} // namespace vh::ponc::draw

#endif // VH_PONC_DRAW_AREA_CREATOR_H_
3 changes: 3 additions & 0 deletions include/draw/diagram/draw_diagram_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "core_diagram.h"
#include "coreui_diagram.h"
#include "draw_area_creator.h"
#include "draw_background_popup.h"
#include "draw_item_deleter.h"
#include "draw_link_popup.h"
Expand Down Expand Up @@ -45,6 +46,8 @@ class DiagramEditor {
///
Linker linker_{};
///
AreaCreator area_creator_{};
///
BackgroundPopup background_popup_{};
///
NodePopup node_popup_{};
Expand Down
37 changes: 37 additions & 0 deletions include/draw/diagram/popup/draw_area_popup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* PONC @link https://github.com/qoala101/ponc @endlink
* @author Volodymyr Hromakov (4y5t6r@gmail.com)
* @copyright Copyright (c) 2023, MIT License
*/

#ifndef VH_PONC_DRAW_AREA_POPUP_H_
#define VH_PONC_DRAW_AREA_POPUP_H_

#include <vector>

#include "core_area.h"
#include "coreui_diagram.h"
#include "cpp_callbacks.h"
#include "draw_string_buffer.h"

namespace vh::ponc::draw {
///
class AreaPopup {
public:
///
struct Callbacks {
///
cpp::Query<bool> was_just_opened{};
};

///
void Draw(const std::vector<core::AreaId> &selected_areas,
coreui::Diagram &diagram, const Callbacks &callbacks);

private:
///
StringBuffer rename_buffer_{};
};
} // namespace vh::ponc::draw

#endif // VH_PONC_DRAW_AREA_POPUP_H_
6 changes: 0 additions & 6 deletions include/draw/diagram/popup/draw_background_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "coreui_diagram.h"
#include "draw_i_popup.h"
#include "draw_string_buffer.h"

namespace vh::ponc::draw {
///
Expand All @@ -23,13 +22,8 @@ class BackgroundPopup : public IPopup {
void SetPos(const ImVec2 &pos);

private:
auto DrawRenamePopup();

///
ImVec2 pos_{};

StringBuffer area_name_buffer_{};
bool focus_name_input_{};
};
} // namespace vh::ponc::draw

Expand Down
5 changes: 5 additions & 0 deletions include/draw/diagram/popup/draw_node_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define VH_PONC_DRAW_NODE_POPUP_H_

#include "coreui_diagram.h"
#include "draw_area_popup.h"
#include "draw_i_popup.h"

namespace vh::ponc::draw {
Expand All @@ -16,6 +17,10 @@ class NodePopup : public IPopup {
public:
///
void Draw(coreui::Diagram &diagram);

private:
///
AreaPopup area_popup_{};
};
} // namespace vh::ponc::draw

Expand Down
20 changes: 20 additions & 0 deletions include/draw/draw_rename_widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* PONC @link https://github.com/qoala101/ponc @endlink
* @author Volodymyr Hromakov (4y5t6r@gmail.com)
* @copyright Copyright (c) 2023, MIT License
*/

#ifndef VH_PONC_DRAW_RENAME_WIDGET_H_
#define VH_PONC_DRAW_RENAME_WIDGET_H_

#include <string_view>

#include "draw_string_buffer.h"

namespace vh::ponc::draw {
///
auto DrawRenameWidget(std::string_view label, StringBuffer &name_buffer)
-> bool;
} // namespace vh::ponc::draw

#endif // VH_PONC_DRAW_RENAME_WIDGET_H_
Loading

0 comments on commit 0a3e439

Please sign in to comment.