UI CONTROLS */
| 30 | namespace ifd { |
| 31 | /* UI CONTROLS */ |
| 32 | bool FolderNode(const char* label, ImTextureID icon, bool& clicked) |
| 33 | { |
| 34 | ImGuiContext& g = *GImGui; |
| 35 | ImGuiWindow* window = g.CurrentWindow; |
| 36 | |
| 37 | clicked = false; |
| 38 | |
| 39 | ImU32 id = window->GetID(label); |
| 40 | int opened = window->StateStorage.GetInt(id, 0); |
| 41 | ImVec2 pos = window->DC.CursorPos; |
| 42 | const bool is_mouse_x_over_arrow = (g.IO.MousePos.x >= pos.x && g.IO.MousePos.x < pos.x + g.FontSize); |
| 43 | if (ImGui::InvisibleButton(label, ImVec2(-FLT_MIN, g.FontSize + g.Style.FramePadding.y * 2))) |
| 44 | { |
| 45 | if (is_mouse_x_over_arrow) { |
| 46 | int* p_opened = window->StateStorage.GetIntRef(id, 0); |
| 47 | opened = *p_opened = !*p_opened; |
| 48 | } else { |
| 49 | clicked = true; |
| 50 | } |
| 51 | } |
| 52 | bool hovered = ImGui::IsItemHovered(); |
| 53 | bool active = ImGui::IsItemActive(); |
| 54 | bool doubleClick = ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left); |
| 55 | if (doubleClick && hovered) { |
| 56 | int* p_opened = window->StateStorage.GetIntRef(id, 0); |
| 57 | opened = *p_opened = !*p_opened; |
| 58 | clicked = false; |
| 59 | } |
| 60 | if (hovered || active) |
| 61 | window->DrawList->AddRectFilled(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max, ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[active ? ImGuiCol_HeaderActive : ImGuiCol_HeaderHovered])); |
| 62 | |
| 63 | // Icon, text |
| 64 | float icon_posX = pos.x + g.FontSize + g.Style.FramePadding.y; |
| 65 | float text_posX = icon_posX + g.Style.FramePadding.y + ICON_SIZE; |
| 66 | ImGui::RenderArrow(window->DrawList, ImVec2(pos.x, pos.y+g.Style.FramePadding.y), ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[((hovered && is_mouse_x_over_arrow) || opened) ? ImGuiCol_Text : ImGuiCol_TextDisabled]), opened ? ImGuiDir_Down : ImGuiDir_Right); |
| 67 | window->DrawList->AddImage(icon, ImVec2(icon_posX, pos.y), ImVec2(icon_posX + ICON_SIZE, pos.y + ICON_SIZE)); |
| 68 | ImGui::RenderText(ImVec2(text_posX, pos.y + g.Style.FramePadding.y), label); |
| 69 | if (opened) |
| 70 | ImGui::TreePush(label); |
| 71 | return opened != 0; |
| 72 | } |
| 73 | bool FileNode(const char* label, ImTextureID icon) { |
| 74 | ImGuiContext& g = *GImGui; |
| 75 | ImGuiWindow* window = g.CurrentWindow; |