MCPcopy Create free account
hub / github.com/chrxh/alien / FolderNode

Function FolderNode

external/ImFileDialog/ImFileDialog.cpp:35–75  ·  view source on GitHub ↗

UI CONTROLS */

Source from the content-addressed store, hash-verified

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

Callers 1

m_renderTreeMethod · 0.85

Calls 1

ImVec2Class · 0.85

Tested by

no test coverage detected