completing refactoring, something does not work on resize
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<layout id="button">
|
||||
|
||||
</layout>
|
||||
<layout id="main">
|
||||
<node dir="col" wrap="0" width="100%" height="100%" pad="5">
|
||||
<!-- toolbar -->
|
||||
|
||||
@@ -5,7 +5,7 @@ App App::I; // singleton
|
||||
|
||||
void App::create()
|
||||
{
|
||||
width = 500;
|
||||
width = 800;
|
||||
height = 500;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ void App::init()
|
||||
#endif
|
||||
|
||||
layout.load("data/layout.xml");
|
||||
//layout.update(width, height);
|
||||
layout["main"].update(width, height);
|
||||
|
||||
sampler.create();
|
||||
ShaderManager::create(kShader::Texture, shader_v, shader_f);
|
||||
@@ -109,11 +109,16 @@ void App::init()
|
||||
|
||||
void App::update(float dt)
|
||||
{
|
||||
constexpr auto main_id = const_hash("main");
|
||||
|
||||
glClearColor(.1f, .1f, .1f, 1.f);
|
||||
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
layout.reload();
|
||||
if (layout.reload())
|
||||
{
|
||||
layout[main_id].update(width, height);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
tex.bind();
|
||||
@@ -122,17 +127,16 @@ void App::update(float dt)
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
// for (auto& n : layout)
|
||||
// {
|
||||
//
|
||||
// if (n.m_widget)
|
||||
// {
|
||||
// auto box = n.m_widget->clip;
|
||||
// glScissor(box.x, height - box.y - box.w, box.z, box.w);
|
||||
// n.m_widget->draw();
|
||||
// }
|
||||
// }
|
||||
//glEnable(GL_SCISSOR_TEST);
|
||||
for (auto& n : layout[main_id])
|
||||
{
|
||||
if (n.m_widget)
|
||||
{
|
||||
auto box = n.m_widget->clip;
|
||||
glScissor(box.x, height - box.y - box.w, box.z, box.w);
|
||||
n.m_widget->draw();
|
||||
}
|
||||
}
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
tex.unbind();
|
||||
sampler.unbind();
|
||||
@@ -140,9 +144,8 @@ void App::update(float dt)
|
||||
|
||||
void App::resize(float w, float h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
// layout.update(width, height);
|
||||
constexpr auto main_id = const_hash("main");
|
||||
layout[main_id].update(w, h);
|
||||
}
|
||||
|
||||
void App::mouse_down(int button, float x, float y)
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -182,6 +182,8 @@ public:
|
||||
|
||||
class Node
|
||||
{
|
||||
friend class LayoutManager;
|
||||
|
||||
const Node* parent{ nullptr };
|
||||
YGNodeRef y_node{ nullptr };
|
||||
|
||||
@@ -293,5 +295,7 @@ class LayoutManager
|
||||
struct stat m_file_info { 0 };
|
||||
public:
|
||||
bool load(const char* path);
|
||||
void reload();
|
||||
bool reload();
|
||||
Node& operator[](uint16_t id) { return m_layouts[id]; }
|
||||
Node& operator[](const char* ids) { return m_layouts[const_hash(ids)]; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user