hoffstadt / hoffstadt/DearPyGui

A `normalview_viewport` or a `toggle_maximize_viewport` function

Open
#1,800 2 comments 1 reaction 0 assignees View on GitHub
state: pending type: improvement
Dominant language
C++
Stars
15.6k
Forks
783
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
Currently there is no set feature which allows for the viewport to return to it's original state after the function `dpg.maximize_viewport()` has been called.
It is however possible to store the position and size before the `dpg.maximize_viewport()` function is called, which can then be restored afterwards. Yet, in Windows (my OS), once a viewport has been maximized, there isn't a way to make windows aware of a "de-maximization" unless you manually drag or reshape the viewport. This makes toggling between the `dpg.maximize_viewport()` function and restoring the stored position and size impossible as Windows is unwilling to maximize a viewport which it thinks is already maximized

**Describe the solution you'd like**
I propose two possible solutions:
1. A toggle function called something like `dpg.toggle_viewport_maximize()` to be in line with the naming of `dpg.toggle_viewport_fullscreen()` which is a function that handles the state between maximized and normal, with a returning to size and position of before the maximization.
2. A "flush"-like function which makes windows aware of the return to a non maximized state. I personally believe this is a better solution as it would allow people to make custom window title bars which allow for more functionality like click dragging it to come back from a maximized state.

**Describe alternatives you've considered**
See above

**Additional context**
A currently working implementation is the following piece of code. On Windows (as this is the only OS I currently use), the toggle function doesn't work a second loop if the window stays at the same location. Ergo, a user doesn't manually move the Windows title bar around.
```python
import dearpygui.dearpygui as dpg

# define global variables to be used in the toggle function
maximized:bool = False
position:list
width:int
height:int

def toggle_function():
# use global variables
global maximized
global position
global width
global height

# When maximized the old values need to be set to the viewport again
if maximized:
# proposal: make some sort of function to make windows/any OS aware of the not maximized state
dpg.set_viewport_pos(position)
dpg.set_viewport_width(width)
dpg.set_viewport_height(height)

# Store the values for future use if we want to get back from maximize
else:
position = dpg.get_viewport_pos()
width = dpg.get_viewport_width()
height = dpg.get_viewport_height()

dpg.maximize_viewport()

# set the maximized state to the negative of the current state
# so on the next button click, this value can be used properly
maximized = not maximized
print(maximized)

dpg.create_context()
dpg.create_viewport(title='Maximize toggle', width=300, height=300)

with dpg.window(label="Maximize test window", tag="PrimaryWindow"):
dpg.add_text("Toggle Maximize Test")
dpg.add_button(label="Toggle me!", callback=toggle_function)

dpg.set_primary_window("PrimaryWindow", True)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.