implementing text input on osx

This commit is contained in:
2017-07-16 18:37:00 +01:00
parent 4e765f1450
commit e32329ea98
4 changed files with 26 additions and 1 deletions

View File

@@ -7,6 +7,18 @@ Node* NodeTextInput::clone_instantiate() const
return new NodeTextInput();
}
void NodeTextInput::clone_finalize(Node* dest) const
{
NodeBorder::clone_copy(dest);
NodeTextInput* n = static_cast<NodeTextInput*>(dest);
if (n->m_children.size())
{
auto t = n->m_children[0];
n->m_text = (NodeText*)t.get();
}
n->m_string = m_string;
}
void NodeTextInput::init()
{
init_controls();
@@ -20,6 +32,7 @@ void NodeTextInput::init_controls()
m_text->m_font_size = 11;
m_text->m_text = "TextInput";
m_text->create();
m_string = "TextInput";
}
kEventResult NodeTextInput::handle_event(Event* e)
@@ -46,7 +59,13 @@ kEventResult NodeTextInput::handle_event(Event* e)
case kEventType::KeyChar:
if (ke->m_char >= 32 && ke->m_char < (32 + 96))
{
m_string += (char)ke->m_key;
if (ke->m_char == 0x7f)
{
if (!m_string.empty())
m_string.erase(m_string.end() - 1);
}
else
m_string += (char)ke->m_char;
m_text->set_text(m_string.c_str());
}
break;

View File

@@ -8,6 +8,7 @@ public:
NodeText* m_text;
std::string m_string;
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;
virtual void init() override;
void init_controls();
virtual kEventResult handle_event(Event* e) override;