completing refactoring, something does not work on resize
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<layout id="button">
|
|
||||||
|
|
||||||
</layout>
|
|
||||||
<layout id="main">
|
<layout id="main">
|
||||||
<node dir="col" wrap="0" width="100%" height="100%" pad="5">
|
<node dir="col" wrap="0" width="100%" height="100%" pad="5">
|
||||||
<!-- toolbar -->
|
<!-- toolbar -->
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ App App::I; // singleton
|
|||||||
|
|
||||||
void App::create()
|
void App::create()
|
||||||
{
|
{
|
||||||
width = 500;
|
width = 800;
|
||||||
height = 500;
|
height = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ void App::init()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
layout.load("data/layout.xml");
|
layout.load("data/layout.xml");
|
||||||
//layout.update(width, height);
|
layout["main"].update(width, height);
|
||||||
|
|
||||||
sampler.create();
|
sampler.create();
|
||||||
ShaderManager::create(kShader::Texture, shader_v, shader_f);
|
ShaderManager::create(kShader::Texture, shader_v, shader_f);
|
||||||
@@ -109,11 +109,16 @@ void App::init()
|
|||||||
|
|
||||||
void App::update(float dt)
|
void App::update(float dt)
|
||||||
{
|
{
|
||||||
|
constexpr auto main_id = const_hash("main");
|
||||||
|
|
||||||
glClearColor(.1f, .1f, .1f, 1.f);
|
glClearColor(.1f, .1f, .1f, 1.f);
|
||||||
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
layout.reload();
|
if (layout.reload())
|
||||||
|
{
|
||||||
|
layout[main_id].update(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
tex.bind();
|
tex.bind();
|
||||||
@@ -122,17 +127,16 @@ void App::update(float dt)
|
|||||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||||
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
//glEnable(GL_SCISSOR_TEST);
|
||||||
// for (auto& n : layout)
|
for (auto& n : layout[main_id])
|
||||||
// {
|
{
|
||||||
//
|
if (n.m_widget)
|
||||||
// if (n.m_widget)
|
{
|
||||||
// {
|
auto box = n.m_widget->clip;
|
||||||
// auto box = n.m_widget->clip;
|
glScissor(box.x, height - box.y - box.w, box.z, box.w);
|
||||||
// glScissor(box.x, height - box.y - box.w, box.z, box.w);
|
n.m_widget->draw();
|
||||||
// n.m_widget->draw();
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
tex.unbind();
|
tex.unbind();
|
||||||
sampler.unbind();
|
sampler.unbind();
|
||||||
@@ -140,9 +144,8 @@ void App::update(float dt)
|
|||||||
|
|
||||||
void App::resize(float w, float h)
|
void App::resize(float w, float h)
|
||||||
{
|
{
|
||||||
width = w;
|
constexpr auto main_id = const_hash("main");
|
||||||
height = h;
|
layout[main_id].update(w, h);
|
||||||
// layout.update(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::mouse_down(int button, float x, float y)
|
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);
|
YGNodeStyleSetWidth(y_node, width);
|
||||||
YGNodeStyleSetHeight(y_node, height);
|
YGNodeStyleSetHeight(y_node, height);
|
||||||
YGNodeCalculateLayout(y_node, YGUndefined, YGUndefined, YGDirectionLTR);
|
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);
|
update_internal({ 0, 0 }, proj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ bool LayoutManager::load(const char* path)
|
|||||||
m_file_info = tmp_info;
|
m_file_info = tmp_info;
|
||||||
m_path = path;
|
m_path = path;
|
||||||
|
|
||||||
m_layouts.clear();
|
auto old = std::move(m_layouts);
|
||||||
|
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
auto ret = xml.LoadFile(path);
|
auto ret = xml.LoadFile(path);
|
||||||
@@ -235,11 +235,18 @@ bool LayoutManager::load(const char* path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint16_t id = const_hash(id_str);
|
uint16_t id = const_hash(id_str);
|
||||||
auto p = m_layouts.try_emplace(id);
|
auto& p = m_layouts.try_emplace(id);
|
||||||
if (p.second)
|
if (p.second)
|
||||||
{
|
{
|
||||||
auto& node = p.first->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
|
else
|
||||||
{
|
{
|
||||||
@@ -247,14 +254,13 @@ bool LayoutManager::load(const char* path)
|
|||||||
}
|
}
|
||||||
current = current->NextSiblingElement("layout");
|
current = current->NextSiblingElement("layout");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutManager::reload()
|
bool LayoutManager::reload()
|
||||||
{
|
{
|
||||||
// float w = YGNodeLayoutGetWidth(y_node);
|
// avoid conflict when assigning the same string from c_str
|
||||||
// float h = YGNodeLayoutGetHeight(y_node);
|
std::string path_copy = m_path;
|
||||||
// // avoid conflict when assigning the same string from c_str
|
return load(path_copy.c_str());
|
||||||
// std::string path_copy = m_path;
|
|
||||||
// load(path_copy.c_str());
|
|
||||||
// update(w, h);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,8 @@ public:
|
|||||||
|
|
||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
|
friend class LayoutManager;
|
||||||
|
|
||||||
const Node* parent{ nullptr };
|
const Node* parent{ nullptr };
|
||||||
YGNodeRef y_node{ nullptr };
|
YGNodeRef y_node{ nullptr };
|
||||||
|
|
||||||
@@ -293,5 +295,7 @@ class LayoutManager
|
|||||||
struct stat m_file_info { 0 };
|
struct stat m_file_info { 0 };
|
||||||
public:
|
public:
|
||||||
bool load(const char* path);
|
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