add remote page loading

This commit is contained in:
2019-11-27 19:55:31 +01:00
parent 7701e6771b
commit 41579fa3c6
18 changed files with 373 additions and 41 deletions

View File

@@ -20,6 +20,10 @@ void NodeText::clone_copy(Node* dest) const
n->m_color = m_color;
n->m_font_size = m_font_size;
n->font_id = font_id;
n->m_multiline = m_multiline;
n->m_off = m_off;
n->m_text_align_v = m_text_align_v;
n->m_text_align_h = m_text_align_h;
}
void NodeText::create()
@@ -32,7 +36,7 @@ void NodeText::create()
font_id = (kFont)const_hash(font);
m_text_mesh.create();
m_text_mesh.update(font_id, m_text);
SetSize(m_text_mesh.bb);
update_layout();
}
}
@@ -41,13 +45,7 @@ void NodeText::set_font(kFont fontID)
font_id = fontID;
m_text_mesh.create();
m_text_mesh.update(font_id, m_text);
SetSize(m_text_mesh.bb);
}
void NodeText::restore_context()
{
Node::restore_context();
create();
update_layout();
}
void NodeText::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
@@ -55,6 +53,25 @@ void NodeText::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* att
Node::parse_attributes(ka, attr);
switch (ka)
{
case kAttribute::Multiline:
m_multiline = attr->BoolValue();
break;
case kAttribute::TextAlign:
if (strcmp(attr->Value(), "left") == 0)
m_text_align_h = TextAlign::Begin;
else if (strcmp(attr->Value(), "center") == 0)
m_text_align_h = TextAlign::Center;
else if (strcmp(attr->Value(), "right") == 0)
m_text_align_h = TextAlign::End;
break;
case kAttribute::TextVerticalAlign:
if (strcmp(attr->Value(), "top") == 0)
m_text_align_v = TextAlign::Begin;
else if (strcmp(attr->Value(), "center") == 0)
m_text_align_v = TextAlign::Center;
else if (strcmp(attr->Value(), "bottom") == 0)
m_text_align_v = TextAlign::End;
break;
case kAttribute::TextWrapWidth:
m_text_mesh.max_width = attr->IntValue();
break;
@@ -82,11 +99,11 @@ void NodeText::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* att
}
}
void NodeText::set_text(const char* s)
void NodeText::set_text(const std::string& s)
{
m_text = s;
m_text_mesh.update(font_id, s);
SetSize(m_text_mesh.bb);
update_layout();
}
void NodeText::set_text_format(const char* fmt, ...)
@@ -98,7 +115,39 @@ void NodeText::set_text_format(const char* fmt, ...)
va_end(args);
m_text = buffer;
m_text_mesh.update(font_id, buffer);
SetSize(m_text_mesh.bb);
update_layout();
}
void NodeText::update_layout()
{
if (auto_width)
{
YGNodeStyleSetWidth(y_node, m_text_mesh.bb.x);
m_size.x = m_text_mesh.bb.x;
}
if (auto_height)
{
YGNodeStyleSetHeight(y_node, m_text_mesh.bb.y);
m_size.y = m_text_mesh.bb.y;
}
auto pad = GetPadding();
float h = GetHeight() - (pad[1] + pad[3]);
float w = GetWidth() - (pad[0] + pad[2]);
if (m_text_align_v == TextAlign::Begin)
m_off.y = pad[0];
else if (m_text_align_v == TextAlign::Center)
m_off.y = (h - m_text_mesh.bb.y) * 0.5f + pad[0];
else
m_off.y = (h - m_text_mesh.bb.y) + pad[0];
if (m_text_align_h == TextAlign::Begin)
m_off.x = pad[3];
else if (m_text_align_v == TextAlign::Center)
m_off.x = (w - m_text_mesh.bb.x) * 0.5f + pad[3];
else
m_off.x = (w - m_text_mesh.bb.x) + pad[3];
}
void NodeText::draw()
@@ -116,6 +165,8 @@ void NodeText::draw()
void NodeText::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom)
{
auto pad = GetPadding();
m_text_mesh.max_width = m_multiline ? new_size.x - (pad[1] + pad[3]) : 0;
m_text_mesh.update(font_id, m_text);
SetSize(m_text_mesh.bb);
update_layout();
}