14 const std::array<gfx::Bitmap, zelda3::kNumGfxSheets>& bmp_manager) {
15 PushItemWidth(GetFontSize() * 10);
27 SliderFloat(tr(
"Icon Size"), &
IconSize, 16.0f, 128.0f,
"%.0f");
35 static bool filter_type[4] = {
true,
true,
true,
true};
36 Text(tr(
"Filter by type:"));
38 Checkbox(tr(
"Unsorted"), &filter_type[0]);
40 Checkbox(tr(
"Dungeon"), &filter_type[1]);
42 Checkbox(tr(
"Overworld"), &filter_type[2]);
44 Checkbox(tr(
"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_Borders, 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;
92 ms_flags |= ImGuiMultiSelectFlags_BoxSelect2d;
97 ms_flags |= ImGuiMultiSelectFlags_SelectOnClickRelease;
106 ms_flags |= ImGuiMultiSelectFlags_NavWrapX;
108 ImGuiMultiSelectIO* ms_io =
113 Selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self_,
116 return self->
Items[idx].ID;
120 const bool want_delete =
121 (
Shortcut(ImGuiKey_Delete, ImGuiInputFlags_Repeat) &&
124 const int item_curr_idx_to_focus =
136 PushStyleVar(ImGuiStyleVar_ItemSpacing,
140 const ImU32 icon_type_overlay_colors[5] = {
141 0, IM_COL32(200, 70, 70, 255), IM_COL32(70, 170, 70, 255),
142 IM_COL32(70, 70, 200, 255), IM_COL32(200, 200, 200, 255)};
143 const ImU32 icon_bg_color = GetColorU32(ImGuiCol_MenuBarBg);
144 const ImVec2 icon_type_overlay_size = ImVec2(5.0f, 5.0f);
145 const bool display_label = (
LayoutItemSize.x >= CalcTextSize(
"999").x);
148 ImGuiListClipper clipper;
152 if (item_curr_idx_to_focus != -1)
153 clipper.IncludeItemByIndex(item_curr_idx_to_focus / column_count);
156 if (ms_io->RangeSrcItem != -1)
157 clipper.IncludeItemByIndex((
int)ms_io->RangeSrcItem / column_count);
159 while (clipper.Step()) {
160 for (
int line_idx = clipper.DisplayStart; line_idx < clipper.DisplayEnd;
162 const int item_min_idx_for_current_line = line_idx * column_count;
163 const int item_max_idx_for_current_line =
165 for (
int item_idx = item_min_idx_for_current_line;
166 item_idx < item_max_idx_for_current_line; ++item_idx) {
168 PushID((
int)item_data->
ID);
172 ImVec2(start_pos.x + (item_idx % column_count) *
LayoutItemStep.x,
174 SetCursorScreenPos(pos);
176 SetNextItemSelectionUserData(item_idx);
177 bool item_is_selected =
Selection.Contains((ImGuiID)item_data->
ID);
179 Selectable(
"", item_is_selected, ImGuiSelectableFlags_None,
185 if (IsItemToggledSelection())
186 item_is_selected = !item_is_selected;
189 if (item_curr_idx_to_focus == item_idx)
190 SetKeyboardFocusHere(-1);
193 if (BeginDragDropSource()) {
197 if (GetDragDropPayload() == NULL) {
198 ImVector<ImGuiID> payload_items;
201 if (!item_is_selected)
202 payload_items.push_back(item_data->
ID);
204 while (
Selection.GetNextSelectedItem(&it, &
id))
205 payload_items.push_back(
id);
206 SetDragDropPayload(
"ASSETS_BROWSER_ITEMS", payload_items.Data,
207 (
size_t)payload_items.size_in_bytes());
213 const ImGuiPayload* payload = GetDragDropPayload();
214 const int payload_count =
215 (int)payload->DataSize / (
int)
sizeof(ImGuiID);
216 Text(tr(
"%d assets"), payload_count);
225 if (item_is_visible) {
226 ImVec2 box_min(pos.x - 1, pos.y - 1);
229 draw_list->AddRectFilled(box_min, box_max,
233 ImU32 label_col = GetColorU32(
234 item_is_selected ? ImGuiCol_Text : ImGuiCol_TextDisabled);
236 (ImTextureID)(intptr_t)bmp_manager[item_data->
ID].texture(),
237 box_min, box_max, ImVec2(0, 0), ImVec2(1, 1),
238 GetColorU32(ImVec4(1, 1, 1, 1)));
239 draw_list->AddText(ImVec2(box_min.x, box_max.y - GetFontSize()),
241 absl::StrFormat(
"%X", item_data->
ID).c_str());
244 ImU32 type_col = icon_type_overlay_colors
245 [item_data->
Type % IM_ARRAYSIZE(icon_type_overlay_colors)];
246 draw_list->AddRectFilled(
247 ImVec2(box_max.x - 2 - icon_type_overlay_size.x,
249 ImVec2(box_max.x - 2,
250 box_min.y + 2 + icon_type_overlay_size.y),
263 if (BeginPopupContextWindow()) {
264 Text(tr(
"Selection: %d items"),
Selection.Size);
266 if (BeginMenu(tr(
"Set Type"))) {
267 if (MenuItem(tr(
"Unsorted"))) {
270 while (
Selection.GetNextSelectedItem(&it, &
id))
273 if (MenuItem(tr(
"Dungeon"))) {
276 while (
Selection.GetNextSelectedItem(&it, &
id))
279 if (MenuItem(tr(
"Overworld"))) {
282 while (
Selection.GetNextSelectedItem(&it, &
id))
285 if (MenuItem(tr(
"Sprite"))) {
288 while (
Selection.GetNextSelectedItem(&it, &
id))
294 if (MenuItem(tr(
"Delete"),
"Del",
false,
Selection.Size > 0))
299 ms_io = EndMultiSelect();
305 if (IsWindowAppearing())
307 if (IsWindowHovered() && io.MouseWheel != 0.0f &&
308 IsKeyDown(ImGuiMod_Ctrl) && IsAnyItemActive() ==
false) {
314 const float hovered_item_nx =
317 const float hovered_item_ny =
320 const int hovered_item_idx =
337 float hovered_item_rel_pos_y =
339 fmodf(hovered_item_ny, 1.0f)) *
341 hovered_item_rel_pos_y += GetStyle().WindowPadding.y;
342 float mouse_local_y = io.MousePos.y - GetWindowPos().y;
343 SetScrollY(hovered_item_rel_pos_y - mouse_local_y);