static void shortcutInput(int& shortcut) { StringBuilder<50> popup_name(""); popup_name << (Lumix::int64)&shortcut; char key_string[30]; PlatformInterface::getKeyName(shortcut, key_string, 30); StringBuilder<50> button_label(key_string); button_label << "##" << (Lumix::int64)&shortcut; if (ImGui::Button(button_label, ImVec2(50, 0))) shortcut = -1; auto& io = ImGui::GetIO(); if (ImGui::IsItemHovered()) { for (int i = 0; i < Lumix::lengthOf(ImGui::GetIO().KeysDown); ++i) { if (io.KeysDown[i]) { shortcut = i; break; } } } }
static void shortcutInput(int& shortcut) { Lumix::StaticString<50> popup_name(""); popup_name << (Lumix::i64)&shortcut; Lumix::StaticString<50> button_label(SDL_GetKeyName(SDL_GetKeyFromScancode((SDL_Scancode)shortcut))); button_label << "###" << (Lumix::i64)&shortcut; if (ImGui::Button(button_label, ImVec2(65, 0))) shortcut = -1; auto& io = ImGui::GetIO(); int key_count; auto* state = SDL_GetKeyboardState(&key_count); if (ImGui::IsItemHovered()) { for (int i = 0; i < key_count; ++i) { if (state[i]) { shortcut = i; break; } } } }
bool AssetBrowser::resourceInput(const char* label, const char* str_id, char* buf, int max_size, Lumix::uint32 type) { float item_w = ImGui::CalcItemWidth(); auto& style = ImGui::GetStyle(); float text_width = Lumix::Math::maximum( 50.0f, item_w - ImGui::CalcTextSize("...View").x - style.FramePadding.x * 4 - style.ItemSpacing.x * 2); char* c = buf + Lumix::stringLength(buf); while (c > buf && *c != '/' && *c != '\\') --c; if (*c == '/' || *c == '\\') ++c; auto pos = ImGui::GetCursorPos(); pos.x += text_width; ImGui::AlignFirstTextHeightToWidgets(); ImGui::PushTextWrapPos(text_width); ImGui::Text("%s", c); ImGui::PopTextWrapPos(); ImGui::SameLine(); ImGui::SetCursorPos(pos); Lumix::StaticString<50> popup_name("pu", str_id); if (ImGui::Button(Lumix::StaticString<30>("...###browse", str_id))) { ImGui::OpenPopup(popup_name); } ImGui::SameLine(); if (ImGui::Button(Lumix::StaticString<30>("View###go", str_id))) { m_is_focus_requested = true; m_is_opened = true; m_wanted_resource = buf; } ImGui::SameLine(); ImGui::Text("%s", label); if (ImGui::BeginResizablePopup(popup_name, ImVec2(300, 300))) { static char filter[128] = ""; ImGui::InputText("Filter", filter, sizeof(filter)); ImGui::BeginChild("Resources", ImVec2(0, 0)); for (auto unv : getResources(getTypeIndexFromManagerType(type))) { if (filter[0] != '\0' && strstr(unv.c_str(), filter) == nullptr) continue; if (ImGui::Selectable(unv.c_str(), false)) { Lumix::copyString(buf, max_size, unv.c_str()); ImGui::EndChild(); ImGui::EndPopup(); return true; } } ImGui::EndChild(); ImGui::EndPopup(); } return false; }
bool PropertyGrid::entityInput(const char* label, const char* str_id, Lumix::Entity& entity) const { const auto& style = ImGui::GetStyle(); float item_w = ImGui::CalcItemWidth(); ImGui::PushItemWidth( item_w - ImGui::CalcTextSize("...").x - style.FramePadding.x * 2 - style.ItemSpacing.x); char buf[50]; getEntityListDisplayName(m_editor, buf, sizeof(buf), entity); ImGui::LabelText("", "%s", buf); ImGui::SameLine(); Lumix::StaticString<30> popup_name("pu", str_id); if (ImGui::Button(Lumix::StaticString<30>("...###br", str_id))) { ImGui::OpenPopup(popup_name); } ImGui::SameLine(); ImGui::Text("%s", label); ImGui::PopItemWidth(); if (ImGui::BeginPopup(popup_name)) { struct ListBoxData { Lumix::WorldEditor* m_editor; Lumix::Universe* universe; char buffer[1024]; static bool itemsGetter(void* data, int idx, const char** txt) { auto* d = static_cast<ListBoxData*>(data); auto entity = d->universe->getEntityFromDenseIdx(idx); getEntityListDisplayName(*d->m_editor, d->buffer, sizeof(d->buffer), entity); *txt = d->buffer; return true; } }; ListBoxData data; Lumix::Universe* universe = m_editor.getUniverse(); data.universe = universe; data.m_editor = &m_editor; static int current_item; if (ImGui::ListBox("Entities", ¤t_item, &ListBoxData::itemsGetter, &data, universe->getEntityCount(), 15)) { entity = universe->getEntityFromDenseIdx(current_item); ImGui::CloseCurrentPopup(); ImGui::EndPopup(); return true; }; ImGui::EndPopup(); } return false; }
bool AssetBrowser::resourceInput(const char* label, const char* str_id, char* buf, int max_size, Lumix::uint32 type) { float item_w = ImGui::CalcItemWidth(); auto& style = ImGui::GetStyle(); ImGui::PushItemWidth(item_w - ImGui::CalcTextSize("...View").x - style.FramePadding.x * 4 - style.ItemSpacing.x * 2); if (ImGui::InputText(Lumix::StaticString<30>("###", str_id), buf, max_size)) return true; ImGui::SameLine(); Lumix::StaticString<50> popup_name("pu", str_id); if (ImGui::Button(Lumix::StaticString<30>("...###browse", str_id))) { ImGui::OpenPopup(popup_name); } ImGui::SameLine(); if (ImGui::Button(Lumix::StaticString<30>("View###go", str_id))) { m_is_focus_requested = true; m_is_opened = true; m_wanted_resource = buf; } ImGui::SameLine(); ImGui::Text("%s", label); ImGui::PopItemWidth(); if (ImGui::BeginResizablePopup(popup_name, ImVec2(300, 300))) { static char filter[128] = ""; ImGui::InputText("Filter", filter, sizeof(filter)); ImGui::BeginChild("Resources", ImVec2(0, 0)); for (auto unv : getResources(getTypeIndexFromManagerType(type))) { if (filter[0] != '\0' && strstr(unv.c_str(), filter) == nullptr) continue; if (ImGui::Selectable(unv.c_str(), false)) { Lumix::copyString(buf, max_size, unv.c_str()); ImGui::EndChild(); ImGui::EndPopup(); return true; } } ImGui::EndChild(); ImGui::EndPopup(); } return false; }
bool AssetBrowser::resourceInput(const char* label, const char* str_id, char* buf, int max_size, Lumix::uint32 type) { float item_w = ImGui::CalcItemWidth(); auto& style = ImGui::GetStyle(); float text_width = Lumix::Math::maximum( 50.0f, item_w - ImGui::CalcTextSize("...View").x - style.FramePadding.x * 4 - style.ItemSpacing.x * 2); char* c = buf + Lumix::stringLength(buf); while (c > buf && *c != '/' && *c != '\\') --c; if (*c == '/' || *c == '\\') ++c; auto pos = ImGui::GetCursorPos(); pos.x += text_width; ImGui::BeginGroup(); ImGui::AlignFirstTextHeightToWidgets(); ImGui::PushTextWrapPos(text_width); ImGui::Text("%s", c); ImGui::PopTextWrapPos(); ImGui::SameLine(); ImGui::SetCursorPos(pos); Lumix::StaticString<50> popup_name("pu", str_id); if (ImGui::Button(Lumix::StaticString<30>("...###browse", str_id))) { ImGui::OpenPopup(popup_name); } ImGui::EndGroup(); if (ImGui::IsItemHoveredRect()) { if (ImGui::IsMouseReleased(0) && m_app.getDragData().type == StudioApp::DragData::PATH) { char ext[10]; const char* path = (const char*)m_app.getDragData().data; Lumix::PathUtils::getExtension(ext, Lumix::lengthOf(ext), path); if (acceptExtension(ext, type)) { Lumix::copyString(buf, max_size, path); return true; } } } ImGui::SameLine(); if (ImGui::Button(Lumix::StaticString<30>("View###go", str_id))) { m_is_focus_requested = true; m_is_opened = true; m_wanted_resource = buf; } ImGui::SameLine(); ImGui::Text("%s", label); if (ImGui::BeginResizablePopup(popup_name, ImVec2(300, 300))) { if (resourceList(buf, max_size, type, 0)) { ImGui::EndPopup(); return true; } ImGui::EndPopup(); } return false; }