completing refactoring, something does not work on resize

This commit is contained in:
2017-02-02 00:43:23 +00:00
parent 70792669e7
commit bcf95d5432
4 changed files with 42 additions and 32 deletions

View File

@@ -9,7 +9,7 @@ void Node::update(float width, float height)
YGNodeStyleSetWidth(y_node, width);
YGNodeStyleSetHeight(y_node, height);
YGNodeCalculateLayout(y_node, YGUndefined, YGUndefined, YGDirectionLTR);
glm::mat4 proj = glm::ortho(0.f, m_size.x, m_size.y, 0.f, -1.f, 1.f);
glm::mat4 proj = glm::ortho(0.f, width, height, 0.f, -1.f, 1.f);
update_internal({ 0, 0 }, proj);
}
@@ -218,7 +218,7 @@ bool LayoutManager::load(const char* path)
m_file_info = tmp_info;
m_path = path;
m_layouts.clear();
auto old = std::move(m_layouts);
tinyxml2::XMLDocument xml;
auto ret = xml.LoadFile(path);
@@ -235,11 +235,18 @@ bool LayoutManager::load(const char* path)
return false;
}
uint16_t id = const_hash(id_str);
auto p = m_layouts.try_emplace(id);
auto& p = m_layouts.try_emplace(id);
if (p.second)
{
auto& node = p.first->second;
node.load_internal(current);
// try to copy the old size values
if (old.count(id))
{
const auto& old_node = old[id];
YGNodeCopyStyle(node.y_node, old_node.y_node);
}
if (!current->NoChildren())
node.load_internal(current->FirstChildElement());
}
else
{
@@ -247,14 +254,13 @@ bool LayoutManager::load(const char* path)
}
current = current->NextSiblingElement("layout");
}
return true;
}
void LayoutManager::reload()
bool LayoutManager::reload()
{
// float w = YGNodeLayoutGetWidth(y_node);
// float h = YGNodeLayoutGetHeight(y_node);
// // avoid conflict when assigning the same string from c_str
// std::string path_copy = m_path;
// load(path_copy.c_str());
// update(w, h);
// avoid conflict when assigning the same string from c_str
std::string path_copy = m_path;
return load(path_copy.c_str());
}