fix pixel snapping, add loaded event, remove default border thickness
This commit is contained in:
@@ -24,15 +24,17 @@
|
|||||||
</layout>
|
</layout>
|
||||||
<layout id="message-box">
|
<layout id="message-box">
|
||||||
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
|
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
|
||||||
<border width="400" height="40" color="0 0 0 .9" dir="row" align="center" justify="center">
|
<border thickness="5" border-color=".2" pad="3">
|
||||||
<text text="Shit! Bug happens." font-face="arial" font-size="11"></text>
|
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
|
||||||
</border>
|
<text text="Shit! Bug happens." font-face="arial" font-size="11"></text>
|
||||||
<border width="400" height="200" color="0 0 0 .9" pad="10" dir="col">
|
</border>
|
||||||
<text text="Yep, it's a bug. No worries, it happens. Try Unity and see." font-face="arial" font-size="11"></text>
|
<border width="400" color="0 0 0 .9" pad="10" dir="col">
|
||||||
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
|
<text text="Yep, it's a bug. No worries, it happens. Try Unity and see." font-face="arial" font-size="11"></text>
|
||||||
<button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/>
|
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
|
||||||
<button text="Cancel" width="60" height="30" pad="10"/>
|
<button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/>
|
||||||
</node>
|
<button text="Cancel" width="60" height="30" pad="10"/>
|
||||||
|
</node>
|
||||||
|
</border>
|
||||||
</border>
|
</border>
|
||||||
</border>
|
</border>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@@ -123,36 +123,24 @@ void App::init()
|
|||||||
FontManager::load(kFont::Arial_11, ttf, 15);
|
FontManager::load(kFont::Arial_11, ttf, 15);
|
||||||
FontManager::load(kFont::Arial_30, ttf, 30);
|
FontManager::load(kFont::Arial_30, ttf, 30);
|
||||||
|
|
||||||
|
layout.on_loaded = [&] {
|
||||||
|
layout[main_id].update(width, height);
|
||||||
|
if (auto* button = layout[main_id].find<NodeButton>("btn-close"))
|
||||||
|
{
|
||||||
|
button->on_click = [] { exit(0); };
|
||||||
|
}
|
||||||
|
if (auto* button = layout[main_id].find<NodeButton>("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");
|
layout.load("data/layout.xml");
|
||||||
if (auto* button = layout[main_id].find<NodeButton>("btn-close"))
|
|
||||||
{
|
|
||||||
button->on_click = [] { exit(0); };
|
|
||||||
}
|
|
||||||
if (auto* button = layout[main_id].find<NodeButton>("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<NodeButton>("btn-ok")->on_click = [] { exit(0); };
|
//msgbox->find<NodeButton>("btn-ok")->on_click = [] { exit(0); };
|
||||||
// msgbox->find<NodeButton>("btn-ok")->m_text->m_text = "DO";
|
// msgbox->find<NodeButton>("btn-ok")->m_text->m_text = "DO";
|
||||||
@@ -200,10 +188,7 @@ void App::update(float dt)
|
|||||||
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// if (layout.reload())
|
layout.reload();
|
||||||
// {
|
|
||||||
// layout[main_id].update(width, height);
|
|
||||||
// }
|
|
||||||
|
|
||||||
auto observer = [this](Node* n)
|
auto observer = [this](Node* n)
|
||||||
{
|
{
|
||||||
@@ -235,6 +220,14 @@ void App::mouse_down(int button, float x, float y)
|
|||||||
e.m_pos = { x, y };
|
e.m_pos = { x, y };
|
||||||
layout[main_id].on_event(&e);
|
layout[main_id].on_event(&e);
|
||||||
printf("mouse click %f %f\n", x, y);
|
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)
|
void App::mouse_move(float x, float y)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
|||||||
float y = YGNodeLayoutGetTop(y_node);
|
float y = YGNodeLayoutGetTop(y_node);
|
||||||
float w = YGNodeLayoutGetWidth(y_node);
|
float w = YGNodeLayoutGetWidth(y_node);
|
||||||
float h = YGNodeLayoutGetHeight(y_node);
|
float h = YGNodeLayoutGetHeight(y_node);
|
||||||
m_pos = origin + glm::vec2(x, y);
|
m_pos = glm::floor(origin + glm::vec2(x, y));
|
||||||
m_size = glm::vec2(w, h);
|
m_size = glm::ceil(glm::vec2(w, h));
|
||||||
|
|
||||||
if (parent)
|
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 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f));
|
||||||
glm::mat4 scale = glm::scale(glm::vec3(glm::ceil(m_size), 1.f));
|
glm::mat4 scale = glm::scale(glm::vec3(m_size, 1.f));
|
||||||
glm::mat4 pos = glm::translate(glm::vec3(glm::floor(m_pos), 0));
|
glm::mat4 pos = glm::translate(glm::vec3(m_pos, 0));
|
||||||
m_mvp = proj * pos * scale * pivot;
|
m_mvp = proj * pos * scale * pivot;
|
||||||
m_proj = proj;
|
m_proj = proj;
|
||||||
for (auto& c : m_children)
|
for (auto& c : m_children)
|
||||||
@@ -463,6 +463,8 @@ bool LayoutManager::load(const char* path)
|
|||||||
}
|
}
|
||||||
current = current->NextSiblingElement("layout");
|
current = current->NextSiblingElement("layout");
|
||||||
}
|
}
|
||||||
|
if (on_loaded)
|
||||||
|
on_loaded();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ class LayoutManager
|
|||||||
std::string m_path;
|
std::string m_path;
|
||||||
struct stat m_file_info { 0 };
|
struct stat m_file_info { 0 };
|
||||||
public:
|
public:
|
||||||
|
std::function<void()> on_loaded;
|
||||||
bool load(const char* path);
|
bool load(const char* path);
|
||||||
bool reload();
|
bool reload();
|
||||||
class Node& operator[](uint16_t id) { return *m_layouts[id]; }
|
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)
|
void SetPosition(float l, float t, float r, float b)
|
||||||
{
|
{
|
||||||
YGNodeStyleSetPadding(y_node, YGEdgeTop, t);
|
YGNodeStyleSetPosition(y_node, YGEdgeTop, t);
|
||||||
YGNodeStyleSetPadding(y_node, YGEdgeRight, r);
|
YGNodeStyleSetPosition(y_node, YGEdgeRight, r);
|
||||||
YGNodeStyleSetPadding(y_node, YGEdgeBottom, b);
|
YGNodeStyleSetPosition(y_node, YGEdgeBottom, b);
|
||||||
YGNodeStyleSetPadding(y_node, YGEdgeLeft, l);
|
YGNodeStyleSetPosition(y_node, YGEdgeLeft, l);
|
||||||
}
|
}
|
||||||
void SetPosition(float l, float t)
|
void SetPosition(float l, float t)
|
||||||
{
|
{
|
||||||
YGNodeStyleSetPadding(y_node, YGEdgeTop, t);
|
YGNodeStyleSetPosition(y_node, YGEdgeTop, t);
|
||||||
YGNodeStyleSetPadding(y_node, YGEdgeLeft, l);
|
YGNodeStyleSetPosition(y_node, YGEdgeLeft, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFlexGrow(float value) { YGNodeStyleSetFlexGrow(y_node, value); }
|
void SetFlexGrow(float value) { YGNodeStyleSetFlexGrow(y_node, value); }
|
||||||
@@ -285,7 +286,7 @@ public:
|
|||||||
static Plane m_plane;
|
static Plane m_plane;
|
||||||
glm::vec4 m_color{ 0, 0, 0, 1 };
|
glm::vec4 m_color{ 0, 0, 0, 1 };
|
||||||
glm::vec4 m_border_color{ 1, 1, 1, 1 };
|
glm::vec4 m_border_color{ 1, 1, 1, 1 };
|
||||||
float m_thinkness{ 1 };
|
float m_thinkness{ 0 };
|
||||||
static void static_init()
|
static void static_init()
|
||||||
{
|
{
|
||||||
m_plane.create<1>(1, 1);
|
m_plane.create<1>(1, 1);
|
||||||
@@ -342,9 +343,12 @@ public:
|
|||||||
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
|
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
|
||||||
m_plane.draw_fill();
|
m_plane.draw_fill();
|
||||||
|
|
||||||
glLineWidth(m_thinkness);
|
if (m_thinkness > 0)
|
||||||
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
|
{
|
||||||
m_plane.draw_stroke();
|
glLineWidth(m_thinkness);
|
||||||
|
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
|
||||||
|
m_plane.draw_stroke();
|
||||||
|
}
|
||||||
|
|
||||||
if (m_color.a != 1.f)
|
if (m_color.a != 1.f)
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|||||||
Reference in New Issue
Block a user