#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("title"); m_field_name = m_template->find("field-name"); m_field_text = m_template->find("field-text"); btn_ok = m_template->find("btn-ok"); btn_ok->on_click = [&](Node*) { if (on_submit) on_submit(this, m_field_text->m_text); }; btn_cancel = m_template->find("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); break; case kEventType::KeyChar: break; default: return kEventResult::Available; break; } return kEventResult::Consumed; } void NodeInputBox::added(Node* parent) { Node::added(parent); mouse_capture(); m_field_text->key_capture(); }