// SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/select_menu.hpp" #include #include #include #include #include #include #include #include #include namespace bmh::modern_ui { namespace { using Select = Rml::ElementFormControlSelect; using Clock = std::chrono::steady_clock; std::string plain_text(Rml::Element *node) { if (auto *text = dynamic_cast(node)) return Rml::StringUtilities::DecodeRml(text->GetText()); std::string text; for (int i = 0; i < node->GetNumChildren(); ++i) text += plain_text(node->GetChild(i)); return text; } std::string tidy(std::string text) { std::string out; bool space = false; for (const auto c : text) { if (c == ' ' || c == '\t' || c == '\n' || c == '\r') { space = !out.empty(); continue; } if (space) out += ' '; space = false; out += c; } return out; } // Country/league labels use Latin scripts. Keep UTF-8 intact and support their // common accented capitals, rather than lowercasing individual non-ASCII bytes. std::string folded(std::string text) { for (size_t i = 0; i < text.size(); ++i) { const auto c = static_cast(text[i]); if (c >= 'A' && c <= 'Z') text[i] = char(c + ('a' - 'A')); else if (c == 0xc3 && i + 1 < text.size()) { const auto next = static_cast(text[i + 1]); if (next >= 0x80 && next <= 0x9e && next != 0x97) text[++i] = char(next + 0x20); } } return text; } bool within(Rml::Element *node, const Rml::Element *root) { for (; node; node = node->GetParentNode()) if (node == root) return true; return false; } Select *native_select(Rml::Element *node) { for (; node; node = node->GetParentNode()) if (auto *select = dynamic_cast(anchor.get()); } std::vector