refactor font loading

This commit is contained in:
2019-12-01 18:24:59 +01:00
parent 0905827b8d
commit c8bce21b95
30 changed files with 180 additions and 84 deletions

View File

@@ -35,12 +35,13 @@ void NodeTextInput::clone_copy(Node* dest) const
NodeTextInput* n = static_cast<NodeTextInput*>(dest);
n->m_text_mesh.max_width = m_text_mesh.max_width;
n->m_text_mesh.create();
n->m_text_mesh.update(font_id, m_text);
n->m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
n->m_text = m_text;
n->m_font = m_font;
n->m_color = m_color;
n->m_font_name = m_font_name;
n->m_font_size = m_font_size;
n->font_id = font_id;
n->m_font_weight = m_font_weight;
n->m_font_italic = m_font_italic;
n->m_color = m_color;
n->m_multiline = m_multiline;
n->m_off = m_off;
n->m_text_align_v = m_text_align_v;
@@ -130,7 +131,7 @@ kEventResult NodeTextInput::handle_event(Event* e)
void NodeTextInput::set_text(const std::string& s)
{
m_text = s;
m_text_mesh.update(font_id, s);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
@@ -142,7 +143,26 @@ void NodeTextInput::set_text_format(const char* fmt, ...)
vsnprintf(buffer, sizeof(buffer), fmt, args);
va_end(args);
m_text = buffer;
m_text_mesh.update(font_id, buffer);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
void NodeTextInput::set_font(const std::string& name, int size, const std::string& weight, bool italic)
{
m_font_name = name;
m_font_size = size;
m_font_weight = weight;
m_font_italic = italic;
m_text_mesh.create();
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
void NodeTextInput::set_font_size(int size)
{
m_font_size = size;
m_text_mesh.create();
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
@@ -182,11 +202,10 @@ void NodeTextInput::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float
void NodeTextInput::create()
{
NodeBorder::create();
if (!m_font.empty())
if (!m_font_name.empty())
{
font_id = fmt::format("{}-{}", m_font, m_font_size);
m_text_mesh.create();
m_text_mesh.update(font_id, m_text);
m_text_mesh.update(m_text, m_font_name, m_font_size, m_font_weight, m_font_italic);
update_layout();
}
}