bg_window

This commit is contained in:
timerix 2023-04-01 05:31:19 +06:00
parent 5dd4da0e30
commit 20d662424e
4 changed files with 48 additions and 21 deletions

36
src/gui/bg_window.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "gui_internal.hpp"
void draw_bg_window(){
const ImGuiDockNodeFlags dockspace_flags =
ImGuiDockNodeFlags_PassthruCentralNode;
const ImGuiWindowFlags window_flags =
ImGuiWindowFlags_MenuBar |
ImGuiWindowFlags_NoDocking |
ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoScrollWithMouse |
ImGuiWindowFlags_NoBringToFrontOnFocus |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoBackground;
// not dockable window that always bound to viewport
ImGuiViewport* viewport = ImGui::GetWindowViewport();
ImGui::SetNextWindowPos(viewport->Pos, ImGuiCond_Always);
ImGui::SetNextWindowSize(viewport->Size, ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("bg_window", nullptr, window_flags);
ImGui::PopStyleVar(3);
// DockSpace
ImGuiID dockspace_id = ImGui::GetID("bg_dockspace");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
// MenuBar
//TODO
ImGui::End();
}

View File

@ -1,14 +1,15 @@
#include "gui_internal.hpp" #include "gui_internal.hpp"
bool show_demo_window = true; bool show_demo_window = true;
bool show_another_window = false; bool show_metrics_window = true;
Maybe demo_ui_draw(ImGuiIO& io){ void draw_demo_windows(ImGuiIO& io){
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
if (show_demo_window) if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window); ImGui::ShowDemoWindow(&show_demo_window);
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. if (show_metrics_window)
ImGui::ShowMetricsWindow(&show_metrics_window);
{ {
static float f = 0.0f; static float f = 0.0f;
static int counter = 0; static int counter = 0;
@ -17,7 +18,7 @@ Maybe demo_ui_draw(ImGuiIO& io){
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
ImGui::Checkbox("Another Window", &show_another_window); ImGui::Checkbox("Metrics/Debug Window", &show_metrics_window);
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
@ -30,16 +31,4 @@ Maybe demo_ui_draw(ImGuiIO& io){
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End(); ImGui::End();
} }
// 3. Show another simple window.
if (show_another_window)
{
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}
return MaybeNull;
} }

View File

@ -12,4 +12,5 @@ extern ImVec4 clear_color; // background color for main window
/// @brief frees all allocated resources /// @brief frees all allocated resources
void main_window_destroy(); void main_window_destroy();
Maybe demo_ui_draw(ImGuiIO&); void draw_demo_windows(ImGuiIO&);
void draw_bg_window();

View File

@ -46,10 +46,10 @@ Maybe main_window_open(const char* window_title){
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows // io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
io.ConfigDockingTransparentPayload = true; io.ConfigDockingTransparentPayload = true;
io.ConfigInputTextCursorBlink = false; io.ConfigInputTextCursorBlink = false;
io.ConfigViewportsNoTaskBarIcon = true; // io.ConfigViewportsNoTaskBarIcon = true;
io.ConfigWindowsMoveFromTitleBarOnly = true; io.ConfigWindowsMoveFromTitleBarOnly = true;
// Setup Dear ImGui style // Setup Dear ImGui style
@ -113,7 +113,8 @@ Maybe draw_frame(){
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
// Draw UI // Draw UI
try_cpp(demo_ui_draw(io), _5218, ;); draw_bg_window();
draw_demo_windows(io);
// Rendering // Rendering
ImGui::Render(); ImGui::Render();