Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window layout, order #4476

Closed
kfsone opened this issue Aug 24, 2021 · 2 comments
Closed

Window layout, order #4476

kfsone opened this issue Aug 24, 2021 · 2 comments

Comments

@kfsone
Copy link
Contributor

kfsone commented Aug 24, 2021

"Give a man a fish, feed him for a day; give a man a demo, feed everyone"
-- Albert Einstein, on the Internet

The first thing I run into whenever creating a new imgui-based tool-ui is that windows are a bit messy on first open, and in several of my use cases that means permanently because I try to (have to) avoid creating the .ini files.

I recognize you can do this by setting some windows to NoFocusOnAppearing, but I have use cases where I want to specify one window should usurp all the other windows without having to locate and change every window's flags. SetForegroundMostWindow(window, ImGuiCond_FirstUseEver)?

The second is if there is a recommended way to encourage windows not to all appear overlapping each other (given enough space).

I've created a complete example under items/focus-window here https://github.com/kfsone/imgui-stuff/blob/main/items/focus-window/main.cpp

	constexpr ImGuiWindowFlags flags = ImGuiWindowFlags_NoSavedSettings;

	// Goal: Open 3 windows and avoid them overlapping, but if they must,
	// ensure that the first window is the one infront.
	// 
	// Could be done by making the second two windows NoFocusOnAppearing,
	// but that's not always either desirable or easy to pull off in a
	// particularly complex environment (think: scripted).
	//
	dear::Begin("Preferred Foreground Window", nullptr, flags) && []{
		ImGui::Text("This should be in front");
	};

	dear::Begin("Second Window") && []{
		ImGui::Text("Preferably not overlapping", nullptr, flags);
	};

	dear::Begin("Third Window") && []{
		ImGui::Text("Preferably not overlapping", nullptr, flags);
	};
@ocornut
Copy link
Owner

ocornut commented Aug 25, 2021

I try to (have to) avoid creating the .ini files.

I'd like to challenge this statement to make sure you aren't fighting against a XY Problem.
Why would you need to do that? Are you aware you can load/save from memory and therefore in location or form or your choice?

I recognize you can do this by setting some windows to NoFocusOnAppearing, but I have use cases where I want to specify one window should usurp all the other windows without having to locate and change every window's flags. SetForegroundMostWindow(window, ImGuiCond_FirstUseEver)?

You could call FocusWindow() at the end of the frame.
What we are expected to eventually support is restoring relative focus order for simultaneously reappearing windows (#2304, it's trickier than it sounds, I got 80% there and keep needing large rework).

The second is if there is a recommended way to encourage windows not to all appear overlapping each other (given enough space).

There's none presently. I don't think we would do that but one could come with a tool/algorithm that takes newly appearing window at the end of the frame (that didn't have settings), and position them. It would need to jump through some hoops to calculate the next window size ahead of the next-frame Begin(), by extracting some of the calls from Begin(), something like:

CalcWindowContentSizes(window, &content_size, &content_size_ideal);
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, content_size_ideal);
ImVec2 size_expected = CalcWindowSizeAfterConstraint(window, window->SizeFull);
// there we know the size

@ocornut ocornut changed the title [demo request] Window layout, order Window layout, order Aug 25, 2021
@kfsone
Copy link
Contributor Author

kfsone commented Aug 25, 2021

I try to (have to) avoid creating the .ini files.

I'd like to challenge this statement to make sure you aren't fighting against a XY Problem.
Why would you need to do that? Are you aware you can load/save from memory and therefore in location or form or your choice?

In the specific use case, I cannot yet any user-specific data - no config files, no ini files, etc, and if I do they're removed at the end of the session, but only after an unexpected files report gets mailed out and I get nagged :) So I have to make the saves noops :)

I recognize you can do this by setting some windows to NoFocusOnAppearing, but I have use cases where I want to specify one window should usurp all the other windows without having to locate and change every window's flags. SetForegroundMostWindow(window, ImGuiCond_FirstUseEver)?

You could call FocusWindow() at the end of the frame.
What we are expected to eventually support is restoring relative focus order for simultaneously reappearing windows (#2304, it's trickier than it sounds, I got 80% there and keep needing large rework).

The second is if there is a recommended way to encourage windows not to all appear overlapping each other (given enough space).

There's none presently. I don't think we would do that but one could come with a tool/algorithm that takes newly appearing window at the end of the frame (that didn't have settings), and position them. It would need to jump through some hoops to calculate the next window size ahead of the next-frame Begin(), by extracting some of the calls from Begin(), something like:

CalcWindowContentSizes(window, &content_size, &content_size_ideal);
ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, content_size_ideal);
ImVec2 size_expected = CalcWindowSizeAfterConstraint(window, window->SizeFull);
// there we know the size

Thanks -- I'll close this because the one actionable would be a demo of the relative focus, and you don't need a stand alone ticket for that :)

@kfsone kfsone closed this as completed Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants