Skip to content

Commit c9a2e24

Browse files
authored
fix more ui elements in multi viewport (search input, drag&drop zones) (#5432)
1 parent b4a5b91 commit c9a2e24

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

source/MRCommonPlugins/ViewerButtons/MRIOFilesMenuItems.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "MRViewer/MRLambdaRibbonItem.h"
4949
#include "MRIOExtras/MRPng.h"
5050
#include "MRViewer/MRRibbonFontHolder.h"
51+
#include "MRViewer/MRImGuiMultiViewport.h"
5152

5253
#ifndef MESHLIB_NO_VOXELS
5354
#include "MRVoxels/MRObjectVoxels.h"
@@ -333,11 +334,10 @@ void OpenFilesMenuItem::preDraw_()
333334

334335
auto mainColor = ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::BackgroundSecStyle );
335336
auto secondColor = ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::Background );
336-
337-
ImVec2 min = ImVec2( 10.0f * UI::scale(), 10.0f * UI::scale() );
338-
ImVec2 max = ImVec2( Vector2f( getViewerInstance().framebufferSize ) );
339-
max.x -= min.x;
340-
max.y -= min.y;
337+
338+
ImVec2 offset = ImVec2( 10.0f, 10.0f ) * UI::scale();
339+
ImVec2 min = ImGuiMV::Window2ScreenSpaceImVec2( offset );
340+
ImVec2 max = ImGuiMV::Window2ScreenSpaceImVec2( ImVec2( Vector2f( getViewerInstance().framebufferSize ) ) - offset );
341341
drawList->AddRectFilled( min, max,
342342
( addAreaHovered ? secondColor : mainColor ).scaledAlpha( 0.8f ).getUInt32(), 10.0f * UI::scale() );
343343
drawList->AddRect( min, max, ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::Borders ).getUInt32(), 10.0f * UI::scale(), 0, 2.0f * UI::scale() );
@@ -352,7 +352,7 @@ void OpenFilesMenuItem::preDraw_()
352352
{
353353
auto sceneBoxSize = menu->getSceneSize();
354354
min.y += ( getViewerInstance().framebufferSize.y - sceneBoxSize.y );
355-
max.x = sceneBoxSize.x - min.x;
355+
max.x = min.x + sceneBoxSize.x - offset.x * 2.f;
356356
drawList->AddRectFilled( min, max, ( addAreaHovered ? mainColor : secondColor ).scaledAlpha( 0.8f ).getUInt32(), 10.0f * UI::scale() );
357357
drawList->AddRect( min, max, ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::Borders ).getUInt32(), 10.0f * UI::scale(), 0, 2.0f * UI::scale() );
358358

source/MRViewer/MRRibbonMenuSearch.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "MRUIStyle.h"
1212
#include "MRRibbonFontHolder.h"
1313
#include "MRImGuiMultiViewport.h"
14+
#include "MRImGuiMultiViewport.h"
1415
#include <imgui_internal.h>
1516

1617
namespace MR
@@ -341,15 +342,17 @@ bool RibbonMenuSearch::smallSearchButton_()
341342
bool RibbonMenuSearch::searchInputText_( const char* label, std::string& str )
342343
{
343344
ImGui::PushID( "searchInputText" );
344-
const ImVec2 cursorPos = ImGui::GetCursorPos();
345+
const ImVec2 cursorPosWindow = ImGui::GetCursorPos();
346+
const ImVec2 cursorPosScreen = ImGuiMV::Window2ScreenSpaceImVec2( cursorPosWindow );
347+
345348

346349
const auto& style = ImGui::GetStyle();
347350

348351
const float inputHeight = ImGui::GetTextLineHeight() + style.FramePadding.y * 2.f;
349352
const auto drawList = ImGui::GetWindowDrawList();
350-
drawList->AddRectFilled( cursorPos, ImVec2( cursorPos.x + cSearchSize * UI::scale(), cursorPos.y + inputHeight ),
353+
drawList->AddRectFilled( cursorPosScreen, ImVec2( cursorPosScreen.x + cSearchSize * UI::scale(), cursorPosScreen.y + inputHeight ),
351354
ColorTheme::getRibbonColor( ColorTheme::RibbonColorsType::TopPanelSearchBackground ).getUInt32(), style.FrameRounding );
352-
drawList->AddRect( cursorPos, ImVec2( cursorPos.x + cSearchSize * UI::scale(), cursorPos.y + inputHeight ),
355+
drawList->AddRect( cursorPosScreen, ImVec2( cursorPosScreen.x + cSearchSize * UI::scale(), cursorPosScreen.y + inputHeight ),
353356
ImGui::GetColorU32( ImGuiCol_Border ), style.FrameRounding );
354357

355358
int colorNum = 0;
@@ -360,7 +363,7 @@ bool RibbonMenuSearch::searchInputText_( const char* label, std::string& str )
360363
}
361364
RibbonFontHolder font( RibbonFontManager::FontType::Icons, 0.7f );
362365
const float inputWidth = cSearchSize * UI::scale() - style.FramePadding.x - style.ItemSpacing.x - ImGui::CalcTextSize( "\xef\x80\x82" ).x;
363-
ImGui::SetCursorPos( ImVec2( cursorPos.x + inputWidth + style.ItemSpacing.x, cursorPos.y + style.FramePadding.y ) );
366+
ImGui::SetCursorPos( ImVec2( cursorPosWindow.x + inputWidth + style.ItemSpacing.x, cursorPosWindow.y + style.FramePadding.y ) );
364367
ImGui::Text( "%s", "\xef\x80\x82" );
365368
font.popFont();
366369
if ( colorNum )
@@ -369,7 +372,7 @@ bool RibbonMenuSearch::searchInputText_( const char* label, std::string& str )
369372
if ( ImGui::IsItemClicked( ImGuiMouseButton_Left ) )
370373
activate();
371374

372-
ImGui::SetCursorPos( cursorPos );
375+
ImGui::SetCursorPos( cursorPosWindow );
373376
ImGui::SetNextItemWidth( inputWidth );
374377
ImGui::PushStyleColor( ImGuiCol_FrameBg, Color::transparent().getUInt32() );
375378
ImGui::PushStyleColor( ImGuiCol_Border, Color::transparent().getUInt32() );

0 commit comments

Comments
 (0)