61 if (holder.getButtons().empty())
64 const ImVec2 &frameSize = holder.getButtons().front()->getBtnSize();
66 ImVec2 screenSize = ui::GetIO().DisplaySize;
73 ImVec2 nextOffset{0, 0};
77 windowSize = verticalMenu ? ImVec2(frameSize.x, frameFullWidth * (
float)holder.getButtons().size())
78 : ImVec2(frameFullWidth * (float)holder.getButtons().size(), frameSize.y);
80 switch (uiManager.buildMenuLayout())
83 nextOffset.y = -categoryOffset;
86 nextOffset.y = +categoryOffset;
89 nextOffset.x = categoryOffset;
92 nextOffset.x = -categoryOffset;
95 const auto &layout = uiManager.getLayouts()[
"BuildMenuButtons"];
97 ui::SetNextWindowPos(pos);
98 ui::SetNextWindowSize(windowSize);
101 ui::PushFont(layout.font);
102 ui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
103 ui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{0, 0});
104 ui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{0, 0});
105 ui::PushStyleVar(ImGuiStyleVar_ItemSpacing, itemSpacing);
111 ui::Begin(wId.c_str(), &open,
112 ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoScrollbar |
113 ImGuiWindowFlags_NoScrollWithMouse);
116 ui::PushClipRect(ImVec2{0, 0}, screenSize,
false);
121 std::array<char, 128> id_str = {0};
122 for (
auto btn : holder.getButtons())
124 snprintf(id_str.data(), 128,
"%s_%d", holder.getId().c_str(), ++idx);
126 ImVec2 imgPos{btn->m_destRect.x, btn->m_destRect.y};
127 ImVec2 imgSize{btn->m_destRect.z, btn->m_destRect.w};
130 ImGuiButtonFlags flags = btn->m_open ? ImGuiButtonFlags_ForcePressed : 0;
131 flags |= btn->m_background ? 0 : ImGuiButtonFlags_NoBackground;
133 if (ui::ImageButtonCt(btn->m_tex, flags, frameSize, imgPos, imgSize, btn->m_uv0, btn->m_uv1, -1, ImVec4(0, 0, 0, 0)))
135 btn->m_open = !btn->m_open;
140 if (ui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) && ui::GetHoveredTimer() > menu->
getTooltipDelay())
142 ui::SetTooltip(btn->getId().c_str());
146 if (btn->m_open && !btn->getButtons().empty())
149 const ImVec2 &nextFrameSize = btn->getButtons().front()->getBtnSize();
150 const float nextFrameFullWidth = (verticalMenu ? nextFrameSize.y : nextFrameSize.x) +
detail::getItemSpan(deep + 1);
151 const float nextCategoryOffset = (nextFrameFullWidth * (float)btn->getButtons().size()) / 2;
153 switch (uiManager.buildMenuLayout())
156 nextPos.x = ui::GetCursorScreenPos().x + ((float)(idx - 1) * frameFullWidth) - nextCategoryOffset + frameFullWidth / 2;
157 nextPos.y = pos.y - nextFrameFullWidth;
160 nextPos.x = ui::GetCursorScreenPos().x + ((float)(idx - 1) * frameFullWidth) - nextCategoryOffset + frameFullWidth / 2;
165 nextPos.y = ui::GetCursorScreenPos().y - nextCategoryOffset - frameFullWidth / 2;
168 nextPos.x = pos.x - nextFrameFullWidth;
169 nextPos.y = ui::GetCursorScreenPos().y - nextCategoryOffset - frameFullWidth / 2;
189 drawSubmenu(nextPos, frameSize.y + 10.f, *nextMenuLevel, menu, deep + 1);