diff --git a/data/layout.xml b/data/layout.xml
index 029580a..77f9666 100644
--- a/data/layout.xml
+++ b/data/layout.xml
@@ -24,15 +24,17 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/engine/app.cpp b/engine/app.cpp
index bb4971f..6ac9726 100644
--- a/engine/app.cpp
+++ b/engine/app.cpp
@@ -123,36 +123,24 @@ void App::init()
FontManager::load(kFont::Arial_11, ttf, 15);
FontManager::load(kFont::Arial_30, ttf, 30);
+ layout.on_loaded = [&] {
+ layout[main_id].update(width, height);
+ if (auto* button = layout[main_id].find("btn-close"))
+ {
+ button->on_click = [] { exit(0); };
+ }
+ if (auto* button = layout[main_id].find("btn-popup"))
+ {
+ button->on_click = [this] {
+ msgbox = new NodeMessageBox();
+ msgbox->m_manager = &layout;
+ msgbox->init();
+ layout[main_id].add_child(msgbox);
+ layout[main_id].update(width, height);
+ };
+ }
+ };
layout.load("data/layout.xml");
- if (auto* button = layout[main_id].find("btn-close"))
- {
- button->on_click = [] { exit(0); };
- }
- if (auto* button = layout[main_id].find("btn-popup"))
- {
- button->on_click = [this] {
-// auto nb = new NodeButton();
-// nb->init();
-// nb->SetWidth(50);
-// nb->SetHeightP(100);
-// nb->m_border->SetWidthP(100);
-// nb->m_border->SetHeightP(100);
-// nb->m_text->m_text = "NB";
-// nb->create();
-// layout[main_id].find("toolbar")->add_child(nb);
-// layout[main_id].update(width, height);
- msgbox = new NodeMessageBox();
- msgbox->m_manager = &layout;
- msgbox->init();
- layout[main_id].add_child(msgbox);
- layout[main_id].update(width, height);
- };
- }
-
- msgbox = new NodeMessageBox();
- msgbox->m_manager = &layout;
- msgbox->init();
- layout[main_id].add_child(msgbox);
//msgbox->find("btn-ok")->on_click = [] { exit(0); };
// msgbox->find("btn-ok")->m_text->m_text = "DO";
@@ -200,10 +188,7 @@ void App::update(float dt)
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
glClear(GL_COLOR_BUFFER_BIT);
-// if (layout.reload())
-// {
-// layout[main_id].update(width, height);
-// }
+ layout.reload();
auto observer = [this](Node* n)
{
@@ -235,6 +220,14 @@ void App::mouse_down(int button, float x, float y)
e.m_pos = { x, y };
layout[main_id].on_event(&e);
printf("mouse click %f %f\n", x, y);
+// NodeBorder* n = new NodeBorder();
+// n->SetPositioning(YGPositionTypeAbsolute);
+// n->SetWidth(100);
+// n->SetHeight(100);
+// n->SetPosition(x, y);
+// n->m_color = glm::vec4(.5, .5, .5, .5);
+// layout[main_id].add_child(n);
+// layout[main_id].update(width, height);
}
void App::mouse_move(float x, float y)
{
diff --git a/engine/layout.cpp b/engine/layout.cpp
index 1887426..2d6aa31 100644
--- a/engine/layout.cpp
+++ b/engine/layout.cpp
@@ -87,8 +87,8 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
float y = YGNodeLayoutGetTop(y_node);
float w = YGNodeLayoutGetWidth(y_node);
float h = YGNodeLayoutGetHeight(y_node);
- m_pos = origin + glm::vec2(x, y);
- m_size = glm::vec2(w, h);
+ m_pos = glm::floor(origin + glm::vec2(x, y));
+ m_size = glm::ceil(glm::vec2(w, h));
if (parent)
{
@@ -110,8 +110,8 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
}
glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
- glm::mat4 scale = glm::scale(glm::vec3(glm::ceil(m_size), 1.f));
- glm::mat4 pos = glm::translate(glm::vec3(glm::floor(m_pos), 0));
+ glm::mat4 scale = glm::scale(glm::vec3(m_size, 1.f));
+ glm::mat4 pos = glm::translate(glm::vec3(m_pos, 0));
m_mvp = proj * pos * scale * pivot;
m_proj = proj;
for (auto& c : m_children)
@@ -463,6 +463,8 @@ bool LayoutManager::load(const char* path)
}
current = current->NextSiblingElement("layout");
}
+ if (on_loaded)
+ on_loaded();
return true;
}
diff --git a/engine/layout.h b/engine/layout.h
index ea64d64..c234daa 100644
--- a/engine/layout.h
+++ b/engine/layout.h
@@ -113,6 +113,7 @@ class LayoutManager
std::string m_path;
struct stat m_file_info { 0 };
public:
+ std::function on_loaded;
bool load(const char* path);
bool reload();
class Node& operator[](uint16_t id) { return *m_layouts[id]; }
@@ -182,15 +183,15 @@ public:
}
void SetPosition(float l, float t, float r, float b)
{
- YGNodeStyleSetPadding(y_node, YGEdgeTop, t);
- YGNodeStyleSetPadding(y_node, YGEdgeRight, r);
- YGNodeStyleSetPadding(y_node, YGEdgeBottom, b);
- YGNodeStyleSetPadding(y_node, YGEdgeLeft, l);
+ YGNodeStyleSetPosition(y_node, YGEdgeTop, t);
+ YGNodeStyleSetPosition(y_node, YGEdgeRight, r);
+ YGNodeStyleSetPosition(y_node, YGEdgeBottom, b);
+ YGNodeStyleSetPosition(y_node, YGEdgeLeft, l);
}
void SetPosition(float l, float t)
{
- YGNodeStyleSetPadding(y_node, YGEdgeTop, t);
- YGNodeStyleSetPadding(y_node, YGEdgeLeft, l);
+ YGNodeStyleSetPosition(y_node, YGEdgeTop, t);
+ YGNodeStyleSetPosition(y_node, YGEdgeLeft, l);
}
void SetFlexGrow(float value) { YGNodeStyleSetFlexGrow(y_node, value); }
@@ -285,7 +286,7 @@ public:
static Plane m_plane;
glm::vec4 m_color{ 0, 0, 0, 1 };
glm::vec4 m_border_color{ 1, 1, 1, 1 };
- float m_thinkness{ 1 };
+ float m_thinkness{ 0 };
static void static_init()
{
m_plane.create<1>(1, 1);
@@ -342,9 +343,12 @@ public:
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
m_plane.draw_fill();
- glLineWidth(m_thinkness);
- ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
- m_plane.draw_stroke();
+ if (m_thinkness > 0)
+ {
+ glLineWidth(m_thinkness);
+ ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
+ m_plane.draw_stroke();
+ }
if (m_color.a != 1.f)
glDisable(GL_BLEND);