26 ImGui::SetNextItemWidth(-1);
27 ImGui::InputTextWithHint(
"##Search",
"Search name or ID", state.
search,
30 const float sort_width = ImGui::GetFontSize() * 5.0f;
31 const float width = std::max(1.0f, ImGui::GetContentRegionAvail().x);
32 ImGui::SetNextItemWidth(
33 std::max(1.0f, width - sort_width - ImGui::GetStyle().ItemSpacing.x));
34 if (!categories.empty())
35 ImGui::Combo(
"##Category", &state.
category, categories.data(),
36 static_cast<int>(categories.size()));
39 ImGui::SetNextItemWidth(sort_width);
40 constexpr const char* sorts[] = {
"ID",
"Name"};
41 ImGui::Combo(
"##Sort", &state.
sort, sorts, IM_ARRAYSIZE(sorts));
43 if (ImGui::IsItemHovered())
44 ImGui::SetTooltip(
"Sort by ID or name.");
48 std::string folded(value);
50 folded.begin(), folded.end(), folded.begin(),
51 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
74 DrawPreview preview, std::string_view badge = {}) {
75 const float height = std::max(28.0f, ImGui::GetTextLineHeight() + 10.0f);
76 const ImVec2 pos = ImGui::GetCursorScreenPos();
78 ImGui::Selectable(
"##row", selected, 0, ImVec2(0, height));
79 const ImVec2 max = ImGui::GetItemRectMax();
80 if (ImGui::IsItemVisible()) {
82 preview(ImVec2(pos.x + 3, pos.y + 2), ImVec2(24, height - 4));
84 std::snprintf(hex,
sizeof(hex),
"%03X",
id);
85 const std::string id_text =
86 badge.empty() ? std::string(hex) : std::string(badge);
87 const float id_width = ImGui::CalcTextSize(id_text.c_str()).x;
88 const float name_x = pos.x + (rendered ? 34.0f : 6.0f);
89 auto* draw = ImGui::GetWindowDrawList();
90 draw->PushClipRect(ImVec2(name_x, pos.y),
91 ImVec2(std::max(name_x, max.x - id_width - 12), max.y),
94 ImVec2(name_x, pos.y + (height - ImGui::GetTextLineHeight()) * .5f),
95 ImGui::GetColorU32(ImGuiCol_Text), name.c_str());
97 draw->AddText(ImVec2(max.x - id_width - 4,
98 pos.y + (height - ImGui::GetTextLineHeight()) * .5f),
99 ImGui::GetColorU32(ImGuiCol_TextDisabled), id_text.c_str());
101 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
102 ImGui::SetTooltip(
"%s ($%03X)", name.c_str(),
id);
103 ImGui::LogText(
"%03X %s\n",
id, name.c_str());