mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-06 19:03:50 +00:00
Modal Dialogs #249
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#249
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It would be nice to add an begin/end api pair to allow for Modal Dialogs that block inputs to anything else, waiting for and answer.
A gif is worth a thousand words ;)
I think this can be implemented with minor modifications to current functionality in many ways, but I'm not sure what's the best one (tooltips? Begin/EndPopup? Fullscreen window?).
This test gif has been done creating a fullscreen window (to mask the background AND block inputs to windows below) and a child window that contains the text+yes/no controls.
I've also done some hacks to calculate child windows minimum Y size.
Maybe I should use a second window with autosize for the actual dialog content instead of a child win.
Thoughts?
OT: this looks great !!!!
+1 for Modal Dialogs
+1 Yeah Modal Dialogs are a great addition!
Seems reasonably easy to implement.
(Nice colors, could you post your styke & font settings somewhere?)
Thanks @everyone for joining the discussion!
I really think that the closing EndDialog should give a few common presets (YesNo, OkCancel etc.) or a NoButtons if the user really wants to draw/handle the buttons him/herself.
In the last case he will signal the closing of dialog by setting selection var to 1 or some other known value.
ImGuiCol_ModalDarkening 👍 animating the alpha value makes it very nice looking!
The centring was my issue as well...I've done it so that during first frame I render with alpha ~ 0, just to calculate the dialog size, and from the next frame than I use it to center the child window.
I re-compute the Y size so in case something gets added (like shown in the gif) it will be adjusted in next frame (it's almost not noticeable at 60 fps...)
Some consideration goes for the centring of the buttons.
Regarding my settings:
Font is DroidSans from extra_fonts.
I'm using ttf icon fonts from http://fortawesome.github.io/Font-Awesome/icons/ and a couple of custom Button/CollapsingHeader functions that render the icon to left/right of text like described in #232
Thanks for the detail. I am working of it (the basic behaviour work but there's no darkening now so it can be confusing).
I called the main function BeginPopupModal() and not just BeginModal() to clarify that it is using the popup system and related popup functions are available.
Added darkening, added demo

Not sure what to do with the centering here. I made the modal windows center on screen at the time they first appear.
Is there a GetLastWindowWidth like method that could be used in a call to a
method like SetLastWindowPosition?
On Jun 23, 2015 3:33 PM, "omar" notifications@github.com wrote:
@adam4813 What are you trying to do exactly ?
You can use:
GetWindowWidth(); // current window
SetNextWindowPos/Size(); // set pos/size of upcoming window
I was throwing out a suggestion for centering.
On Jun 23, 2015 4:37 PM, "omar" notifications@github.com wrote:
You are right that it is missing some api to do it without juggling awkwardly with 'next window pos' and 'current window size'.
I will add optional name to the GetWindowPos/Size functions that would cover some more cases.
I like your api a lot more than my proposal, I will test it soon and reporting any inconsistency I may eventually found.
@ocornut your speed in implementing this one has been awesome 👍
+1 I will try out this very soonish :)
Not sure if it's a bug or wrong usage, posting here anyway.
The following code will cause a wrong Y centering.
Commenting the ImGui::TextWrapped solves the problem.
Yes it's an issue with TextWrapped it doesn't really work with always auto-resizing windows at the moment.
On frame 0 which isnt displayed, while the initial size is being calculated the window is still zero width so wrapped text takes lots of vertical place. Because the modal is centered only once it stays there. There's way around the issue with TextWrapped but not that I'm satisfied with yet. I can probably at least mitigate the problem.
Note that if you call SetNextWindowSize(400,0) prior to opening the dialog to enforce a width it should remove the issue.
Ok, I understand, not a big deal actually, it's just important to know, I can skip the wrapped text calls for the first frame if needed.
If you push an explicit width to wrap, e.g. PushTextWrapPos(400); Text(...)
it'll also work.
If anybody else tries the dialog let me know. I would like to package 1.41 shortly if possible.
I'm not sure yet what to do with TextWrapped() (it's a known problem for always-auto-resizing window) but I'll handle that separately.
@adam4813 I just remembered why functions like GetWindowPos/GetWindowSize etc. didn't allow to pass in a name. The reason is that I didn't know how to handle errors properly if the given name didn't match an existing window.
It's ok to assert on incorrect code but I don't really want to assert on incorrect data (or very rarely), especially here it's easy to imagine cases where a window doesn't already exist. I could return a default value for position/size (e.g. zero) but I don't fancy silent errors either. So I left that unsolved and didn't add this parameter to the functions even though as you pointed you it would be useful e.g. to manual center a window, without juggling with next/current window functions.
If I get to implement the ID collision mechanism I envision in the future perhaps imgui will have a non intrusive way to signal errors to the programmer and then it might be a good place to log in a warning in those cases.
It isn't a silent error if it is well documented that passing in a window
name that doesn't exist will result in a size of 0 or -1 or similar default
value.
On Jun 24, 2015 9:59 PM, "omar" notifications@github.com wrote:
That would be acceptable I suppose.
However just noticed that for pattern I was trying to cater for (GetWindowSize(name) followed by SetNextWindowPos) the named-get would necessarily fail on the first time the function is called (assuming the Begin is after SetNextWindowPos which makes sense). I think the named get are probably useful but I would like to identify a pattern where they are before just adding them, because right now we've got a functional SetPosCenter already.
A possibility left to do it without SetPosCenter (just because it is healthy to see if we can do it ourselves) is Begin, GetWindowSize (current), SetWindowPos() and that already works but it has a frame of lag hmm. Tricky. I'll put that aside and open a topic later if necessary. I know there's something fishy here but I don't have an immediate blocker to solve.
Closing this. Note about TextWrapped and name-based Get Pos/Size helpers added in todo list.