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

Potential new feature: Maximize/Restore button for window #2104

Open
DJLink opened this issue Sep 26, 2018 · 8 comments
Open

Potential new feature: Maximize/Restore button for window #2104

DJLink opened this issue Sep 26, 2018 · 8 comments

Comments

@DJLink
Copy link
Contributor

DJLink commented Sep 26, 2018


**Version/Branch of Dear ImGui: 1.66 WIP

My Issue/Question: Hi, while building/using my editor I sometimes felt the need to quickly maximize a imgui window to the full size of the window, so I did a few hacks to get a button next to the close one. Got it working, also stores the last position/size at the moment maximize is called so when button is pressed again it will restore the last settings. This is not being saved when restoring a session so might be some side effects, but not sure if we really want that.

I pushed a code to a repo so anyone can take a look. Feel free to suggest changes to both the way it works or the code.

Link to code: https://github.com/DJLink/imgui/commit/d1fd4909b869e8b50a0519864ba515b9cc2902cb

For now it works on request only, so user has to pass a flag to ImGui::Begin(), like this. It will detect for the presence of ImGuiWindowFlags_NoResize, in which case it never shows even with ImGuiWindowFlags_MaximizeButton present.

ImGui::Begin("windows",&_isVisible, ImGuiWindowFlags_MaximizeButton)

Screenshots/Video
imgui_maximize_button2

@DJLink
Copy link
Contributor Author

DJLink commented Sep 27, 2018

I was making a few more tests and I'm unsure of a certain scenario.

Right now after maximizing, the Resize handle on bottom right corner still shows and will allow resize. It doesn't necessary break anything but my question is, which one of the following would be more suitable:

    • Disable resize & handle when "maximized", ie Windows OS does this, only way is to press Max button again. This would probably mean to store value between session and can maybe lead to other issues too.
    • Still allow it and next time user presses maximize again it will restore to state it was before maximize happen (pretty much how it is right now)
    • allow resize but clear Maximized flag, so when button pressed it will maximize to full screen again and store that new resized value as the restore one.

Opinions are appreciated, would like to hear @ocornut (sorry for ping) opinion on this.

@ocornut
Copy link
Owner

ocornut commented Sep 27, 2018

Sorry won't have time to look at this in details right away but it is interesting.

Quick notes:

  • One property of "Maximized" state is that is the underlying display change sizes, the window could follow.

  • The pos/size to restore could be persistent (maybe only saved if the window is maximized, otherwise we don't spam the ini file with both copies of the pos/size)... One possible way to do is that when Maximized is true we store PosRestore/SizeRestore in the .ini file instead of Pos/SizeFull. We also need to store Maximized=true (and maybe skip it when false). This way neither ImGuiWindowSettings or the .ini file gets more crowded apart from the extra bool.

  • As for your options, I think "Disable resize" may be the right way, and we'll need to store the Maximized bool in ImGuiWindowSettings and .ini file anyway..

  • But that can't work with _NoTitleBar, so when _NoTitleBar is set we cancel out the Maximized options.

  • I'm not totally sure about adding a ImGuiWindowFlags_MaximizeButton flag, part of me thinks we should transition this sort of thing to global config/style settings, and perhaps add a ImGuiWindowFlags_NoMaximize flag instead. Part of me also not sure about crowding the default ui becoming very OS-ey. There are larger design decision to make.

  • If you consider mimicking the IsWindowCollapsed()/SetWindowCollapsed() API with equivalent for Maximized, it means the user can also perfectly create a title bar context menu and provide this option in the context menu. That's another possibility.

@DJLink
Copy link
Contributor Author

DJLink commented Oct 6, 2018

Hi, sorry for the delay answering, and thank you for your comment. I've been taking a look at more code as I'm not super familiar with imgui internally, mostly only from a using standpoint.

1 - Makes sense, and should be doable, when detecting a window is maximized and changes to display just update the size.

2- I like this, worse case scenario we only write the bool. Alternative would be not to save any bool and to detect if window is maximized and save the restore value instead. This way when session restarts window would not be maximized. While this breaks the "remember all positions and sizes" it's a specific case of a maximized window, user just had to press it maximize again. Maybe not a good idea, just throwing the idea.

3 - Agree
4 - Agree

5 - So in the case of a ImGuiWindowFlags_NoMaximize the default would be to show the maximize button?

6 - this could work, I'll run some tests with this too

@rg-net
Copy link

rg-net commented Dec 10, 2018

@ocornut Another thing we need to consider is how this works in concert with the dockable solution. While in theory these controls are not exposed for the windows. In practice someone will inadvertently find a way to maximize while docked. Need to make sure that the persistence is going to work as expected with that scenario as well.

@HowardZorn
Copy link

Thanks for inspiring! I'm writing a demo program with GUI for my course(Data Structure) project. This enhancement helps me a lot.

@chrxh
Copy link

chrxh commented May 6, 2023

Hi, the link https://github.com/DJLink/imgui/commit/d1fd4909b869e8b50a0519864ba515b9cc2902cb does not work anymore.
I would also need this feature. Is the code somewhere available?
Thanks!

@DJLink
Copy link
Contributor Author

DJLink commented May 6, 2023

Hi, the link https://github.com/DJLink/imgui/commit/d1fd4909b869e8b50a0519864ba515b9cc2902cb does not work anymore. I would also need this feature. Is the code somewhere available? Thanks!

I don't recall deleting the repo but it doesn't exist anymore, so I guess I did, sorry. I must have the source somewhere in one of my projects but I'll have to look into my old computer to see if where it's at, if at all. It's been a couple years sorry

@chrxh
Copy link

chrxh commented May 6, 2023

I don't recall deleting the repo but it doesn't exist anymore, so I guess I did, sorry. I must have the source somewhere in one of my projects but I'll have to look into my old computer to see if where it's at, if at all. It's been a couple years sorry

I see. If you find it, it would be nice to share the code. Otherwise I will have to write it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants