Comments (5)
I'm so sorry.
I understand what you mean.
Every time there is some thing I miss.
It's just that I still don't fully understand what the internal architecture of ImGui is.
So I by doing this:
if(ImGui::BeginMainMenuBar()) {
if(ImGui::BeginMenu("File")) {
ImGui::MenuItem("About", NULL, false, true);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
I was already defining a menu in the "main" window.
So actually by putting this flag ImGuiWindowFlags_MenuBar
I was adding another menu in the window that I was creating below
I was sure that putting ImGuiWindowFlags_MenuBar
was to put the menu in the window I was creating here:
ImGui::Begin("MainWindow", NULL, windowFlags);
And that this was the code that was needed to make it work.
if(ImGui::BeginMainMenuBar()) {
if(ImGui::BeginMenu("File")) {
ImGui::MenuItem("About", NULL, false, true);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
Anyway here is the complete corrected code.
thank you very much again.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui/imgui.hpp>
static void glfwErrorCallback(int error, const char * description) {
fprintf(stderr, "GLFW error (%d): %s\n", error, description);
}
int main(int argc, const char * argv[]) {
if(!glfwInit()) {
fprintf(stderr, "GLFW init error\n");
exit(EXIT_FAILURE);
}
#if __APPLE__
const char* glsl_version = "#version 100";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#else
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif
glfwSetErrorCallback(glfwErrorCallback);
GLFWwindow * window = glfwCreateWindow(640, 480, "ImGui", NULL, NULL);
if(!window) {
glfwTerminate();
abort();
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
if(!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) abort();
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
ImGui::StyleColorsDark();
while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGuiViewport * viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->WorkPos);
ImGui::SetNextWindowSize(viewport->WorkSize);
ImGui::SetNextWindowViewport(viewport->ID);
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoMove;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("MainWindow", NULL, windowFlags);
ImGui::PopStyleVar();
if(ImGui::BeginMainMenuBar()) {
if(ImGui::BeginMenu("File")) {
ImGui::MenuItem("About", NULL, false, true);
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
float heightSideBar = ImGui::GetFrameHeight();
if(ImGui::BeginViewportSideBar("StatusBar", viewport, ImGuiDir_Down, heightSideBar, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar)) {
if(ImGui::BeginMenuBar()) {
ImGui::Text("Status Bar:");
ImGui::EndMenuBar();
}
ImGui::End();
}
// right part red
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImColor(255,0,0).Value);
ImGui::BeginChild("3", ImVec2(0, 0), true);
ImGui::PopStyleColor();
ImGui::EndChild();
ImGui::End();
ImGui::Render();
int displayW, displayH;
glfwGetFramebufferSize(window, &displayW, &displayH);
glViewport(0, 0, displayW, displayH);
static ImVec4 clearColor = ImColor(60, 55, 15);
glClearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
from imgui.
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);
Your window is programmed to fill the entire viewport so thatβs what it does. Bringing to front makes it appear over those bars.
You should use viewport->WorkPos and viewport->WorkSize to avoid overlapping menu bars and side bars.
from imgui.
Hi @ocornut ,
thank you very much for the explanation.
I absolutely did not understand that was the problem.
I implemented what you suggested and indeed nothing disappears anymore.
What I don't understand is why the red part doesn't fill all the available space.
from imgui.
Because your red window also has a Menubar as you passed ImGuiWindowFlags_MenuBar to it.
from imgui.
Happy to help!
from imgui.
Related Issues (20)
- Win32 DirectX11 app resize resizes ImGui window HOT 1
- GLFW backend: PrevWndProc != NULL assertion fails on Windows HOT 2
- Unexpected output from DrawList->PathArcTo HOT 2
- SetKeyboardFocusHere(-1) not working as expected with InputTextMultiline
- TabBar - Common Style
- WebGPU backend causes crash after window resize HOT 1
- Table drawing Horizontal Scrollbar too far below HOT 3
- Vertical Misalignment when using different size fonts with AlignTextToFramePadding HOT 3
- ImDrawList's PushClipRect not inherited by child window HOT 3
- How can I set FULL window transparency HOT 1
- Detecting a mouse click HOT 6
- How to get resizable child in window? HOT 8
- CMake Support HOT 1
- I want know where is ImGuiLayout HOT 3
- Question: How to load state of docked windows HOT 11
- Locked on 62 / 63 fps in dx11 without Vsync HOT 1
- Change cursor when hand whenTextLink is hovered - Common Style HOT 1
- Touchpad tap to click not captured when io.ConfigInputTrickleEventQueue is false HOT 5
- Position inside child window when border width changes HOT 7
- Left upper corner coordinates and child window dimensions for different border thicknesses HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgui.