MCPcopy Create free account
hub / github.com/dfranx/SHADERed / PathBox

Function PathBox

libs/misc/ImFileDialog.cpp:92–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90 return ret;
91 }
92 bool PathBox(const char* label, std::filesystem::path& path, char* pathBuffer, ImVec2 size_arg) {
93 ImGuiWindow* window = ImGui::GetCurrentWindow();
94 if (window->SkipItems)
95 return false;
96
97 bool ret = false;
98 const ImGuiID id = window->GetID(label);
99 int* state = window->StateStorage.GetIntRef(id, 0);
100
101 ImGui::SameLine();
102
103 ImGuiContext& g = *GImGui;
104 const ImGuiStyle& style = g.Style;
105 ImVec2 pos = window->DC.CursorPos;
106 ImVec2 uiPos = ImGui::GetCursorPos();
107 ImVec2 size = ImGui::CalcItemSize(size_arg, 200, GUI_ELEMENT_SIZE);
108 const ImRect bb(pos, pos + size);
109
110 // buttons
111 if (!(*state & 0b001)) {
112 ImGui::PushClipRect(bb.Min, bb.Max, false);
113
114 // background
115 bool hovered = g.IO.MousePos.x >= bb.Min.x && g.IO.MousePos.x <= bb.Max.x &&
116 g.IO.MousePos.y >= bb.Min.y && g.IO.MousePos.y <= bb.Max.y;
117 bool clicked = hovered && ImGui::IsMouseReleased(ImGuiMouseButton_Left);
118 bool anyOtherHC = false; // are any other items hovered or clicked?
119 window->DrawList->AddRectFilled(pos, pos + size, ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[(*state & 0b10) ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg]));
120
121 // fetch the buttons (so that we can throw some away if needed)
122 std::vector<std::string> btnList;
123 float totalWidth = 0.0f;
124 for (auto comp : path) {
125 std::string section = comp.u8string();
126 if (section.size() == 1 && (section[0] == '\\' || section[0] == '/'))
127 continue;
128
129 totalWidth += ImGui::CalcTextSize(section.c_str()).x + style.FramePadding.x * 2.0f + GUI_ELEMENT_SIZE;
130 btnList.push_back(section);
131 }
132 totalWidth -= GUI_ELEMENT_SIZE;
133
134
135 // UI buttons
136 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, ImGui::GetStyle().ItemSpacing.y));
137 ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
138 bool isFirstElement = true;
139 for (int i = 0; i < btnList.size(); i++) {
140 if (totalWidth > size.x - 30 && i != btnList.size() - 1) { // trim some buttons if there's not enough space
141 float elSize = ImGui::CalcTextSize(btnList[i].c_str()).x + style.FramePadding.x * 2.0f + GUI_ELEMENT_SIZE;
142 totalWidth -= elSize;
143 continue;
144 }
145
146 ImGui::PushID(i);
147 if (!isFirstElement) {
148 ImGui::ArrowButtonEx("##dir_dropdown", ImGuiDir_Right, ImVec2(GUI_ELEMENT_SIZE, GUI_ELEMENT_SIZE));
149 anyOtherHC |= ImGui::IsItemHovered() | ImGui::IsItemClicked();

Callers 1

m_renderFileDialogMethod · 0.85

Calls 2

sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected