add text input popup
This commit is contained in:
57
src/node_input_box.cpp
Normal file
57
src/node_input_box.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "node_input_box.h"
|
||||
#include "layout.h"
|
||||
|
||||
Node* NodeInputBox::clone_instantiate() const
|
||||
{
|
||||
return new NodeInputBox();
|
||||
}
|
||||
|
||||
void NodeInputBox::init()
|
||||
{
|
||||
SetPosition(0, 0);
|
||||
SetWidthP(100);
|
||||
SetHeightP(100);
|
||||
SetPositioning(YGPositionTypeAbsolute);
|
||||
auto m_template = (*m_manager)[const_hash("input-box")]->m_children[0]->clone();
|
||||
add_child(m_template);
|
||||
m_title = m_template->find<NodeText>("title");
|
||||
m_field_name = m_template->find<NodeText>("field-name");
|
||||
m_field_text = m_template->find<NodeTextInput>("field-text");
|
||||
btn_ok = m_template->find<NodeButton>("btn-ok");
|
||||
btn_ok->on_click = [&](Node*) {
|
||||
if (on_submit)
|
||||
on_submit(this, m_field_text->m_text->m_text);
|
||||
};
|
||||
btn_cancel = m_template->find<NodeButton>("btn-cancel");
|
||||
btn_cancel->on_click = [&](Node*) { destroy(); };
|
||||
m_capture_children = false; // don't capture children events on mouse_capture
|
||||
}
|
||||
|
||||
kEventResult NodeInputBox::handle_event(Event* e)
|
||||
{
|
||||
Node::handle_event(e);
|
||||
auto ke = (KeyEvent*)e;
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::KeyDown:
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
if (ke->m_key == kKey::KeyEnter && on_submit)
|
||||
on_submit(this, m_field_text->m_text->m_text);
|
||||
break;
|
||||
case kEventType::KeyChar:
|
||||
break;
|
||||
default:
|
||||
return kEventResult::Available;
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
|
||||
void NodeInputBox::added(Node* parent)
|
||||
{
|
||||
Node::added(parent);
|
||||
mouse_capture();
|
||||
}
|
||||
Reference in New Issue
Block a user