This commit is contained in:
2019-08-28 10:00:35 +02:00
parent c1bd377ee8
commit 62a95c1a0f
13 changed files with 122 additions and 63 deletions

View File

@@ -693,7 +693,7 @@
<slider-h id="grid-ground-offset" value="0.25"/> <slider-h id="grid-ground-offset" value="0.25"/>
</node> </node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0"> <node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-ground-resolution" width="100%" height="30" combo-list="0.1,0.5,1,2,4,8" default="2"/> <combobox id="grid-ground-resolution" width="100%" height="28" combo-list="0.1,0.5,1,2,4,8" default="2"/>
</node> </node>
</node> </node>
</node> </node>
@@ -731,7 +731,7 @@
</node> </node>
<node dir="col" align="center" grow="1" width="1" flood-events="1" color=".3" > <node dir="col" align="center" grow="1" width="1" flood-events="1" color=".3" >
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0"> <node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-shading" width="100%" height="30" combo-list="Transparent,Flat,Solid,Textured" default="0"/> <combobox id="grid-heightmap-shading" width="100%" height="28" combo-list="Transparent,Flat,Solid,Textured" default="0"/>
</node> </node>
<node height="20" pad="1" width="100%" margin="5 0 0 0"> <node height="20" pad="1" width="100%" margin="5 0 0 0">
<slider-h id="grid-heightmap-wireframe" value="1.0"/> <slider-h id="grid-heightmap-wireframe" value="1.0"/>
@@ -753,10 +753,10 @@
<slider-h id="grid-heightmap-radius" value="0.25"/> <slider-h id="grid-heightmap-radius" value="0.25"/>
</node> </node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0"> <node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-samples" width="100%" height="30" combo-list="1,4,8,16,32,64,128" default="2"/> <combobox id="grid-heightmap-samples" width="100%" height="28" combo-list="1,4,8,16,32,64,128" default="2"/>
</node> </node>
<node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0"> <node height="30" pad="1" width="100%" dir="row" margin="5 0 0 0">
<combobox id="grid-heightmap-texres" width="100%" height="30" combo-list="256,512,1024,2048,4096" default="1"/> <combobox id="grid-heightmap-texres" width="100%" height="28" combo-list="256,512,1024,2048,4096" default="1"/>
</node> </node>
</node> </node>
</node> </node>
@@ -771,7 +771,7 @@
<!-- MESSAGE BOX --> <!-- MESSAGE BOX -->
<layout id="message-box"> <layout id="message-box">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
<border thickness="1" border-color=".2" pad="3"> <border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text id="title" text="Just a test message"></text> <text id="title" text="Just a test message"></text>
@@ -789,8 +789,8 @@
<!-- PROGRESS BAR --> <!-- PROGRESS BAR -->
<layout id="progress-bar"> <layout id="progress-bar">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center" mouse-capture="true"> <border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
<border thickness="1" border-color=".2" pad="3"> <border id="body" thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center"> <border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text id="title" text="Just a test message"></text> <text id="title" text="Just a test message"></text>
</border> </border>

View File

