Hasareej lyn 4389 fix cluster overlap with ImGui (#1329)

Fixing the cluster overlap with ImGui & a ViewportDisplayLayout alignment issue.
This commit is contained in:
Hasareej
2021-06-18 09:50:02 +01:00
committed by GitHub
parent 96da6c6438
commit 75e640b908
3 changed files with 45 additions and 8 deletions
@@ -24,8 +24,6 @@
namespace AzToolsFramework::ViewportUi::Internal
{
// margin for the Viewport UI Overlay in pixels
const static int ViewportUiOverlayMargin = 5;
const static int HighlightBorderSize = 5;
const static int TopHighlightBorderSize = 25;
const static char* HighlightBorderColor = "#44B2F8";
@@ -387,7 +385,6 @@ namespace AzToolsFramework::ViewportUi::Internal
m_fullScreenLayout.setSpacing(0);
m_fullScreenLayout.setContentsMargins(0, 0, 0, 0);
m_fullScreenLayout.addLayout(&m_uiOverlayLayout, 0, 0, 1, 1);
m_uiOverlayLayout.setMargin(ViewportUiOverlayMargin);
// format the label which will appear on top of the highlight border
AZStd::string styleSheet = AZStd::string::format(
@@ -25,13 +25,15 @@ namespace AzToolsFramework::ViewportUi::Internal
: QGridLayout(parent)
{
// set margins and spacing for internal contents
setContentsMargins(0, 0, 0, 0);
setContentsMargins(
ViewportUiOverlayMargin, ViewportUiOverlayMargin + ViewportUiOverlayTopMarginPadding, ViewportUiOverlayMargin,
ViewportUiOverlayMargin);
setSpacing(ViewportUiDisplayLayoutSpacing);
// create a 3x2 map of sub layouts which will stack widgets according to their mapped alignment
m_internalLayouts = AZStd::unordered_map<Qt::Alignment, QBoxLayout*> {
CreateSubLayout(new QVBoxLayout(), 0, 0, Qt::AlignTop | Qt::AlignLeft),
CreateSubLayout(new QHBoxLayout(), 1, 0, Qt::AlignBottom | Qt::AlignLeft),
CreateSubLayout(new QVBoxLayout(), 1, 0, Qt::AlignBottom | Qt::AlignLeft),
CreateSubLayout(new QVBoxLayout(), 0, 1, Qt::AlignTop),
CreateSubLayout(new QHBoxLayout(), 1, 1, Qt::AlignBottom),
CreateSubLayout(new QVBoxLayout(), 0, 2, Qt::AlignTop | Qt::AlignRight),
@@ -50,9 +52,42 @@ namespace AzToolsFramework::ViewportUi::Internal
if (auto layoutForAlignment = m_internalLayouts.find(alignment);
layoutForAlignment != m_internalLayouts.end())
{
// place the widget before the invisible spacer
// spacer must be last item in layout to not interfere with positioning
int index = layoutForAlignment->second->count() - 1;
// place the widget before or after the invisible spacer
// depending on the layout alignment
int index = 0;
switch (alignment)
{
case Qt::AlignTop | Qt::AlignLeft:
case Qt::AlignTop:
index = layoutForAlignment->second->count() - 1;
break;
case Qt::AlignBottom | Qt::AlignRight:
case Qt::AlignBottom:
index = layoutForAlignment->second->count();
break;
// TopRight and BottomLeft are special cases
// place the spacer differently according to whether it's a vertical or horizontal layout
case Qt::AlignTop | Qt::AlignRight:
if (QVBoxLayout* vLayout = qobject_cast<QVBoxLayout*>(layoutForAlignment->second))
{
index = layoutForAlignment->second->count() - 1;
}
else if (QHBoxLayout* hLayout = qobject_cast<QHBoxLayout*>(layoutForAlignment->second))
{
index = layoutForAlignment->second->count();
}
break;
case Qt::AlignBottom | Qt::AlignLeft:
if (QVBoxLayout* vLayout = qobject_cast<QVBoxLayout*>(layoutForAlignment->second))
{
index = layoutForAlignment->second->count();
}
else if (QHBoxLayout* hLayout = qobject_cast<QHBoxLayout*>(layoutForAlignment->second))
{
index = layoutForAlignment->second->count() - 1;
}
break;
}
layoutForAlignment->second->insertWidget(index, widget);
}
}
@@ -19,6 +19,11 @@
namespace AzToolsFramework::ViewportUi::Internal
{
// margin for the Viewport UI Overlay in pixels
constexpr int ViewportUiOverlayMargin = 5;
// padding to make space for ImGui
constexpr int ViewportUiOverlayTopMarginPadding = 20;
//! QGridLayout implementation that uses a grid of QVBox/QHBoxLayouts internally to stack widgets.
class ViewportUiDisplayLayout : public QGridLayout
{