diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplay.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplay.cpp index bb2aeed4d6..81be2bba90 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplay.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplay.cpp @@ -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( diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.cpp index bab664d832..92fad8cc93 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.cpp @@ -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 { 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(layoutForAlignment->second)) + { + index = layoutForAlignment->second->count() - 1; + } + else if (QHBoxLayout* hLayout = qobject_cast(layoutForAlignment->second)) + { + index = layoutForAlignment->second->count(); + } + break; + case Qt::AlignBottom | Qt::AlignLeft: + if (QVBoxLayout* vLayout = qobject_cast(layoutForAlignment->second)) + { + index = layoutForAlignment->second->count(); + } + else if (QHBoxLayout* hLayout = qobject_cast(layoutForAlignment->second)) + { + index = layoutForAlignment->second->count() - 1; + } + break; + } layoutForAlignment->second->insertWidget(index, widget); } } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.h b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.h index 0beb0d5bd6..8d710264be 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.h @@ -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 {