neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_element.hpp
Go to the documentation of this file.
1// i_element.hpp
2/*
3 neoGFX Design Studio
4 Copyright(C) 2020 Leigh Johnston
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <neolib/neolib.hpp>
33
35{
36 class i_project;
37
39 {
40 public:
41 virtual void start_drag(cardinal aPart, point const& aPosition) = 0;
42 virtual void drag(point const& aPosition, bool aIgnoreConstraints) = 0;
43 virtual void end_drag() = 0;
44 };
45
46 enum class element_group : uint32_t
47 {
48 Unknown,
50 Project,
52 Code,
53 Script,
54 Node,
55 App,
56 Menu,
57 Action,
58 Widget,
59 Layout,
61 };
62
63 class i_element_library;
64
65 enum class element_mode
66 {
67 None,
68 Drag,
69 Edit
70 };
71
73 {
74 public:
75 declare_event(mode_changed)
76 declare_event(selection_changed)
78 public:
80 public:
82 public:
83 struct no_parent : std::logic_error { no_parent() : std::logic_error{ "neogfx::DesignStudio::i_element::no_parent" } {} };
84 struct no_layout_item : std::logic_error { no_layout_item() : std::logic_error{ "neogfx::DesignStudio::i_element::no_layout_item" } {} };
85 struct no_caddy : std::logic_error { no_caddy() : std::logic_error{ "neogfx::DesignStudio::i_element::no_caddy" } {} };
86 public:
87 virtual i_element_library const& library() const = 0;
88 virtual i_project& project() const = 0;
89 virtual element_group group() const = 0;
90 virtual neolib::i_string const& type() const = 0;
91 virtual neolib::i_string const& id() const = 0;
92 public:
93 virtual i_element const& root() const = 0;
94 virtual i_element& root() = 0;
95 virtual bool has_parent() const = 0;
96 virtual i_element const& parent() const = 0;
97 virtual i_element& parent() = 0;
98 virtual void set_parent(i_element& aParent) = 0;
99 virtual children_t const& children() const = 0;
100 virtual children_t& children() = 0;
101 virtual void add_child(i_element& aChild) = 0;
102 virtual void remove_child(i_element& aChild) = 0;
103 public:
104 virtual void create_default_children() = 0;
105 public:
106 virtual bool needs_caddy() const = 0;
107 virtual bool has_caddy() const = 0;
108 virtual i_element_caddy& caddy() const = 0;
109 virtual void set_caddy(i_element_caddy& aCaddy) = 0;
110 virtual bool has_layout_item() const = 0;
111 virtual void create_layout_item(i_widget& aParent) = 0;
112 virtual i_layout_item& layout_item() const = 0;
113 public:
114 virtual element_mode mode() const = 0;
115 virtual void set_mode(element_mode aMode) = 0;
116 virtual bool is_selected() const = 0;
117 virtual void select(bool aSelected = true, bool aDeselectRest = true) = 0;
118 public:
123 public:
124 bool is_root() const
125 {
126 return !has_parent();
127 }
128 std::size_t selected_child_count() const
129 {
130 std::size_t result = 0;
131 for (auto& child : children())
132 child->visit([&](i_element& aChild) { if (aChild.is_selected()) ++result; });
133 return result;
134 }
135 void visit(std::function<void(i_element&)> aVisitor)
136 {
137 aVisitor(*this);
138 for (auto& child : children())
139 child->visit(aVisitor);
140 }
141 void reverse_visit(std::function<void(i_element&)> aVisitor)
142 {
143 for (auto iterChild = children().rbegin(); iterChild != children().rend(); ++iterChild)
144 (*iterChild)->visit(aVisitor);
145 aVisitor(*this);
146 }
147 public:
148 bool has_widget() const
149 {
150 return has_layout_item() && layout_item().is_widget();
151 }
153 {
154 return layout_item().as_widget();
155 }
156 };
157
158 template <typename T>
160 {
162 static constexpr bool needsCaddy = true;
163 };
164
165 template <typename Type>
166 inline void create_default_children(i_element& aParent)
167 {
168 // specialize
169 }
170}
virtual void start_drag(cardinal aPart, point const &aPosition)=0
virtual void drag(point const &aPosition, bool aIgnoreConstraints)=0
virtual i_element_caddy & caddy() const =0
virtual void remove_child(i_element &aChild)=0
virtual i_layout_item & layout_item() const =0
virtual children_t const & children() const =0
children_t::const_iterator end() const
virtual i_project & project() const =0
virtual bool has_parent() const =0
virtual i_element const & parent() const =0
virtual neolib::i_string const & id() const =0
virtual void set_mode(element_mode aMode)=0
virtual void add_child(i_element &aChild)=0
virtual neolib::i_string const & type() const =0
virtual element_group group() const =0
virtual bool has_layout_item() const =0
virtual void create_layout_item(i_widget &aParent)=0
void reverse_visit(std::function< void(i_element &)> aVisitor)
std::size_t selected_child_count() const
virtual i_element_library const & library() const =0
virtual i_element & root()=0
neolib::i_vector< i_ref_ptr< i_element > > children_t
Definition i_element.hpp:81
virtual i_element & parent()=0
virtual bool is_selected() const =0
void visit(std::function< void(i_element &)> aVisitor)
children_t::iterator end()
children_t::iterator begin()
virtual children_t & children()=0
virtual void set_caddy(i_element_caddy &aCaddy)=0
declare_event(mode_changed) declare_event(selection_changed) declare_event(context_menu
children_t::const_iterator begin() const
virtual void select(bool aSelected=true, bool aDeselectRest=true)=0
virtual void create_default_children()=0
virtual bool needs_caddy() const =0
virtual void set_parent(i_element &aParent)=0
virtual i_element const & root() const =0
virtual element_mode mode() const =0
virtual bool has_caddy() const =0
virtual const i_widget & as_widget() const =0
virtual bool is_widget() const =0
offset_iterator< value_type > iterator
offset_iterator< const value_type > const_iterator
void create_default_children(i_element &aParent)
#define declare_event(declName,...)
Definition i_event.hpp:305