@@ -551,32 +551,23 @@ float GetTitleBarHeght( float menuScaling )
551
551
return 2 * MR::cRibbonItemInterval * menuScaling + ImGui::GetTextLineHeight () + 2 * ImGui::GetStyle ().WindowBorderSize * menuScaling;
552
552
}
553
553
554
- bool BeginCustomStatePlugin ( const char * label, bool * open, const CustomStatePluginWindowParameters& params )
554
+ std::pair<ImVec2, bool > LoadSavedWindowPos ( const char * label, ImGuiWindow* window, float width, const ImVec2* position /* = nullptr */ )
555
555
{
556
- const auto & style = ImGui::GetStyle ();
557
-
558
- const float borderSize = style.WindowBorderSize * params.menuScaling ;
559
- const float titleBarHeight = GetTitleBarHeght ( params.menuScaling );
560
- auto height = params.height ;
561
- if ( params.collapsed && *params.collapsed )
562
- height = titleBarHeight;
563
-
564
- ImGui::PushStyleVar ( ImGuiStyleVar_ItemSpacing, ImVec2 ( 12 * params.menuScaling , 8 * params.menuScaling ) );
556
+ bool haveSavedWindowPos = false ;
557
+ ImVec2 initialWindowPos;
565
558
566
- ImGuiWindow* window = FindWindowByName ( label );
567
559
auto menu = ImGuiMenu::instance ();
568
- ImVec2 initialWindowPos;
569
- bool haveSavedWindowPos = false ;
570
560
bool windowIsInactive = window && !window->WasActive ;
561
+
571
562
if ( !window || windowIsInactive )
572
563
{
573
- auto ribMenu = std::dynamic_pointer_cast<MR::RibbonMenu>( menu );
574
- float xPos = GetIO ().DisplaySize .x - params. width ;
564
+ auto ribMenu = std::dynamic_pointer_cast< MR::RibbonMenu >( menu );
565
+ float xPos = GetIO ().DisplaySize .x - width;
575
566
float yPos = 0 .0f ;
576
- if ( params. position )
567
+ if ( position )
577
568
{
578
- xPos = params. position ->x ;
579
- yPos = params. position ->y ;
569
+ xPos = position->x ;
570
+ yPos = position->y ;
580
571
}
581
572
else if ( ribMenu )
582
573
yPos = ( ribMenu->getTopPanelOpenedHeight () - 1 .0f ) * menu->menu_scaling ();
@@ -600,7 +591,46 @@ bool BeginCustomStatePlugin( const char* label, bool* open, const CustomStatePlu
600
591
initialWindowPos = ImVec2 ( xPos, yPos );
601
592
}
602
593
}
594
+ return { initialWindowPos, haveSavedWindowPos };
595
+ }
603
596
597
+ void SaveWindowPosition ( const char * label, ImGuiWindow* window )
598
+ {
599
+ if ( window )
600
+ {
601
+ auto & config = Config::instance ();
602
+ auto dpJson = config.getJsonValue ( " DialogPositions" );
603
+ serializeToJson ( Vector2i{ int ( window->Pos .x ), int ( window->Pos .y ) }, dpJson[label] );
604
+ config.setJsonValue ( " DialogPositions" , dpJson );
605
+ }
606
+ }
607
+
608
+ bool BeginSavedWindowPos ( const std::string& name, bool * open, const SavedWindowPosParams& params )
609
+ {
610
+ ImGuiWindow* window = ImGui::FindWindowByName ( name.c_str () );
611
+ auto [initialWindowPos, haveSavedWindowPos] = LoadSavedWindowPos ( name.c_str (), window, params.size .y , params.pos );
612
+ UI::getDefaultWindowRectAllocator ().setFreeNextWindowPos ( name.c_str (), initialWindowPos, haveSavedWindowPos ? ImGuiCond_FirstUseEver : ImGuiCond_Appearing, ImVec2 ( 0 , 0 ) );
613
+ ImGui::SetNextWindowSize ( params.size , ImGuiCond_Appearing );
614
+ const bool res = Begin ( name.c_str (), open, params.flags );
615
+ SaveWindowPosition ( name.c_str (), window);
616
+ return res;
617
+ }
618
+
619
+ bool BeginCustomStatePlugin ( const char * label, bool * open, const CustomStatePluginWindowParameters& params )
620
+ {
621
+ const auto & style = ImGui::GetStyle ();
622
+
623
+ const float borderSize = style.WindowBorderSize * params.menuScaling ;
624
+ const float titleBarHeight = GetTitleBarHeght ( params.menuScaling );
625
+ auto height = params.height ;
626
+ if ( params.collapsed && *params.collapsed )
627
+ height = titleBarHeight;
628
+
629
+ ImGui::PushStyleVar ( ImGuiStyleVar_ItemSpacing, ImVec2 ( 12 * params.menuScaling , 8 * params.menuScaling ) );
630
+
631
+ ImGuiWindow* window = FindWindowByName ( label );
632
+ auto menu = ImGuiMenu::instance ();
633
+ auto [initialWindowPos, haveSavedWindowPos] = LoadSavedWindowPos ( label, params.width , params.position );
604
634
UI::getDefaultWindowRectAllocator ().setFreeNextWindowPos ( label, initialWindowPos, haveSavedWindowPos ? ImGuiCond_FirstUseEver : ImGuiCond_Appearing, haveSavedWindowPos ? ImVec2 ( 0 , 0 ) : params.pivot );
605
635
606
636
if ( params.changedSize )
0 commit comments