Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions source/MRViewer/ImGuiHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "MRMesh/MRObjectMesh.h"
#include "MRPch/MRSpdlog.h"
#include "MRRibbonFontHolder.h"
#include "MRImGuiMultiViewport.h"
#include <imgui_internal.h>

namespace ImGui
Expand Down Expand Up @@ -562,15 +563,16 @@ std::pair<ImVec2, bool> LoadSavedWindowPos( const char* label, ImGuiWindow* wind
if ( !window || windowIsInactive )
{
auto ribMenu = std::dynamic_pointer_cast< MR::RibbonMenu >( menu );
float xPos = GetIO().DisplaySize.x - width;
float yPos = 0.0f;
const auto shiftMV = ImGuiMV::GetMainViewportShift();
float xPos = GetIO().DisplaySize.x - width + shiftMV.x;
float yPos = shiftMV.y;
if ( position )
{
xPos = position->x;
yPos = position->y;
}
else if ( ribMenu )
yPos = ( ribMenu->getTopPanelOpenedHeight() - 1.0f ) * UI::scale();
yPos += ( ribMenu->getTopPanelOpenedHeight() - 1.0f ) * UI::scale();

auto& config = MR::Config::instance();
if ( menu->isSavedDialogPositionsEnabled() && config.hasJsonValue( "DialogPositions" ) )
Expand Down Expand Up @@ -670,6 +672,8 @@ bool BeginCustomStatePlugin( const char* label, bool* open, const CustomStatePlu
}
}
}
else
maxHeight = FLT_MAX;

SetNextWindowSizeConstraints( ImVec2( params.width, minHeight ), ImVec2( params.width, maxHeight ) );
}
Expand Down
11 changes: 8 additions & 3 deletions source/MRViewer/MRUIRectAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "MRViewer/MRViewer.h"
#include "MRViewer/MRViewport.h"
#include "MRViewer/MRImGuiVectorOperators.h"
#include "MRViewer/MRImGuiMultiViewport.h"

#include <imgui_internal.h>

Expand Down Expand Up @@ -159,16 +160,20 @@ void WindowRectAllocator::setFreeNextWindowPos( const char* expectedWindowName,
{
// push into application window if it is out
const Vector2f appWindowSize = Vector2f( getViewerInstance().framebufferSize );
const Box2f appWindowBox = Box2f::fromMinAndSize( ImGuiMV::GetMainViewportShift(), appWindowSize );
auto windowBox = Box2f::fromMinAndSize( defaultPos, window->Size );
defaultPos.x = std::clamp( windowBox.min.x, 0.0f, std::max( 0.0f, windowBox.min.x - ( windowBox.max.x - appWindowSize.x ) ) );
defaultPos.y = std::clamp( windowBox.min.y, 0.0f, std::max( 0.0f, windowBox.min.y - ( windowBox.max.y - appWindowSize.y ) ) );
defaultPos.x = std::clamp( windowBox.min.x, appWindowBox.min.x, std::max( 0.0f, windowBox.min.x + appWindowBox.min.x - ( windowBox.max.x - appWindowBox.max.x ) ) );
defaultPos.y = std::clamp( windowBox.min.y, appWindowBox.min.y, std::max( 0.0f, windowBox.min.y + appWindowBox.min.y - ( windowBox.max.y - appWindowBox.max.y ) ) );
windowBox = Box2f::fromMinAndSize( defaultPos, window->Size );


// convert viewport bounds from local to window space
Box2f viewportBounds = getViewerInstance().getViewportsBounds();
Box2f boundsFixed = viewportBounds;
boundsFixed.min.y = ImGui::GetIO().DisplaySize.y - boundsFixed.max.y;
boundsFixed.max.y = boundsFixed.min.y + viewportBounds.size().y;
// convert viewport bounds from window to screen space
boundsFixed.min = ImGuiMV::Window2ScreenSpaceVector2f( boundsFixed.min );
boundsFixed.max = ImGuiMV::Window2ScreenSpaceVector2f( boundsFixed.max );

auto result = findFreeRect( windowBox, boundsFixed, [&]( Box2f rect, std::function<void( const char*, Box2f )> func )
{
Expand Down
3 changes: 2 additions & 1 deletion source/MRViewer/MRViewerSettingsPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "MRMesh/MRConfig.h"
#include "MRPch/MRSpdlog.h"
#include "MRViewportGlobalBasis.h"
#include "MRImGuiMultiViewport.h"
#include "MRShortcutManager.h"

namespace
Expand Down Expand Up @@ -78,7 +79,7 @@ void ViewerSettingsPlugin::drawDialog( ImGuiContext* )
{
auto menuWidth = 400.0f * UI::scale();

ImVec2 position{ ( viewer->framebufferSize.x - menuWidth ) / 2, viewer->framebufferSize.y / 6.0f };
ImVec2 position = ImGuiMV::Window2ScreenSpaceImVec2( ImVec2( ( viewer->framebufferSize.x - menuWidth ) / 2, viewer->framebufferSize.y / 6.0f ) );
if ( !ImGuiBeginWindow_( { .width = menuWidth, .position = &position } ) )
return;

Expand Down
Loading