43
43
#include " MRPch/MRSpdlog.h"
44
44
#include " MRProgressBar.h"
45
45
#include " MRFileDialog.h"
46
+ #include " MRModalDialog.h"
46
47
47
48
#include < MRMesh/MRMesh.h>
48
49
#include < MRMesh/MRObjectLoad.h>
@@ -834,26 +835,12 @@ void ImGuiMenu::draw_helpers()
834
835
}
835
836
836
837
const auto menuScaling = menu_scaling ();
837
- ImGui::PushStyleVar ( ImGuiStyleVar_WindowPadding, { cModalWindowPaddingX * menuScaling, cModalWindowPaddingY * menuScaling } );
838
- ImGui::PushStyleVar ( ImGuiStyleVar_ItemSpacing, { cDefaultItemSpacing * menuScaling, 3 .0f * cDefaultItemSpacing * menuScaling } );
839
- ImGui::PushStyleVar ( ImGuiStyleVar_ItemInnerSpacing, { 2 .0f * cDefaultInnerSpacing * menuScaling, cDefaultInnerSpacing * menuScaling } );
840
-
841
- ImVec2 windowSize ( cModalWindowWidth * menuScaling, 0 .0f );
842
- ImGui::SetNextWindowSize ( windowSize, ImGuiCond_Always );
843
-
844
- if ( ImGui::BeginModalNoAnimation ( " Rename object" , nullptr ,
845
- ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar ) )
838
+ ModalDialog renameDialog ( " Rename object" , {
839
+ .headline = " Rename Object" ,
840
+ .closeOnClickOutside = true ,
841
+ } );
842
+ if ( renameDialog.beginPopup ( menuScaling ) )
846
843
{
847
- auto headerFont = RibbonFontManager::getFontByTypeStatic ( RibbonFontManager::FontType::Headline );
848
- if ( headerFont )
849
- ImGui::PushFont ( headerFont );
850
-
851
- ImGui::SetCursorPosX ( ( windowSize.x - ImGui::CalcTextSize ( " Rename Object" ).x ) * 0 .5f );
852
- ImGui::Text ( " Rename Object" );
853
-
854
- if ( headerFont )
855
- ImGui::PopFont ();
856
-
857
844
const auto & obj = SceneCache::getAllObjects<Object, ObjectSelectivityType::Selected>().front ();
858
845
if ( !obj )
859
846
{
@@ -864,7 +851,7 @@ void ImGuiMenu::draw_helpers()
864
851
865
852
const auto & style = ImGui::GetStyle ();
866
853
ImGui::PushStyleVar ( ImGuiStyleVar_FramePadding, { style.FramePadding .x , cInputPadding * menuScaling } );
867
- ImGui::SetNextItemWidth ( windowSize. x - 2 * style.WindowPadding .x - style.ItemInnerSpacing .x - ImGui::CalcTextSize ( " Name" ).x );
854
+ ImGui::SetNextItemWidth ( renameDialog. windowWidth () - 2 * style.WindowPadding .x - style.ItemInnerSpacing .x - ImGui::CalcTextSize ( " Name" ).x );
868
855
UI::inputText ( " Name" , popUpRenameBuffer_, ImGuiInputTextFlags_AutoSelectAll );
869
856
ImGui::PopStyleVar ();
870
857
@@ -877,20 +864,15 @@ void ImGuiMenu::draw_helpers()
877
864
ImGui::CloseCurrentPopup ();
878
865
}
879
866
ImGui::SameLine ();
880
- ImGui::SetCursorPosX ( windowSize. x - btnWidth - style.WindowPadding .x );
867
+ ImGui::SetCursorPosX ( renameDialog. windowWidth () - btnWidth - style.WindowPadding .x );
881
868
if ( UI::button ( " Cancel" , Vector2f ( btnWidth, 0 ), ImGuiKey_Escape ) )
882
869
{
883
870
ImGui::CloseCurrentPopup ();
884
871
}
885
872
ImGui::PopStyleVar ();
886
- if ( ImGui::IsMouseClicked ( 0 ) && !( ImGui::IsAnyItemHovered () || ImGui::IsWindowHovered ( ImGuiHoveredFlags_AnyWindow ) ) )
887
- {
888
- ImGui::CloseCurrentPopup ();
889
- }
890
873
891
- ImGui::EndPopup ( );
874
+ renameDialog. endPopup ( menuScaling );
892
875
}
893
- ImGui::PopStyleVar ( 3 );
894
876
895
877
drawModalMessage_ ();
896
878
}
@@ -960,52 +942,27 @@ void ImGuiMenu::drawModalMessage_()
960
942
}
961
943
962
944
const auto menuScaling = menu_scaling ();
963
- const ImVec2 errorWindowSize{ MR::cModalWindowWidth * menuScaling, - 1 };
964
- ImGui::SetNextWindowSize ( errorWindowSize, ImGuiCond_Always );
965
- ImGui::PushStyleVar ( ImGuiStyleVar_WindowPadding, { cModalWindowPaddingX * menuScaling, cModalWindowPaddingY * menuScaling } );
966
- ImGui::PushStyleVar ( ImGuiStyleVar_ItemSpacing, { 2 . 0f * cDefaultItemSpacing * menuScaling, 3 . 0f * cDefaultItemSpacing * menuScaling } );
967
- if ( ImGui::BeginModalNoAnimation ( titleImGui. c_str (), nullptr ,
968
- ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar ) )
945
+ ModalDialog modal ( titleImGui, {
946
+ . headline = title,
947
+ . text = storedModalMessage_,
948
+ . closeOnClickOutside = true ,
949
+ } );
950
+ if ( modal. beginPopup ( menuScaling ) )
969
951
{
970
- auto headerFont = RibbonFontManager::getFontByTypeStatic ( RibbonFontManager::FontType::Headline );
971
- if ( headerFont )
972
- ImGui::PushFont ( headerFont );
973
-
974
- const auto headerWidth = ImGui::CalcTextSize ( title.c_str () ).x ;
975
-
976
- ImGui::SetCursorPosX ( ( errorWindowSize.x - headerWidth ) * 0 .5f );
977
- ImGui::Text ( " %s" , title.c_str ());
978
-
979
- if ( headerFont )
980
- ImGui::PopFont ();
981
-
982
- const float textWidth = ImGui::CalcTextSize ( storedModalMessage_.c_str () ).x ;
983
-
984
- if ( textWidth + ImGui::GetStyle ().WindowPadding .x * 2 .0f < errorWindowSize.x )
985
- {
986
- ImGui::SetCursorPosX ( ( errorWindowSize.x - textWidth ) * 0 .5f );
987
- ImGui::Text ( " %s" , storedModalMessage_.c_str () );
988
- }
989
- else
990
- {
991
- ImGui::TextWrapped ( " %s" , storedModalMessage_.c_str () );
992
- }
993
952
const auto style = ImGui::GetStyle ();
994
953
ImGui::PushStyleVar ( ImGuiStyleVar_FramePadding, { style.FramePadding .x , cButtonPadding * menuScaling } );
995
- if ( UI::button ( " Okay" , Vector2f ( -1 , 0 ) ) || ImGui::IsKeyPressed ( ImGuiKey_Enter ) ||
996
- ( ImGui::IsMouseClicked ( 0 ) && !ImGui::IsWindowAppearing () && !( ImGui::IsAnyItemHovered () || ImGui::IsWindowHovered (ImGuiHoveredFlags_AnyWindow) ) ) )
997
- {
954
+ if ( UI::button ( " Okay" , Vector2f ( -1 , 0 ), ImGuiKey_Enter ) )
998
955
ImGui::CloseCurrentPopup ();
999
- }
1000
956
ImGui::PopStyleVar ();
1001
- ImGui::EndPopup ();
957
+
958
+ modal.endPopup ( menuScaling );
1002
959
needModalBgChange_ = true ;
1003
960
}
1004
961
else
1005
962
{
1006
963
needModalBgChange_ = false ;
1007
964
}
1008
- ImGui::PopStyleVar ( 2 );
965
+
1009
966
ImGui::PopStyleColor ();
1010
967
}
1011
968
0 commit comments