fix text input in windows: implement backspace

This commit is contained in:
2017-07-16 22:21:59 +01:00
parent e32329ea98
commit 6fb20755d3

View File

@@ -57,15 +57,25 @@ kEventResult NodeTextInput::handle_event(Event* e)
//}
break;
case kEventType::KeyChar:
if (ke->m_char >= 32 && ke->m_char < (32 + 96))
if (ke->m_char == '\b') // backspace
{
if (ke->m_char == 0x7f)
if (!m_string.empty())
{
if (!m_string.empty())
m_string.erase(m_string.end() - 1);
m_string.erase(m_string.end() - 1);
m_text->set_text(m_string.c_str());
}
else
m_string += (char)ke->m_char;
}
else if (ke->m_char == 0x7f) // DEL
{
if (!m_string.empty())
{
m_string.erase(m_string.end() - 1);
m_text->set_text(m_string.c_str());
}
}
else if (ke->m_char >= 32 && ke->m_char < (32 + 96))
{
m_string += (char)ke->m_char;
m_text->set_text(m_string.c_str());
}
break;