@@ -354,7 +354,10 @@ void App::init_sidebar()
if (grid->m_parent) if (grid->m_parent)
{ {
if (auto fp = dynamic_cast<NodePanelFloating*>(grid->m_parent->m_parent)) if (auto fp = dynamic_cast<NodePanelFloating*>(grid->m_parent->m_parent))
{
grid->remove_from_parent();
fp->destroy(); fp->destroy();
}
} }
layout[main_id]->add_child(grid); layout[main_id]->add_child(grid);
auto tick = layout[main_id]->add_child<NodeImage>(); auto tick = layout[main_id]->add_child<NodeImage>();
@@ -505,7 +508,7 @@ void App::init_menu_file()
{ {
menu_file->on_click = [=](Node*) { menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y); glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("file-menu")]->m_children[0]->clone(); auto popup = layout[const_hash("file-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update(); popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x; pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
@@ -610,7 +613,7 @@ void App::init_menu_file()
if (auto b = popup->find<NodeButtonCustom>("file-export-tick")) if (auto b = popup->find<NodeButtonCustom>("file-export-tick"))
b->on_click = [this, b, popup](Node*) { b->on_click = [this, b, popup](Node*) {
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0); glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
auto subpopup = (NodePopupMenu*)layout[const_hash("file-submenu-export")]->m_children[0]->clone(); auto subpopup = layout[const_hash("file-submenu-export")]->m_children[0]->clone<NodePopupMenu>();
subpopup->update(); subpopup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - subpopup->m_size.x + b->m_size.x; pos.x = pos.x - subpopup->m_size.x + b->m_size.x;
@@ -685,7 +688,7 @@ void App::init_menu_edit()
{ {
menu_file->on_click = [=](Node*) { menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y); glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("edit-menu")]->m_children[0]->clone(); auto popup = layout[const_hash("edit-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update(); popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x; pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
@@ -709,7 +712,7 @@ void App::init_menu_tools()
{ {
menu_exp->on_click = [this, menu_exp, main](Node*) { menu_exp->on_click = [this, menu_exp, main](Node*) {
glm::vec2 pos = menu_exp->m_pos + glm::vec2(0, menu_exp->m_size.y); glm::vec2 pos = menu_exp->m_pos + glm::vec2(0, menu_exp->m_size.y);
auto popup_exp = (NodePopupMenu*)layout[const_hash("tools-menu")]->m_children[0]->clone(); auto popup_exp = layout[const_hash("tools-menu")]->m_children[0]->clone<NodePopupMenu>();
popup_exp->update(); popup_exp->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup_exp->m_size.x + menu_exp->m_size.x; pos.x = pos.x - popup_exp->m_size.x + menu_exp->m_size.x;
@@ -727,7 +730,7 @@ void App::init_menu_tools()
if (auto menu_time = popup_exp->find<NodePopupMenu>("tools-timelapse")) if (auto menu_time = popup_exp->find<NodePopupMenu>("tools-timelapse"))
{ {
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0); glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
auto popup_time = (NodePopupMenu*)layout[const_hash("timelapse-menu")]->m_children[0]->clone(); auto popup_time = layout[const_hash("timelapse-menu")]->m_children[0]->clone<NodePopupMenu>();
popup_time->update(); popup_time->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup_time->m_size.x + b->m_size.x; pos.x = pos.x - popup_time->m_size.x + b->m_size.x;
@@ -773,7 +776,7 @@ void App::init_menu_tools()
if (auto menu_time = popup_exp->find<NodePopupMenu>("tools-panels")) if (auto menu_time = popup_exp->find<NodePopupMenu>("tools-panels"))
{ {
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0); glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
auto popup_time = (NodePopupMenu*)layout[const_hash("panels-menu")]->m_children[0]->clone(); auto popup_time = layout[const_hash("panels-menu")]->m_children[0]->clone<NodePopupMenu>();
popup_time->update(); popup_time->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup_time->m_size.x + b->m_size.x; pos.x = pos.x - popup_time->m_size.x + b->m_size.x;
@@ -1039,7 +1042,7 @@ void App::init_menu_about()
{ {
menu_file->on_click = [=](Node*) { menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y); glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("about-menu")]->m_children[0]->clone(); auto popup = layout[const_hash("about-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update(); popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x; pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;
@@ -1160,7 +1163,7 @@ void App::init_menu_layer()
{ {
menu_file->on_click = [=](Node*) { menu_file->on_click = [=](Node*) {
glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y); glm::vec2 pos = menu_file->m_pos + glm::vec2(0, menu_file->m_size.y);
auto popup = (NodePopupMenu*)layout[const_hash("layers-menu")]->m_children[0]->clone(); auto popup = layout[const_hash("layers-menu")]->m_children[0]->clone<NodePopupMenu>();
popup->update(); popup->update();
if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL) if (YGNodeStyleGetDirection(layout[main_id]->y_node) == YGDirectionRTL)
pos.x = pos.x - popup->m_size.x + menu_file->m_size.x; pos.x = pos.x - popup->m_size.x + menu_file->m_size.x;

View File

@@ -58,13 +58,22 @@ void Node::watch(std::function<bool(Node*)> observer)
void Node::destroy() void Node::destroy()
{ {
App::I->ui_task([&] m_destroyed = true;
{ mouse_release();
mouse_release(); key_release();
key_release(); // for (auto& c : m_children)
remove_all_children(); // c->destroy();
remove_from_parent(); for (auto p = m_parent; p; p = p->m_parent)
}); if (p->child_mouse_focus.get() == this)
p->child_mouse_focus = nullptr;
//App::I->ui_task([&]
//{
// auto cp = m_children;
// for (auto& c : cp)
// c->destroy();
// remove_all_children();
// remove_from_parent();
//});
} }
Node* Node::root() Node* Node::root()
@@ -78,6 +87,9 @@ Node* Node::root()
kEventResult Node::on_event(Event* e) kEventResult Node::on_event(Event* e)
{ {
kEventResult ret = kEventResult::Available; kEventResult ret = kEventResult::Available;
if (m_destroyed)
return ret;
if (current_mouse_capture && current_mouse_capture.get() != this) if (current_mouse_capture && current_mouse_capture.get() != this)
{ {
@@ -134,7 +146,7 @@ kEventResult Node::on_event(Event* e)
if (e->m_cat == kEventCategory::MouseEvent && child_mouse_focus.get() != it->get()) if (e->m_cat == kEventCategory::MouseEvent && child_mouse_focus.get() != it->get())
{ {
MouseEvent* me = static_cast<MouseEvent*>(e); MouseEvent* me = static_cast<MouseEvent*>(e);
if (child_mouse_focus) if (child_mouse_focus && !child_mouse_focus->m_destroyed)
{ {
MouseEvent e2 = *me; MouseEvent e2 = *me;
e2.m_type = kEventType::MouseUnfocus; e2.m_type = kEventType::MouseUnfocus;
@@ -144,8 +156,15 @@ kEventResult Node::on_event(Event* e)
MouseEvent e2 = *me; MouseEvent e2 = *me;
e2.m_type = kEventType::MouseFocus; e2.m_type = kEventType::MouseFocus;
(*it)->handle_event(&e2); (*it)->handle_event(&e2);
child_mouse_focus = *it; if (!(*it)->m_destroyed)
child_mouse_focus->m_mouse_focus = true; {
child_mouse_focus = *it;
child_mouse_focus->m_mouse_focus = true;
}
//else
//{
// child_mouse_focus = nullptr;
//}
} }
ret = kEventResult::Consumed; ret = kEventResult::Consumed;
break; break;
@@ -295,7 +314,9 @@ void Node::added(Node* parent)
void Node::removed(Node* parent) void Node::removed(Node* parent)
{ {
for (auto p = m_parent; p; p = p->m_parent)
if (p->child_mouse_focus.get() == this)
p->child_mouse_focus = nullptr;
} }
const Node* Node::init_template(const char* id) const Node* Node::init_template(const char* id)
@@ -329,6 +350,7 @@ void Node::add_child(Node* n)
m_children.emplace_back(n); m_children.emplace_back(n);
n->m_parent = this; n->m_parent = this;
n->m_manager = m_manager; n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node)); YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->added(this); n->added(this);
on_child_added(n); on_child_added(n);
@@ -344,6 +366,7 @@ void Node::add_child(Node* n, int index)
m_children.emplace_back(n); m_children.emplace_back(n);
n->m_parent = this; n->m_parent = this;
n->m_manager = m_manager; n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, index); YGNodeInsertChild(y_node, n->y_node, index);
n->added(this); n->added(this);
on_child_added(n); on_child_added(n);
@@ -359,6 +382,7 @@ void Node::add_child(std::shared_ptr<Node> n)
m_children.push_back(n); m_children.push_back(n);
n->m_parent = this; n->m_parent = this;
n->m_manager = m_manager; n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node)); YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->added(this); n->added(this);
on_child_added(n.get()); on_child_added(n.get());
@@ -374,6 +398,7 @@ void Node::add_child(std::shared_ptr<Node> n, int index)
m_children.insert(m_children.begin() + index, n); m_children.insert(m_children.begin() + index, n);
n->m_parent = this; n->m_parent = this;
n->m_manager = m_manager; n->m_manager = m_manager;
n->m_destroyed = false;
YGNodeInsertChild(y_node, n->y_node, index); YGNodeInsertChild(y_node, n->y_node, index);
n->added(this); n->added(this);
on_child_added(n.get()); on_child_added(n.get());
@@ -663,6 +688,7 @@ Node::Node(Node&& o)
m_pos_offset_childred = o.m_pos_offset_childred; m_pos_offset_childred = o.m_pos_offset_childred;
m_clip_uncut = o.m_clip_uncut; m_clip_uncut = o.m_clip_uncut;
m_destroyed = o.m_destroyed;
} }
Node::~Node() Node::~Node()
@@ -1015,6 +1041,9 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj, float
for (auto& c : m_children) for (auto& c : m_children)
c->update_internal(m_pos, proj, zoom); c->update_internal(m_pos, proj, zoom);
m_children.erase(std::remove_if(m_children.begin(), m_children.end(),
[](const auto& n) { return n->m_destroyed; }), m_children.end());
} }
void Node::tick(float dt) void Node::tick(float dt)
@@ -1320,15 +1349,6 @@ void Node::draw()
} }
Node* Node::clone()
{
Node* n = clone_instantiate();
clone_copy(n);
clone_children(n);
clone_finalize(n);
return n;
}
Node* Node::clone_instantiate() const Node* Node::clone_instantiate() const
{ {
return new Node(); return new Node();
@@ -1363,14 +1383,16 @@ void Node::clone_copy(Node* dest) const
dest->m_pos_offset = m_pos_offset; dest->m_pos_offset = m_pos_offset;
dest->m_pos_offset_childred = m_pos_offset_childred; dest->m_pos_offset_childred = m_pos_offset_childred;
dest->m_clip_uncut = m_clip_uncut; dest->m_clip_uncut = m_clip_uncut;
dest->m_destroyed = m_destroyed;
} }
void Node::clone_children(Node* dest) const void Node::clone_children(Node* dest) const
{ {
for (auto& c : m_children) for (auto& c : m_children)
{ {
Node* cn = c->clone(); std::shared_ptr<Node> cn = c->clone();
dest->m_children.emplace_back(cn); dest->m_children.push_back(cn);
cn->m_parent = dest; cn->m_parent = dest;
cn->m_manager = dest->m_manager; cn->m_manager = dest->m_manager;
cn->loaded(); cn->loaded();

View File

@@ -135,6 +135,8 @@ public:
// it's actually rendering // it's actually rendering
bool m_on_screen = false; bool m_on_screen = false;
bool m_destroyed = false;
Node(const Node&) = delete; Node(const Node&) = delete;
Node& operator=(const Node&) = delete; Node& operator=(const Node&) = delete;
Node&& operator=(Node&& o); Node&& operator=(Node&& o);
@@ -194,7 +196,6 @@ public:
virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr); virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr);
void load_internal(const tinyxml2::XMLElement* x_node); void load_internal(const tinyxml2::XMLElement* x_node);
virtual void draw(); virtual void draw();
Node* clone();
virtual Node* clone_instantiate() const; virtual Node* clone_instantiate() const;
virtual void clone_copy(Node* dest) const; virtual void clone_copy(Node* dest) const;
virtual void clone_children(Node* dest) const; virtual void clone_children(Node* dest) const;
@@ -203,6 +204,16 @@ public:
virtual void destroy(); virtual void destroy();
Node* root(); Node* root();
template<class T = Node> std::shared_ptr<T> clone()
{
std::shared_ptr<T> n = std::shared_ptr<T>((T*)clone_instantiate());
clone_copy(n.get());
clone_children(n.get());
clone_finalize(n.get());
return n;
}
template<class T = Node> T* find(const char* ids) template<class T = Node> T* find(const char* ids)
{ {
uint16_t id = const_hash(ids); uint16_t id = const_hash(ids);

View File

@@ -8,19 +8,29 @@ Node* NodeAbout::clone_instantiate() const
return new NodeAbout(); return new NodeAbout();
} }
void NodeAbout::clone_finalize(Node* dest) const
{
NodeAbout* n = static_cast<NodeAbout*>(dest);
n->init_controls();
}
void NodeAbout::init() void NodeAbout::init()
{ {
SetPosition(0, 0); init_template("about");
SetWidthP(100); init_controls();
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("about")]->m_children[0]->clone();
add_child(m_template);
btn_ok = m_template->find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
} }
kEventResult NodeAbout::handle_event(Event* e) kEventResult NodeAbout::handle_event(Event* e)
{ {
return kEventResult::Consumed; return kEventResult::Consumed;
} }
void NodeAbout::init_controls()
{
SetPosition(0, 0);
SetWidthP(100);
SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute);
btn_ok = find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
}

View File

@@ -4,10 +4,11 @@
class NodeAbout : public Node class NodeAbout : public Node
{ {
Node* m_template;
NodeButton* btn_ok; NodeButton* btn_ok;
public: public:
virtual Node* clone_instantiate() const override; virtual Node* clone_instantiate() const override;
virtual void init() override; virtual void init() override;
virtual kEventResult handle_event(Event* e) override; virtual kEventResult handle_event(Event* e) override;
virtual void clone_finalize(Node* dest) const override;
void init_controls();
}; };

View File

@@ -10,13 +10,13 @@ Node* NodeChangelog::clone_instantiate() const
void NodeChangelog::init() void NodeChangelog::init()
{ {
init_template("changelog");
SetPosition(0, 0); SetPosition(0, 0);
SetWidthP(100); SetWidthP(100);
SetHeightP(100); SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute); SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("changelog")]->m_children[0]->clone(); btn_ok = find<NodeButton>("btn-ok");
add_child(m_template);
btn_ok = m_template->find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); }; btn_ok->on_click = [&](Node*) { destroy(); };
} }

View File

@@ -45,6 +45,7 @@ void NodeDialogCloud::loaded()
void NodeDialogCloud::removed(Node* parent) void NodeDialogCloud::removed(Node* parent)
{ {
NodeBorder::removed(parent);
closed = true; closed = true;
} }

View File

@@ -10,17 +10,17 @@ Node* NodeMessageBox::clone_instantiate() const
void NodeMessageBox::init() void NodeMessageBox::init()
{ {
init_template("message-box");
SetPosition(0, 0); SetPosition(0, 0);
SetWidthP(100); SetWidthP(100);
SetHeightP(100); SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute); SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("message-box")]->m_children[0]->clone(); m_title = find<NodeText>("title");
add_child(m_template); m_message = find<NodeText>("message");
m_title = m_template->find<NodeText>("title"); btn_ok = find<NodeButton>("btn-ok");
m_message = m_template->find<NodeText>("message");
btn_ok = m_template->find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); }; btn_ok->on_click = [&](Node*) { destroy(); };
btn_cancel = m_template->find<NodeButton>("btn-cancel"); btn_cancel = find<NodeButton>("btn-cancel");
on_submit = btn_cancel->on_click = [&](Node*) { destroy(); }; on_submit = btn_cancel->on_click = [&](Node*) { destroy(); };
m_capture_children = false; // don't capture children events on mouse_capture m_capture_children = false; // don't capture children events on mouse_capture
} }

View File

@@ -19,6 +19,7 @@ void NodeProgressBar::init()
btn_cancel = find<NodeButton>("btn-cancel"); btn_cancel = find<NodeButton>("btn-cancel");
btn_cancel->on_click = [&](Node*) { destroy(); }; btn_cancel->on_click = [&](Node*) { destroy(); };
m_progress = find<NodeBorder>("progress"); m_progress = find<NodeBorder>("progress");
m_body = find<NodeBorder>("body");
m_progress->SetWidthP(0); m_progress->SetWidthP(0);
} }
@@ -34,3 +35,9 @@ void NodeProgressBar::set_progress(float p) noexcept
{ {
m_progress->SetWidthP(p * 100.f); m_progress->SetWidthP(p * 100.f);
} }
void NodeProgressBar::added(Node* parent)
{
NodeBorder::added(parent);
m_body->mouse_capture();
}

View File

@@ -11,6 +11,7 @@ public:
NodeButton* btn_cancel; NodeButton* btn_cancel;
NodeText* m_title; NodeText* m_title;
NodeBorder* m_progress; NodeBorder* m_progress;
NodeBorder* m_body;
int m_total = 0; int m_total = 0;
int m_count = 0; int m_count = 0;
virtual Node* clone_instantiate() const override; virtual Node* clone_instantiate() const override;
@@ -18,4 +19,5 @@ public:
void increment() noexcept; void increment() noexcept;
// set progress where p [0, 1] // set progress where p [0, 1]
void set_progress(float p) noexcept; void set_progress(float p) noexcept;
virtual void added(Node* parent) override;
}; };

View File

@@ -10,13 +10,13 @@ Node* NodeSettings::clone_instantiate() const
void NodeSettings::init() void NodeSettings::init()
{ {
init_template("settings");
SetPosition(0, 0); SetPosition(0, 0);
SetWidthP(100); SetWidthP(100);
SetHeightP(100); SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute); SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("settings")]->m_children[0]->clone(); btnOk = find<NodeButton>("btn-ok");
add_child(m_template);
btnOk = m_template->find<NodeButton>("btn-ok");
btnOk->on_click = [&](Node*) { destroy(); }; btnOk->on_click = [&](Node*) { destroy(); };
} }

View File

@@ -10,14 +10,16 @@ Node* NodeUserManual::clone_instantiate() const
void NodeUserManual::init() void NodeUserManual::init()
{ {
init_template("usermanual");
SetPosition(0, 0); SetPosition(0, 0);
SetWidthP(100); SetWidthP(100);
SetHeightP(100); SetHeightP(100);
SetPositioning(YGPositionTypeAbsolute); SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("usermanual")]->m_children[0]->clone(); btn_ok = find<NodeButton>("btn-ok");
add_child(m_template); btn_ok->on_click = [&](Node*) {
btn_ok = m_template->find<NodeButton>("btn-ok"); destroy();
btn_ok->on_click = [&](Node*) { destroy(); }; };
} }
kEventResult NodeUserManual::handle_event(Event* e) kEventResult NodeUserManual::handle_event(Event* e)