14 const std::array<gfx::Bitmap, kNumGfxSheets>& bmp_manager) {
15 PushItemWidth(GetFontSize() * 10);
16 SeparatorText(
"Contents");
27 SliderFloat(
"Icon Size", &
IconSize, 16.0f, 128.0f,
"%.0f");
35 static bool filter_type[4] = {
true,
true,
true,
true};
36 Text(
"Filter by type:");
38 Checkbox(
"Unsorted", &filter_type[0]);
40 Checkbox(
"Dungeon", &filter_type[1]);
42 Checkbox(
"Overworld", &filter_type[2]);
44 Checkbox(
"Sprite", &filter_type[3]);
49 PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
50 ImGuiTableFlags table_flags_for_sort_specs =
51 ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti |
52 ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders;
53 if (BeginTable(
"for_sort_specs_only", 2, table_flags_for_sort_specs,
54 ImVec2(0.0f, GetFrameHeight()))) {
55 TableSetupColumn(
"Index");
56 TableSetupColumn(
"Type");
58 if (ImGuiTableSortSpecs* sort_specs = TableGetSortSpecs())
68 ImGuiIO& io = GetIO();
69 SetNextWindowContentSize(ImVec2(
72 if (BeginChild(
"Assets", ImVec2(0.0f, -GetTextLineHeightWithSpacing()),
73 ImGuiChildFlags_Border, ImGuiWindowFlags_NoMove)) {
74 ImDrawList* draw_list = GetWindowDrawList();
76 const float avail_width = GetContentRegionAvail().x;
80 ImVec2 start_pos = GetCursorScreenPos();
83 SetCursorScreenPos(start_pos);
86 ImGuiMultiSelectFlags ms_flags = ImGuiMultiSelectFlags_ClearOnEscape |
87 ImGuiMultiSelectFlags_ClearOnClickVoid;
96 ms_flags |= ImGuiMultiSelectFlags_SelectOnClickRelease;
105 ms_flags |= ImGuiMultiSelectFlags_NavWrapX;
107 ImGuiMultiSelectIO* ms_io =
112 Selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self_,
115 return self->
Items[idx].ID;
119 const bool want_delete =
120 (Shortcut(ImGuiKey_Delete, ImGuiInputFlags_Repeat) &&
123 const int item_curr_idx_to_focus =
135 PushStyleVar(ImGuiStyleVar_ItemSpacing,
139 const ImU32 icon_type_overlay_colors[5] = {
140 0, IM_COL32(200, 70, 70, 255), IM_COL32(70, 170, 70, 255),
141 IM_COL32(70, 70, 200, 255), IM_COL32(200, 200, 200, 255)};
142 const ImU32 icon_bg_color = GetColorU32(ImGuiCol_MenuBarBg);
143 const ImVec2 icon_type_overlay_size = ImVec2(5.0f, 5.0f);
144 const bool display_label = (
LayoutItemSize.x >= CalcTextSize(
"999").x);
147 ImGuiListClipper clipper;
151 if (item_curr_idx_to_focus != -1)
152 clipper.IncludeItemByIndex(item_curr_idx_to_focus / column_count);
155 if (ms_io->RangeSrcItem != -1)
156 clipper.IncludeItemByIndex((
int)ms_io->RangeSrcItem / column_count);
158 while (clipper.Step()) {
159 for (
int line_idx = clipper.DisplayStart; line_idx < clipper.DisplayEnd;
161 const int item_min_idx_for_current_line = line_idx * column_count;
162 const int item_max_idx_for_current_line =
164 for (
int item_idx = item_min_idx_for_current_line;
165 item_idx < item_max_idx_for_current_line; ++item_idx) {
167 PushID((
int)item_data->
ID);
171 ImVec2(start_pos.x + (item_idx % column_count) *
LayoutItemStep.x,
173 SetCursorScreenPos(pos);
175 SetNextItemSelectionUserData(item_idx);
176 bool item_is_selected =
Selection.Contains((ImGuiID)item_data->
ID);
178 Selectable(
"", item_is_selected, ImGuiSelectableFlags_None,
184 if (IsItemToggledSelection()) item_is_selected = !item_is_selected;
187 if (item_curr_idx_to_focus == item_idx) SetKeyboardFocusHere(-1);
190 if (BeginDragDropSource()) {
194 if (GetDragDropPayload() == NULL) {
195 ImVector<ImGuiID> payload_items;
198 if (!item_is_selected)
199 payload_items.push_back(item_data->
ID);
201 while (
Selection.GetNextSelectedItem(&it, &
id))
202 payload_items.push_back(
id);
203 SetDragDropPayload(
"ASSETS_BROWSER_ITEMS", payload_items.Data,
204 (
size_t)payload_items.size_in_bytes());
210 const ImGuiPayload* payload = GetDragDropPayload();
211 const int payload_count =
212 (int)payload->DataSize / (
int)
sizeof(ImGuiID);
213 Text(
"%d assets", payload_count);
222 if (item_is_visible) {
223 ImVec2 box_min(pos.x - 1, pos.y - 1);
226 draw_list->AddRectFilled(box_min, box_max,
230 ImU32 label_col = GetColorU32(
231 item_is_selected ? ImGuiCol_Text : ImGuiCol_TextDisabled);
233 (ImTextureID)(intptr_t)bmp_manager[item_data->
ID].texture(),
234 box_min, box_max, ImVec2(0, 0), ImVec2(1, 1),
235 GetColorU32(ImVec4(1, 1, 1, 1)));
236 draw_list->AddText(ImVec2(box_min.x, box_max.y - GetFontSize()),
238 absl::StrFormat(
"%X", item_data->
ID).c_str());
241 ImU32 type_col = icon_type_overlay_colors
242 [item_data->
Type % IM_ARRAYSIZE(icon_type_overlay_colors)];
243 draw_list->AddRectFilled(
244 ImVec2(box_max.x - 2 - icon_type_overlay_size.x,
246 ImVec2(box_max.x - 2,
247 box_min.y + 2 + icon_type_overlay_size.y),
260 if (BeginPopupContextWindow()) {
261 Text(
"Selection: %d items",
Selection.Size);
263 if (BeginMenu(
"Set Type")) {
264 if (MenuItem(
"Unsorted")) {
267 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 0;
269 if (MenuItem(
"Dungeon")) {
272 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 1;
274 if (MenuItem(
"Overworld")) {
277 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 2;
279 if (MenuItem(
"Sprite")) {
282 while (
Selection.GetNextSelectedItem(&it, &
id))
Items[id].Type = 3;
287 if (MenuItem(
"Delete",
"Del",
false,
Selection.Size > 0))
292 ms_io = EndMultiSelect();
299 if (IsWindowHovered() && io.MouseWheel != 0.0f &&
300 IsKeyDown(ImGuiMod_Ctrl) && IsAnyItemActive() ==
false) {
306 const float hovered_item_nx =
309 const float hovered_item_ny =
312 const int hovered_item_idx =
329 float hovered_item_rel_pos_y =
331 fmodf(hovered_item_ny, 1.0f)) *
333 hovered_item_rel_pos_y += GetStyle().WindowPadding.y;
334 float mouse_local_y = io.MousePos.y - GetWindowPos().y;
335 SetScrollY(hovered_item_rel_pos_y - mouse_local_y);