Skip to content

Instantly share code, notes, and snippets.

@ITotalJustice
Created October 4, 2024 19:57
Show Gist options
  • Save ITotalJustice/5b017a66795890bd2467ad3ef248f2ae to your computer and use it in GitHub Desktop.
Save ITotalJustice/5b017a66795890bd2467ad3ef248f2ae to your computer and use it in GitHub Desktop.
hides menu bar when the area isn't hovered / selected.
void menubar() {
static float menubar_height = 30.0;
const auto& io = ImGui::GetIO();
const auto flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize;
const auto window_pos = ImVec2(0, 0);
const auto window_size = ImVec2(io.DisplaySize.x, menubar_height);
ImGui::SetNextWindowPos(window_pos);
ImGui::SetNextWindowSize(window_size);
ImGui::SetNextWindowBgAlpha(0);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0F);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0F);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0F);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0F);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, 0.0F);
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0,0));
ImGui::PushStyleVar(ImGuiStyleVar_TabRounding, 0.0F);
ImGui::Begin("##menubar", nullptr, flags);
{
ImGui::PopStyleVar(11);
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) || ImGui::IsWindowHovered(ImGuiFocusedFlags_RootAndChildWindows)) {
if (ImGui::BeginChild("##child", window_size, ImGuiChildFlags_None, flags | ImGuiWindowFlags_MenuBar)) {
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("File"))
{
menubar_tab_file(app);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Emulation", app->rom_loaded))
{
menubar_tab_emulation(app);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Options"))
{
menubar_tab_options(app);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Tools"))
{
menubar_tab_tools(app);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("View"))
{
menubar_tab_view(app);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help"))
{
menubar_tab_help(app);
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
}
ImGui::EndChild();
}
}
ImGui::End();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment