Skip to content

Commit

Permalink
Initially hide the window / add appWindowParams.hidden
Browse files Browse the repository at this point in the history
(initially hidden so that initial positionning & resizing is invisible)
  • Loading branch information
pthom committed Feb 9, 2023
1 parent 59f41c0 commit d6af807
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
10 changes: 7 additions & 3 deletions src/hello_imgui/app_window_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ for details.
_Note: on a mobile device, the application will always be full screen._
* `restorePreviousGeometry`: _bool, default=false_.
If true, then save & restore windowGeometry from last run (the geometry will be written in imgui_app_window.ini)
* `borderless`: _bool, default = false_.
* `resizable`: _bool, default = false_.
@@md
* `borderless`: _bool, default = false_. Should the window have borders. This is taken into account at
creation.
* `resizable`: _bool, default = false_. Should the window have borders. This is taken into account at

This comment has been minimized.

Copy link
@dcnieho

dcnieho Feb 13, 2023

copy paste error in the comment

creation.
* `hidden`: _bool, default = false_. Should the window be hidden. This is taken into account dynamically (you
can show/hide the window with this). Full screen windows cannot be hidden.@@md
**/
struct AppWindowParams
{
Expand All @@ -167,6 +170,7 @@ struct AppWindowParams

bool borderless = false;
bool resizable = true;
bool hidden = false;
};

} // namespace HelloImGui
26 changes: 19 additions & 7 deletions src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <chrono>
#include <cassert>
#include <fstream>
#include <thread>

#ifdef HELLOIMGUI_MACOS
#import <AppKit/NSScreen.h>
Expand Down Expand Up @@ -406,7 +407,7 @@ void AbstractRunner::Setup()
}
}

void AbstractRunner::RenderGui()
void AbstractRunner::RenderGui()
{
DockingDetails::ProvideWindowOrDock(params.imGuiWindowParams, params.dockingParams);

Expand Down Expand Up @@ -443,13 +444,14 @@ void AbstractRunner::Setup()


void AbstractRunner::CreateFramesAndRender()
{
// Note about the application window sizing
// - On the first frame, we create a window, and use the user provided size (if provided)
// - On the second frame, we may multiply this size by the Dpi factor (if > 1), to handle windows and linux High DPI
{
// Note about the application window initial placement and sizing
// - On the first frame (mIdxFrame==0), we create a window, and use the user provided size (if provided). The window is initially hidden.
// - On the second frame (mIdxFrame == 1), we may multiply this size by the Dpi factor (if > 1), to handle windows and linux High DPI
// - At the end of the second frame, we measure the size of the widgets and use it as the application window size, if the user required auto size
// - At the begining of the third frame, we may apply the auto-size and recenter the window to the center of the monitor
// Argh...
// - At the beginning of the third frame (mIdxFrame==2 / mWasWindowAutoResizedOnPreviousFrame), we may apply the auto-size and recenter the window to the center of the monitor
// - At the 4th frame (mIdxFrame >= 3), we finally show the window
// Phew...

//
// Window size setup, etc:
Expand All @@ -461,6 +463,7 @@ void AbstractRunner::CreateFramesAndRender()
HandleDpiOnSecondFrame();
}


if (mWasWindowAutoResizedOnPreviousFrame)
{
// The window was resized on last frame
Expand All @@ -477,6 +480,15 @@ void AbstractRunner::CreateFramesAndRender()
params.appWindowParams.windowGeometry.resizeAppWindowAtNextFrame = false;
}


if (mIdxFrame >= 3)
{
if (params.appWindowParams.hidden)
mBackendWindowHelper->HideWindow(mWindow);
else
mBackendWindowHelper->ShowWindow(mWindow);
}

#ifndef __EMSCRIPTEN__
// Idling for non emscripten, where HelloImGui is responsible for the main loop.
// This form of idling will call WaitForEventTimeout(), which may call sleep():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace HelloImGui { namespace BackendApi
else
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);

This comment has been minimized.

Copy link
@dcnieho

dcnieho Feb 13, 2023

misread the code, ignore my comment please if it makes it into your inbox, i've deleted it here. This should do the trick for me!


// GLFW_SCALE_TO_MONITOR is set to false: we set manually the window size in screen coordinates,
// then AbstractRunner::MakeWindowSizeRelativeTo96Ppi_IfRequired() may resize the window at the second frame
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ namespace HelloImGui { namespace BackendApi
else if (appWindowParams.windowGeometry.windowSizeState == WindowSizeState::Maximized)
window_flags |= SDL_WINDOW_MAXIMIZED;

window_flags |= SDL_WINDOW_HIDDEN;

auto window = SDL_CreateWindow(appWindowParams.windowTitle.c_str(),
window_pos_sdl[0], window_pos_sdl[1],
windowSize[0], windowSize[1],
Expand Down Expand Up @@ -220,11 +222,11 @@ namespace HelloImGui { namespace BackendApi

void SdlWindowHelper::HideWindow(WindowPointer window)
{
SDL_ShowWindow((SDL_Window *) window);
SDL_HideWindow((SDL_Window *) window);
}
void SdlWindowHelper::ShowWindow(WindowPointer window)
{
SDL_HideWindow((SDL_Window *) window);
SDL_ShowWindow((SDL_Window *) window);
}
bool SdlWindowHelper::IsWindowHidden(WindowPointer window)
{
Expand Down

0 comments on commit d6af807

Please sign in to comment.