-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
Modal Dialogs #249
Comments
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!
if(ImGui::CollapsingHeaderIcon("Images", ImGui_fa_camera))
{
if (ImGui::ButtonIcon("Live Image", ImGui_fa_camera))
ImGui::OpenDialog("test dialog");
if (ImGui::BeginDialog("test dialog", ImVec2((float)view->getWidth(), (float)view->getHeight())))
{
ImGui::TextWrapped("Are you sure you want to do this and this and that?");
ImGui::TextWrapped("Are you sure you want to do this and this and that?");
ImGui::TextWrapped("Are you sure you want to do this and this and that?");
static int currentItem = 0;
ImGui::Combo("Your choice", ¤tItem, "Item 1\0Item 2\0Item 3\0Item 4\0\0");
if (currentItem == 1)
{
ImGui::TextWrapped("Good choice!!");
ImGui::TextWrapped("Good choice!!");
ImGui::TextWrapped("Good choice!!");
}
int selection;
if (ImGui::EndDialog(ImGui::Dialog_YesNo, &selection))
{
if (selection == 0)
{
// Dialog Dismissed with YES (first item)
}
else
{
// Dialog Dismissed with NO (second item)
}
}
}
// other stuff
}
Regarding my settings: style.Colors[ImGuiCol_Text] = ImVec4(0.31f, 0.25f, 0.24f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f);
style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.68f, 0.68f, 0.68f, 0.00f);
style.Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.19f);
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.62f, 0.70f, 0.72f, 0.56f);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.95f, 0.33f, 0.14f, 0.47f);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.97f, 0.31f, 0.13f, 0.81f);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.42f, 0.75f, 1.00f, 0.53f);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.65f, 0.80f, 0.20f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.62f, 0.80f, 0.15f);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.39f, 0.64f, 0.80f, 0.30f);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.28f, 0.67f, 0.80f, 0.59f);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.25f, 0.48f, 0.53f, 0.67f);
style.Colors[ImGuiCol_ComboBg] = ImVec4(0.89f, 0.98f, 1.00f, 0.99f);
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.38f, 0.37f, 0.37f, 0.91f);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.31f, 0.47f, 0.99f, 1.00f);
style.Colors[ImGuiCol_Button] = ImVec4(1.00f, 0.79f, 0.18f, 0.78f);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.42f, 0.82f, 1.00f, 0.81f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.86f);
style.Colors[ImGuiCol_Header] = ImVec4(0.73f, 0.80f, 0.86f, 0.45f);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.75f, 0.88f, 0.94f, 0.80f);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.46f, 0.84f, 0.90f, 1.00f);
style.Colors[ImGuiCol_CloseButton] = ImVec4(0.41f, 0.75f, 0.98f, 0.50f);
style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(1.00f, 0.47f, 0.41f, 0.60f);
style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(1.00f, 0.16f, 0.00f, 1.00f);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(1.00f, 0.99f, 0.54f, 0.43f);
style.Colors[ImGuiCol_TooltipBg] = ImVec4(0.82f, 0.92f, 1.00f, 0.90f);
style.Alpha = 1.0f;
style.WindowFillAlphaDefault = 1.0f;
style.FrameRounding = 4; |
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.
|
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
|
@adam4813 What are you trying to do exactly ? You can use: |
…that are still measuring their size (for #249)
I was throwing out a suggestion for centering.
|
You are right that it is missing some api to do it without juggling awkwardly with 'next window pos' and 'current window size'. |
I like your api a lot more than my proposal, I will test it soon and reporting any inconsistency I may eventually found. |
+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. if (ImGui::BeginPopupModal("Load Image?", nullptr, ImGuiWindowFlags_AlwaysAutoResize))
{
static int currentItem = 0;
ImGui::Combo("Your choice", ¤tItem, "Item 1\0Item 2\0Item 3\0Item 4\0\0");
if (currentItem == 1)
{
ImGui::TextWrapped("Good choice!!");
}
ImGui::Text("This line is a regular text line and works fine");
ImGui::TextWrapped("This is a wrapped line and will cause a wrong Y centering");
if (ImGui::ButtonIcon("OK", ImGui_fa_check, ImVec2(120, 40))) { ImGui::CloseCurrentPopup(); }
ImGui::SameLine();
if (ImGui::ButtonIcon("Cancel", ImGui_fa_close, ImVec2(120, 40))) { ImGui::CloseCurrentPopup(); }
ImGui::EndPopup();
} 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(...) |
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. |
…minimum size applied - hopefully no-side effects (#249)
@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. 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
|
That would be acceptable I suppose. |
Closing this. Note about TextWrapped and name-based Get Pos/Size helpers added in todo list. |
When the window size is not wide enough, this causes a flickering where the dialog appears too tall for one frame and then correct the next frame. However, I find that setting the window size to wider than what it should be just results in no text wrapping. How can I fix this? |
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?
The text was updated successfully, but these errors were encountered: