| 279 | return ret; |
| 280 | } |
| 281 | bool FileIcon(const char* label, bool isSelected, ImTextureID icon, ImVec2 size, bool hasPreview, int previewWidth, int previewHeight) |
| 282 | { |
| 283 | ImGuiStyle& style = ImGui::GetStyle(); |
| 284 | ImGuiContext& g = *GImGui; |
| 285 | ImGuiWindow* window = g.CurrentWindow; |
| 286 | |
| 287 | float windowSpace = ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMax().x; |
| 288 | ImVec2 pos = window->DC.CursorPos; |
| 289 | bool ret = false; |
| 290 | |
| 291 | if (ImGui::InvisibleButton(label, size)) |
| 292 | ret = true; |
| 293 | |
| 294 | bool hovered = ImGui::IsItemHovered(); |
| 295 | bool active = ImGui::IsItemActive(); |
| 296 | bool doubleClick = ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left); |
| 297 | if (doubleClick && hovered) |
| 298 | ret = true; |
| 299 | |
| 300 | |
| 301 | float iconSize = size.y - g.FontSize * 2; |
| 302 | float iconPosX = pos.x + (size.x - iconSize) / 2.0f; |
| 303 | ImVec2 textSize = ImGui::CalcTextSize(label, 0, true, size.x); |
| 304 | |
| 305 | |
| 306 | if (hovered || active || isSelected) |
| 307 | window->DrawList->AddRectFilled(g.LastItemData.Rect.Min, g.LastItemData.Rect.Max, ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[active ? ImGuiCol_HeaderActive : (isSelected ? ImGuiCol_Header : ImGuiCol_HeaderHovered)])); |
| 308 | |
| 309 | if (hasPreview) { |
| 310 | ImVec2 availSize = ImVec2(size.x, iconSize); |
| 311 | |
| 312 | float scale = std::min<float>(availSize.x / previewWidth, availSize.y / previewHeight); |
| 313 | availSize.x = previewWidth * scale; |
| 314 | availSize.y = previewHeight * scale; |
| 315 | |
| 316 | float previewPosX = pos.x + (size.x - availSize.x) / 2.0f; |
| 317 | float previewPosY = pos.y + (iconSize - availSize.y) / 2.0f; |
| 318 | |
| 319 | window->DrawList->AddImage(icon, ImVec2(previewPosX, previewPosY), ImVec2(previewPosX + availSize.x, previewPosY + availSize.y)); |
| 320 | } else |
| 321 | window->DrawList->AddImage(icon, ImVec2(iconPosX, pos.y), ImVec2(iconPosX + iconSize, pos.y + iconSize)); |
| 322 | |
| 323 | window->DrawList->AddText(g.Font, g.FontSize, ImVec2(pos.x + (size.x-textSize.x) / 2.0f, pos.y + iconSize), ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_Text]), label, 0, size.x); |
| 324 | |
| 325 | |
| 326 | float lastButtomPos = ImGui::GetItemRectMax().x; |
| 327 | float thisButtonPos = lastButtomPos + style.ItemSpacing.x + size.x; // Expected position if next button was on same line |
| 328 | if (thisButtonPos < windowSpace) |
| 329 | ImGui::SameLine(); |
| 330 | |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | FileDialog::FileData::FileData(const std::filesystem::path& path) { |
| 335 | std::error_code ec; |