29 ImGui::SetNextItemWidth(-1);
30 ImGui::InputTextWithHint(
"##Search",
"Search name or ID", state.
search,
33 const float sort_width = ImGui::GetFontSize() * 5.0f;
34 const float width = std::max(1.0f, ImGui::GetContentRegionAvail().x);
35 ImGui::SetNextItemWidth(
36 std::max(1.0f, width - sort_width - ImGui::GetStyle().ItemSpacing.x));
37 if (!categories.empty())
38 ImGui::Combo(
"##Category", &state.
category, categories.data(),
39 static_cast<int>(categories.size()));
42 ImGui::SetNextItemWidth(sort_width);
43 constexpr const char* sorts[] = {
"ID",
"Name"};
44 ImGui::Combo(
"##Sort", &state.
sort, sorts, IM_ARRAYSIZE(sorts));
46 if (ImGui::IsItemHovered())
47 ImGui::SetTooltip(
"Sort by ID or name.");
69 std::string folded(value);
71 folded.begin(), folded.end(), folded.begin(),
72 [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
95 DrawPreview preview, std::string_view badge = {}) {
96 const float height = std::max(28.0f, ImGui::GetTextLineHeight() + 10.0f);
97 const ImVec2 pos = ImGui::GetCursorScreenPos();
99 ImGui::Selectable(
"##row", selected, 0, ImVec2(0, height));
100 const ImVec2 max = ImGui::GetItemRectMax();
101 if (ImGui::IsItemVisible()) {
102 const bool rendered =
103 preview(ImVec2(pos.x + 3, pos.y + 2), ImVec2(24, height - 4));
105 std::snprintf(hex,
sizeof(hex),
"%03X",
id);
106 const std::string id_text =
107 badge.empty() ? std::string(hex) : std::string(badge);
108 const float id_width = ImGui::CalcTextSize(id_text.c_str()).x;
109 const float name_x = pos.x + (rendered ? 34.0f : 6.0f);
110 auto* draw = ImGui::GetWindowDrawList();
111 draw->PushClipRect(ImVec2(name_x, pos.y),
112 ImVec2(std::max(name_x, max.x - id_width - 12), max.y),
115 ImVec2(name_x, pos.y + (height - ImGui::GetTextLineHeight()) * .5f),
116 ImGui::GetColorU32(ImGuiCol_Text), name.c_str());
118 draw->AddText(ImVec2(max.x - id_width - 4,
119 pos.y + (height - ImGui::GetTextLineHeight()) * .5f),
120 ImGui::GetColorU32(ImGuiCol_TextDisabled), id_text.c_str());
122 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
123 ImGui::SetTooltip(
"%s ($%03X)", name.c_str(),
id);
124 ImGui::LogText(
"%03X %s\n",
id, name.c_str());
130 float width, DrawPreview preview,
131 std::string_view badge = {}) {
132 width = std::max(width, 1.0f);
133 const float line_height = ImGui::GetTextLineHeight();
134 const float padding = std::min(3.0f, width * 0.08f);
135 const ImVec2 pos = ImGui::GetCursorScreenPos();
136 const ImVec2 size(width, width + line_height * 2.0f + padding);
138 const bool pressed = ImGui::Selectable(
"##row", selected, 0, size);
139 if (ImGui::IsItemVisible()) {
141 std::snprintf(hex,
sizeof(hex),
"%03X",
id);
142 const std::string id_text =
143 badge.empty() ? std::string(hex) : std::string(badge);
144 const ImVec2 preview_size(std::max(1.0f, width - padding * 2.0f),
145 std::max(1.0f, width - padding * 2.0f));
146 auto* draw = ImGui::GetWindowDrawList();
147 draw->PushClipRect(pos, ImVec2(pos.x + size.x, pos.y + size.y),
true);
148 if (!preview(ImVec2(pos.x + padding, pos.y + padding), preview_size)) {
149 const ImVec2 label_size = ImGui::CalcTextSize(id_text.c_str());
150 draw->AddText(ImVec2(pos.x + (width - label_size.x) * 0.5f,
151 pos.y + (width - line_height) * 0.5f),
152 ImGui::GetColorU32(ImGuiCol_TextDisabled), id_text.c_str());
154 draw->AddText(ImVec2(pos.x + padding, pos.y + width),
155 ImGui::GetColorU32(ImGuiCol_Text), name.c_str());
156 draw->AddText(ImVec2(pos.x + padding, pos.y + width + line_height),
157 ImGui::GetColorU32(ImGuiCol_TextDisabled), id_text.c_str());
160 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
161 ImGui::SetTooltip(
"%s ($%03X)%s%s", name.c_str(),
id,
162 badge.empty() ?
"" :
" - ",
163 badge.empty() ?
"" : std::string(badge).c_str());
164 ImGui::LogText(
"%03X %s\n",
id, name.c_str());