#include "pch.h" #include "log.h" #include "node_combobox.h" #include "node_popup_menu.h" Node* NodeComboBox::clone_instantiate() const { return new NodeComboBox; } void NodeComboBox::clone_copy(Node* dest) const { NodeButton::clone_copy(dest); NodeComboBox* n = static_cast(dest); n->labels = labels; n->m_current_index = m_current_index; } void NodeComboBox::loaded() { NodeButton::loaded(); on_click = [this](Node* target) { NodePopupMenu* popup = new NodePopupMenu; popup->init(); popup->create(); popup->loaded(); root()->add_child(popup); for (int i = 0; i < labels.size(); i++) { NodeButton* btn = new NodeButton; btn->init(); btn->create(); btn->loaded(); popup->add_child(btn); btn->m_text->set_text(labels[i].c_str()); btn->m_border->SetWidthP(100.f); btn->m_border->SetHeight(30.f); btn->on_click = [this,popup,btn](Node* target) { int index = popup->get_child_index(target); m_current_index = index; m_text->set_text(labels[index].c_str()); popup->mouse_release(); popup->destroy(); if (on_select) on_select(btn, index); }; } glm::vec2 pos = m_pos + glm::vec2(0, m_size.y - (m_current_index+1) * 30.f); popup->SetPositioning(YGPositionTypeAbsolute); popup->SetPosition(pos.x, pos.y); popup->SetSize(m_size.x, YGUndefined); popup->SetFlexGrow(1.f); popup->update(); root()->update(); popup->mouse_capture(); popup->m_mouse_ignore = false; popup->m_flood_events = true; popup->m_capture_children = false; }; } void NodeComboBox::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) { NodeButton::parse_attributes(ka, attr); switch (ka) { case kAttribute::ComboList: { labels = split(attr->Value(), ','); break; } case kAttribute::Default: m_current_index = attr->IntValue(); break; } }