Skip to content

Instantly share code, notes, and snippets.

@rmitton
Created March 13, 2019 06:20
Show Gist options
  • Save rmitton/f80cbb028fca4495ab1859a155db4cd8 to your computer and use it in GitHub Desktop.
Save rmitton/f80cbb028fca4495ab1859a155db4cd8 to your computer and use it in GitHub Desktop.
How to do a toolbar in Dear ImGui.
// How to do a toolbar in Dear ImGui.
const float toolbarSize = 50;
void DockSpaceUI()
{
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos + ImVec2(0, toolbarSize));
ImGui::SetNextWindowSize(viewport->Size - ImVec2(0, toolbarSize));
ImGui::SetNextWindowViewport(viewport->ID);
ImGuiWindowFlags window_flags = 0
| ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking
| ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse
| ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
| ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::Begin("Master DockSpace", NULL, window_flags);
ImGuiID dockMain = ImGui::GetID("MyDockspace");
// Save off menu bar height for later.
menuBarHeight = ImGui::GetCurrentWindow()->MenuBarHeight();
ImGui::DockSpace(dockMain);
ImGui::End();
ImGui::PopStyleVar(3);
}
void ToolbarUI()
{
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + menuBarHeight));
ImGui::SetNextWindowSize(ImVec2(viewport->Size.x, toolbarSize));
ImGui::SetNextWindowViewport(viewport->ID);
ImGuiWindowFlags window_flags = 0
| ImGuiWindowFlags_NoDocking
| ImGuiWindowFlags_NoTitleBar
| ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoMove
| ImGuiWindowFlags_NoScrollbar
| ImGuiWindowFlags_NoSavedSettings
;
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::Begin("TOOLBAR", NULL, window_flags);
ImGui::PopStyleVar();
ImGui::Button("Toolbar goes here", ImVec2(0, 37));
ImGui::End();
}
void ProgramUI()
{
DockSpaceUI();
ToolbarUI();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment