13 const std::array<gfx::Bitmap, kNumGfxSheets>& bmp_manager) {
14 PushItemWidth(GetFontSize() * 10);
15 SeparatorText(
"Contents");
26 SliderFloat(
"Icon Size", &
IconSize, 16.0f, 128.0f,
"%.0f");
34 static bool filter_type[4] = {
true,
true,
true,
true};
35 Text(
"Filter by type:");
37 Checkbox(
"Unsorted", &filter_type[0]);
39 Checkbox(
"Dungeon", &filter_type[1]);
41 Checkbox(
"Overworld", &filter_type[2]);
43 Checkbox(
"Sprite", &filter_type[3]);
48 PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
49 ImGuiTableFlags table_flags_for_sort_specs =
50 ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti |
51 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders;
52 if (BeginTable(
"for_sort_specs_only", 2, table_flags_for_sort_specs,
53 ImVec2(0.0f, GetFrameHeight()))) {
54 TableSetupColumn(
"Index");
55 TableSetupColumn(
"Type");
57 if (ImGuiTableSortSpecs* sort_specs = TableGetSortSpecs())
67 ImGuiIO& io = GetIO();
68 SetNextWindowContentSize(ImVec2(
71 if (BeginChild(
"Assets", ImVec2(0.0f, -GetTextLineHeightWithSpacing()),
72 ImGuiChildFlags_Border, ImGuiWindowFlags_NoMove)) {
73 ImDrawList* draw_list = GetWindowDrawList();
75 const float avail_width = GetContentRegionAvail().x;
79 ImVec2 start_pos = GetCursorScreenPos();
82 SetCursorScreenPos(start_pos);
85 ImGuiMultiSelectFlags ms_flags = ImGuiMultiSelectFlags_ClearOnEscape |
86 ImGuiMultiSelectFlags_ClearOnClickVoid;
95 ms_flags |= ImGuiMultiSelectFlags_SelectOnClickRelease;
104 ms_flags |= ImGuiMultiSelectFlags_NavWrapX;
106 ImGuiMultiSelectIO* ms_io =
111 Selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self_,
114 return self->
Items[idx].ID;
118 const bool want_delete =
119 (Shortcut(ImGuiKey_Delete, ImGuiInputFlags_Repeat) &&
122 const int item_curr_idx_to_focus =
123 want_delete ?
Selection.ApplyDeletionPreLoop(ms_io,
Items.Size) : -1;
134 PushStyleVar(ImGuiStyleVar_ItemSpacing,
138 const ImU32 icon_type_overlay_colors[5] = {
139 0, IM_COL32(200, 70, 70, 255), IM_COL32(70, 170, 70, 255),
140 IM_COL32(70, 70, 200, 255), IM_COL32(200, 200, 200, 255)};
141 const ImU32 icon_bg_color = GetColorU32(ImGuiCol_MenuBarBg);
142 const ImVec2 icon_type_overlay_size = ImVec2(5.0f, 5.0f);
143 const bool display_label = (
LayoutItemSize.x >= CalcTextSize(
"999").x);
146 ImGuiListClipper clipper;
150 if (item_curr_idx_to_focus != -1)
151 clipper.IncludeItemByIndex(item_curr_idx_to_focus / column_count);
154 if (ms_io->RangeSrcItem != -1)
155 clipper.IncludeItemByIndex((
int)ms_io->RangeSrcItem / column_count);
157 while (clipper.Step()) {
158 for (
int line_idx = clipper.DisplayStart; line_idx < clipper.DisplayEnd;
160 const int item_min_idx_for_current_line = line_idx * column_count;
161 const int item_max_idx_for_current_line =
163 for (
int item_idx = item_min_idx_for_current_line;
164 item_idx < item_max_idx_for_current_line; ++item_idx) {
166 PushID((
int)item_data->
ID);
170 ImVec2(start_pos.x + (item_idx % column_count) *
LayoutItemStep.x,
172 SetCursorScreenPos(pos);
174 SetNextItemSelectionUserData(item_idx);
175 bool item_is_selected =
Selection.Contains((ImGuiID)item_data->
ID);
177 Selectable(
"", item_is_selected, ImGuiSelectableFlags_None,
183 if (IsItemToggledSelection()) item_is_selected = !item_is_selected;
186 if (item_curr_idx_to_focus == item_idx) SetKeyboardFocusHere(-1);
189 if (BeginDragDropSource()) {
193 if (GetDragDropPayload() == NULL) {
194 ImVector<ImGuiID> payload_items;
197 if (!item_is_selected)
198 payload_items.push_back(item_data->
ID);
200 while (
Selection.GetNextSelectedItem(&it, &
id))
201 payload_items.push_back(
id);
202 SetDragDropPayload(
"ASSETS_BROWSER_ITEMS", payload_items.Data,
203 (
size_t)payload_items.size_in_bytes());
209 const ImGuiPayload* payload = GetDragDropPayload();
210 const int payload_count =
211 (int)payload->DataSize / (
int)
sizeof(ImGuiID);
212 Text(
"%d assets", payload_count);
221 if (item_is_visible) {
222 ImVec2 box_min(pos.x - 1, pos.y - 1);
225 draw_list->AddRectFilled(box_min, box_max,
229 ImU32 label_col = GetColorU32(
230 item_is_selected ? ImGuiCol_Text : ImGuiCol_TextDisabled);
232 (ImTextureID)(intptr_t)bmp_manager[item_data->
ID].texture(),
233 box_min, box_max, ImVec2(0, 0), ImVec2(1, 1),
234 GetColorU32(ImVec4(1, 1, 1, 1)));
235 draw_list->AddText(ImVec2(box_min.x, box_max.y - GetFontSize()),
237 absl::StrFormat(
"%X", item_data->
ID).c_str());
240 ImU32 type_col = icon_type_overlay_colors
241 [item_data->
Type % IM_ARRAYSIZE(icon_type_overlay_colors)];
242 draw_list->AddRectFilled(
243 ImVec2(box_max.x - 2 - icon_type_overlay_size.x,
245 ImVec2(box_max.x - 2,
246 box_min.y + 2 + icon_type_overlay_size.y),
259 if (BeginPopupContextWindow()) {
260 Text(
"Selection: %d items",
Selection.Size);
262 if (BeginMenu(
"Set Type")) {
263 if (MenuItem(
"Unsorted")) {
266 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 0;
268 if (MenuItem(
"Dungeon")) {
271 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 1;
273 if (MenuItem(
"Overworld")) {
276 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 2;
278 if (MenuItem(
"Sprite")) {
281 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 3;
286 if (MenuItem(
"Delete",
"Del",
false,
Selection.Size > 0))
291 ms_io = EndMultiSelect();
294 Selection.ApplyDeletionPostLoop(ms_io,
Items, item_curr_idx_to_focus);
298 if (IsWindowHovered() && io.MouseWheel != 0.0f &&
299 IsKeyDown(ImGuiMod_Ctrl) && IsAnyItemActive() ==
false) {
305 const float hovered_item_nx =
308 const float hovered_item_ny =
311 const int hovered_item_idx =
328 float hovered_item_rel_pos_y =
330 fmodf(hovered_item_ny, 1.0f)) *
332 hovered_item_rel_pos_y += GetStyle().WindowPadding.y;
333 float mouse_local_y = io.MousePos.y - GetWindowPos().y;
334 SetScrollY(hovered_item_rel_pos_y - mouse_local_y);