fix layout designer

This commit is contained in:
2019-09-26 17:48:38 +02:00
parent e406f7964c
commit 8b179260fb
9 changed files with 27 additions and 11 deletions

View File

@@ -67,6 +67,8 @@ void App::crash_test()
void App::tick(float dt) void App::tick(float dt)
{ {
if (auto* main = layout_designer[main_id])
main->tick(dt);
if (auto* main = layout[main_id]) if (auto* main = layout[main_id])
main->tick(dt); main->tick(dt);
} }

View File

@@ -16,6 +16,7 @@ void LayoutManager::unload()
void LayoutManager::create() void LayoutManager::create()
{ {
m_layouts[const_hash("main")] = std::make_unique<Node>(); m_layouts[const_hash("main")] = std::make_unique<Node>();
m_layouts[const_hash("main")]->m_manager = this;
} }
bool LayoutManager::load(const char* path) bool LayoutManager::load(const char* path)

View File

@@ -96,6 +96,12 @@ void Node::set_manager(LayoutManager* manager)
c->set_manager(manager); c->set_manager(manager);
} }
bool Node::added_to_root()
{
auto r = root();
return r == m_manager->get(App::I->main_id);
}
kEventResult Node::on_event(Event* e) kEventResult Node::on_event(Event* e)
{ {
kEventResult ret = kEventResult::Available; kEventResult ret = kEventResult::Available;
@@ -599,7 +605,7 @@ bool Node::is_child(Node* o) const
void Node::mouse_capture() void Node::mouse_capture()
{ {
auto root = App::I->layout.get_ref("main"); auto root = m_manager->get_ref("main");
if (!root) return; if (!root) return;
auto& c = root->current_mouse_capture; auto& c = root->current_mouse_capture;
@@ -644,7 +650,7 @@ void Node::mouse_release()
if (!m_parent) if (!m_parent)
return; return;
auto root = App::I->layout.get_ref("main"); auto root = m_manager->get_ref("main");
if (!root) return; if (!root) return;
auto& c = root->current_mouse_capture; auto& c = root->current_mouse_capture;
@@ -673,7 +679,7 @@ void Node::key_capture()
if (!m_parent) if (!m_parent)
return; return;
auto root = App::I->layout.get_ref("main"); auto root = m_manager->get_ref("main");
if (!root) return; if (!root) return;
root->current_key_capture = shared_from_this(); root->current_key_capture = shared_from_this();
@@ -682,7 +688,7 @@ void Node::key_capture()
void Node::key_release() void Node::key_release()
{ {
auto root = App::I->layout.get_ref("main"); auto root = m_manager->get_ref("main");
if (!root) return; if (!root) return;
if (root->current_key_capture.get() == this) if (root->current_key_capture.get() == this)

View File

@@ -208,6 +208,7 @@ public:
virtual void destroy(); virtual void destroy();
Node* root(); Node* root();
void set_manager(LayoutManager* manager); void set_manager(LayoutManager* manager);
bool added_to_root();
template<class T = Node> std::shared_ptr<T> clone() template<class T = Node> std::shared_ptr<T> clone()
{ {

View File

@@ -82,5 +82,6 @@ void NodeDialogExportPPBR::open_header()
void NodeDialogExportPPBR::added(Node* parent) void NodeDialogExportPPBR::added(Node* parent)
{ {
NodeBorder::added(parent); NodeBorder::added(parent);
mouse_capture(); if (added_to_root())
mouse_capture();
} }

View File

@@ -152,7 +152,7 @@ void NodeImage::load_url(const std::string& url)
m_remote_texture->create_mipmaps(); m_remote_texture->create_mipmaps();
delete rgba; delete rgba;
if (m_autosize) if (m_autosize)
SetAspectRatio(w / h); SetAspectRatio((float)w / (float)h);
} }
m_remote_asset.reset(); m_remote_asset.reset();
} }
@@ -162,6 +162,6 @@ void NodeImage::load_url(const std::string& url)
void NodeImage::added(Node* parent) void NodeImage::added(Node* parent)
{ {
Node::added(parent); Node::added(parent);
if (!m_url.empty() && root() == App::I->layout.get(App::I->main_id)) if (!m_url.empty() && added_to_root())
load_url(m_url); load_url(m_url);
} }

View File

@@ -52,6 +52,9 @@ kEventResult NodeInputBox::handle_event(Event* e)
void NodeInputBox::added(Node* parent) void NodeInputBox::added(Node* parent)
{ {
Node::added(parent); Node::added(parent);
mouse_capture(); if (added_to_root())
m_field_text->key_capture(); {
mouse_capture();
m_field_text->key_capture();
}
} }

View File

@@ -51,5 +51,6 @@ kEventResult NodeMessageBox::handle_event(Event* e)
void NodeMessageBox::added(Node* parent) void NodeMessageBox::added(Node* parent)
{ {
Node::added(parent); Node::added(parent);
mouse_capture(); if (added_to_root())
mouse_capture();
} }

View File

@@ -37,5 +37,6 @@ void NodeProgressBar::set_progress(float p) noexcept
void NodeProgressBar::added(Node* parent) void NodeProgressBar::added(Node* parent)
{ {
NodeBorder::added(parent); NodeBorder::added(parent);
mouse_capture(); if (added_to_root())
mouse_capture();
} }