13 const std::array<gfx::Bitmap, zelda3::kNumGfxSheets>& bmp_manager) {
14 PushItemWidth(GetFontSize() * 10);
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;
91 ms_flags |= ImGuiMultiSelectFlags_BoxSelect2d;
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())
185 item_is_selected = !item_is_selected;
188 if (item_curr_idx_to_focus == item_idx)
189 SetKeyboardFocusHere(-1);
192 if (BeginDragDropSource()) {
196 if (GetDragDropPayload() == NULL) {
197 ImVector<ImGuiID> payload_items;
200 if (!item_is_selected)
201 payload_items.push_back(item_data->
ID);
203 while (
Selection.GetNextSelectedItem(&it, &
id))
204 payload_items.push_back(
id);
205 SetDragDropPayload(
"ASSETS_BROWSER_ITEMS", payload_items.Data,
206 (
size_t)payload_items.size_in_bytes());
212 const ImGuiPayload* payload = GetDragDropPayload();
213 const int payload_count =
214 (int)payload->DataSize / (
int)
sizeof(ImGuiID);
215 Text(
"%d assets", payload_count);
224 if (item_is_visible) {
225 ImVec2 box_min(pos.x - 1, pos.y - 1);
228 draw_list->AddRectFilled(box_min, box_max,
232 ImU32 label_col = GetColorU32(
233 item_is_selected ? ImGuiCol_Text : ImGuiCol_TextDisabled);
235 (ImTextureID)(intptr_t)bmp_manager[item_data->
ID].texture(),
236 box_min, box_max, ImVec2(0, 0), ImVec2(1, 1),
237 GetColorU32(ImVec4(1, 1, 1, 1)));
238 draw_list->AddText(ImVec2(box_min.x, box_max.y - GetFontSize()),
240 absl::StrFormat(
"%X", item_data->
ID).c_str());
243 ImU32 type_col = icon_type_overlay_colors
244 [item_data->
Type % IM_ARRAYSIZE(icon_type_overlay_colors)];
245 draw_list->AddRectFilled(
246 ImVec2(box_max.x - 2 - icon_type_overlay_size.x,
248 ImVec2(box_max.x - 2,
249 box_min.y + 2 + icon_type_overlay_size.y),
262 if (BeginPopupContextWindow()) {
263 Text(
"Selection: %d items",
Selection.Size);
265 if (BeginMenu(
"Set Type")) {
266 if (MenuItem(
"Unsorted")) {
269 while (
Selection.GetNextSelectedItem(&it, &
id))
272 if (MenuItem(
"Dungeon")) {
275 while (
Selection.GetNextSelectedItem(&it, &
id))
278 if (MenuItem(
"Overworld")) {
281 while (
Selection.GetNextSelectedItem(&it, &
id))
284 if (MenuItem(
"Sprite")) {
287 while (
Selection.GetNextSelectedItem(&it, &
id))
293 if (MenuItem(
"Delete",
"Del",
false,
Selection.Size > 0))
298 ms_io = EndMultiSelect();
304 if (IsWindowAppearing())
306 if (IsWindowHovered() && io.MouseWheel != 0.0f &&
307 IsKeyDown(ImGuiMod_Ctrl) && IsAnyItemActive() ==
false) {
313 const float hovered_item_nx =
316 const float hovered_item_ny =
319 const int hovered_item_idx =
336 float hovered_item_rel_pos_y =
338 fmodf(hovered_item_ny, 1.0f)) *
340 hovered_item_rel_pos_y += GetStyle().WindowPadding.y;
341 float mouse_local_y = io.MousePos.y - GetWindowPos().y;
342 SetScrollY(hovered_item_rel_pos_y - mouse_local_y);