@@ -130,6 +130,7 @@ AssetBrowser::DisplaySelectedFolder(const Util::String& filter)
130130 return AssetEditor::AssetType::None;
131131 }
132132 };
133+
133134 static const auto AddDragSourceForFileEntry = [](const FileEntry& file)
134135 {
135136 if (ImGui::BeginDragDropSource (ImGuiDragDropFlags_SourceAllowNullID))
@@ -139,11 +140,41 @@ AssetBrowser::DisplaySelectedFolder(const Util::String& filter)
139140 ImGui::EndDragDropSource ();
140141 }
141142 };
143+ static const ImGuiTableSortSpecs* s_sort_specs = nullptr ;
144+ static const auto SortEntryFunction = [this ](const uint& a, const uint& b) -> bool
145+ {
146+ n_assert (s_sort_specs != nullptr );
147+ // weirdness sort passes us 0 sometimes.
148+ if (!this ->files .Contains (a)|| !this ->files .Contains (b))
149+ {
150+ return false ;
151+ }
152+ const FileEntry& entryA = this ->files [a];
153+ const FileEntry& entryB = this ->files [b];
154+ const bool descending = s_sort_specs->Specs [0 ].SortDirection == ImGuiSortDirection_Descending ? true : false ;
155+
156+ if (s_sort_specs->SpecsCount != 1 )
157+ {
158+ return descending ^ (entryA.name < entryB.name );
159+ }
160+ switch (s_sort_specs->Specs [0 ].ColumnIndex )
161+ {
162+ case 0 :
163+ return descending ^ (entryA.name < entryB.name );
164+ case 1 :
165+ return descending ^ (entryA.size < entryB.size );
166+ case 2 :
167+ return descending ^ (entryA.modifiedTime < entryB.modifiedTime );
168+ default :
169+ return false ;
170+ }
171+ return false ;
172+ };
142173
143174 if (this ->activeFolder != -1 )
144175 {
145176 bool doubleClicked = false ;
146- const FileTreeNode& node = this ->nodes [this ->activeFolder ];
177+ FileTreeNode& node = this ->nodes [this ->activeFolder ];
147178 switch (this ->fileViewMode )
148179 {
149180 case FileViewMode::List:
@@ -173,14 +204,24 @@ AssetBrowser::DisplaySelectedFolder(const Util::String& filter)
173204 case FileViewMode::Details:
174205 {
175206 ImGui::BeginGroup ();
176- ImGui::Columns (3 );
177- ImGui::Text (" Name" );
178- ImGui::NextColumn ();
179- ImGui::Text (" Size" );
180- ImGui::NextColumn ();
181- ImGui::Text (" Modified" );
182- ImGui::NextColumn ();
183- ImGui::Separator ();
207+ ImGui::BeginTable (" ##filedetails" , 3 , ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings| ImGuiTableFlags_Sortable | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_RowBg);
208+ ImGui::TableSetupColumn (" Name" , ImGuiTableColumnFlags_DefaultSort);
209+ ImGui::TableSetupColumn (" Size" , ImGuiTableColumnFlags_WidthFixed);
210+ ImGui::TableSetupColumn (" Modified" , ImGuiTableColumnFlags_WidthFixed);
211+ ImGui::TableHeadersRow ();
212+
213+ if (ImGuiTableSortSpecs* sorts_specs = ImGui::TableGetSortSpecs ())
214+ if (sorts_specs->SpecsDirty && node.files .Size () > 1 )
215+ {
216+ if (sorts_specs->SpecsCount != 1 )
217+ {
218+ break ;
219+ }
220+ s_sort_specs = sorts_specs;
221+ std::sort (node.files .begin (), node.files .end (), SortEntryFunction);
222+ sorts_specs->SpecsDirty = false ;
223+ }
224+
184225 for (uint fileHash : node.files )
185226 {
186227 const FileEntry& file = this ->files [fileHash];
@@ -189,8 +230,8 @@ AssetBrowser::DisplaySelectedFolder(const Util::String& filter)
189230 {
190231 continue ;
191232 }
192- ImGui::PushID (fileHash );
193- ImGui::BeginGroup ();
233+ ImGui::TableNextRow ( );
234+ ImGui::TableNextColumn ();
194235 if (ImGui::Selectable (file.name .AsCharPtr (), &isSelected))
195236 {
196237 this ->activeFile = fileHash;
@@ -201,15 +242,13 @@ AssetBrowser::DisplaySelectedFolder(const Util::String& filter)
201242 doubleClicked = true ;
202243 }
203244 AddDragSourceForFileEntry (file);
204- ImGui::NextColumn ();
245+ ImGui::TableNextColumn ();
205246 ImGui::Text (" %d KB" , (int )(file.size / 1024 ));
206- ImGui::NextColumn ();
247+ ImGui::TableNextColumn ();
207248 Timing::CalendarTime cal = Timing::CalendarTime::FileTimeToSystemTime (file.modifiedTime );
208249 ImGui::Text (" %d-%d-%d %d:%d" , cal.GetYear (), cal.GetMonth (), cal.GetDay (), cal.GetHour (), cal.GetMinute ());
209- ImGui::EndGroup ();
210- ImGui::PopID ();
211- ImGui::NextColumn ();
212250 }
251+ ImGui::EndTable ();
213252 ImGui::EndGroup ();
214253 }
215254 break ;
0 commit comments