Merge pull request #95 from aws-lumberyard-dev/hasareej_LYN-2475_viewportui_switcher
Initial pass of ViewportUiSwitcher.
This commit is contained in:
+3
-3
@@ -441,7 +441,7 @@ namespace AzToolsFramework
|
||||
clusterId);
|
||||
}
|
||||
|
||||
static void SetViewportUiClusterVisible(ViewportUi::ClusterId clusterId, bool visible)
|
||||
static void SetViewportUiClusterVisible(const ViewportUi::ClusterId clusterId, const bool visible)
|
||||
{
|
||||
ViewportUi::ViewportUiRequestBus::Event(
|
||||
ViewportUi::DefaultViewportId,
|
||||
@@ -449,7 +449,7 @@ namespace AzToolsFramework
|
||||
clusterId, visible);
|
||||
}
|
||||
|
||||
static void SetViewportUiClusterActiveButton(ViewportUi::ClusterId clusterId, ViewportUi::ButtonId buttonId)
|
||||
static void SetViewportUiClusterActiveButton(const ViewportUi::ClusterId clusterId, const ViewportUi::ButtonId buttonId)
|
||||
{
|
||||
ViewportUi::ViewportUiRequestBus::Event(
|
||||
ViewportUi::DefaultViewportId,
|
||||
@@ -457,7 +457,7 @@ namespace AzToolsFramework
|
||||
clusterId, buttonId);
|
||||
}
|
||||
|
||||
static ViewportUi::ButtonId RegisterClusterButton(ViewportUi::ClusterId clusterId, const char* iconName)
|
||||
static ViewportUi::ButtonId RegisterClusterButton(const ViewportUi::ClusterId clusterId, const char* iconName)
|
||||
{
|
||||
ViewportUi::ButtonId buttonId;
|
||||
ViewportUi::ViewportUiRequestBus::EventResult(
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "AzToolsFramework_precompiled.h"
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
@@ -22,4 +21,11 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
, m_buttonId(buttonId)
|
||||
{
|
||||
}
|
||||
|
||||
Button::Button(AZStd::string icon, AZStd::string name, ButtonId buttonId)
|
||||
: m_icon(AZStd::move(icon))
|
||||
, m_name(AZStd::move(name))
|
||||
, m_buttonId(buttonId)
|
||||
{
|
||||
}
|
||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiRequestBus.h>
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
@@ -27,10 +26,12 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
Deselected
|
||||
};
|
||||
|
||||
explicit Button(AZStd::string icon, ButtonId buttonId);
|
||||
Button(AZStd::string icon, ButtonId buttonId);
|
||||
Button(AZStd::string icon, AZStd::string name, ButtonId buttonId);
|
||||
~Button() = default;
|
||||
|
||||
AZStd::string m_icon; //!< The icon for this button, string path to an image.
|
||||
AZStd::string m_name; //!< The name displayed as a label next to the button's icon.
|
||||
State m_state = State::Deselected;
|
||||
ButtonId m_buttonId;
|
||||
};
|
||||
|
||||
+18
-21
@@ -11,37 +11,27 @@
|
||||
*/
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
Cluster::Cluster()
|
||||
ButtonGroup::ButtonGroup()
|
||||
: m_buttons()
|
||||
, m_buttonTriggeredEvent()
|
||||
{
|
||||
}
|
||||
|
||||
void Cluster::SetViewportUiElementId(const ViewportUiElementId id)
|
||||
void ButtonGroup::SetViewportUiElementId(const ViewportUiElementId id)
|
||||
{
|
||||
m_viewportUiId = id;
|
||||
}
|
||||
|
||||
ViewportUiElementId Cluster::GetViewportUiElementId() const
|
||||
ViewportUiElementId ButtonGroup::GetViewportUiElementId() const
|
||||
{
|
||||
return m_viewportUiId;
|
||||
}
|
||||
|
||||
void Cluster::SetClusterId(const ClusterId clusterId)
|
||||
{
|
||||
m_clusterId = clusterId;
|
||||
}
|
||||
|
||||
ClusterId Cluster::GetClusterId() const
|
||||
{
|
||||
return m_clusterId;
|
||||
}
|
||||
|
||||
void Cluster::SetHighlightedButton(ButtonId buttonId)
|
||||
void ButtonGroup::SetHighlightedButton(ButtonId buttonId)
|
||||
{
|
||||
if (auto buttonEntry = m_buttons.find(buttonId); buttonEntry != m_buttons.end())
|
||||
{
|
||||
@@ -53,15 +43,22 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
}
|
||||
}
|
||||
|
||||
ButtonId Cluster::AddButton(const AZStd::string& icon)
|
||||
ButtonId ButtonGroup::AddButton(const AZStd::string& icon, const AZStd::string& name)
|
||||
{
|
||||
auto buttonId = ButtonId(m_buttons.size() + 1);
|
||||
|
||||
m_buttons.insert({buttonId, AZStd::make_unique<Button>(icon, buttonId)});
|
||||
if (name.empty())
|
||||
{
|
||||
m_buttons.insert({buttonId, AZStd::make_unique<Button>(icon, buttonId)});
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buttons.insert({buttonId, AZStd::make_unique<Button>(icon, name, buttonId)});
|
||||
}
|
||||
return buttonId;
|
||||
}
|
||||
|
||||
Button* Cluster::GetButton(ButtonId buttonId)
|
||||
Button* ButtonGroup::GetButton(ButtonId buttonId)
|
||||
{
|
||||
if (auto buttonEntry = m_buttons.find(buttonId); buttonEntry != m_buttons.end())
|
||||
{
|
||||
@@ -70,7 +67,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AZStd::vector<Button*> Cluster::GetButtons()
|
||||
AZStd::vector<Button*> ButtonGroup::GetButtons()
|
||||
{
|
||||
auto buttons = AZStd::vector<Button*>();
|
||||
for (const auto& button : m_buttons)
|
||||
@@ -80,11 +77,11 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
return buttons;
|
||||
}
|
||||
|
||||
void Cluster::ConnectEventHandler(AZ::Event<ButtonId>::Handler& handler) {
|
||||
void ButtonGroup::ConnectEventHandler(AZ::Event<ButtonId>::Handler& handler) {
|
||||
handler.Connect(m_buttonTriggeredEvent);
|
||||
}
|
||||
|
||||
void Cluster::PressButton(ButtonId buttonId)
|
||||
void ButtonGroup::PressButton(ButtonId buttonId)
|
||||
{
|
||||
m_buttonTriggeredEvent.Signal(buttonId);
|
||||
}
|
||||
+6
-9
@@ -18,23 +18,21 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
class Button;
|
||||
|
||||
//! Data class for a cluster on the Viewport UI. A cluster is defined as a group of buttons with icons
|
||||
//! Data class for a button group on the Viewport UI. A button group is defined as a group of buttons with icons
|
||||
//! each of which can be clicked to trigger an event e.g. toggling between modes.
|
||||
class Cluster
|
||||
//! @note This can be used with either a Cluster or a Switcher with slightly different visuals for each.
|
||||
class ButtonGroup
|
||||
{
|
||||
public:
|
||||
Cluster();
|
||||
~Cluster() = default;
|
||||
ButtonGroup();
|
||||
~ButtonGroup() = default;
|
||||
|
||||
void SetHighlightedButton(ButtonId buttonId);
|
||||
|
||||
void SetViewportUiElementId(ViewportUiElementId id);
|
||||
ViewportUiElementId GetViewportUiElementId() const;
|
||||
|
||||
void SetClusterId(ClusterId id);
|
||||
ClusterId GetClusterId() const;
|
||||
|
||||
ButtonId AddButton(const AZStd::string& icon);
|
||||
ButtonId AddButton(const AZStd::string& icon, const AZStd::string& name = AZStd::string());
|
||||
Button* GetButton(ButtonId buttonId);
|
||||
AZStd::vector<Button*> GetButtons();
|
||||
|
||||
@@ -44,7 +42,6 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
private:
|
||||
AZ::Event<ButtonId> m_buttonTriggeredEvent;
|
||||
ViewportUiElementId m_viewportUiId;
|
||||
ClusterId m_clusterId;
|
||||
AZStd::unordered_map<ButtonId, AZStd::unique_ptr<Button>> m_buttons;
|
||||
};
|
||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||
@@ -9,21 +9,22 @@
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "AzToolsFramework_precompiled.h"
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiCluster.h>
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
ViewportUiCluster::ViewportUiCluster(AZStd::shared_ptr<Cluster> cluster)
|
||||
ViewportUiCluster::ViewportUiCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup)
|
||||
: QToolBar(nullptr)
|
||||
, m_cluster(cluster)
|
||||
, m_buttonGroup(buttonGroup)
|
||||
{
|
||||
setOrientation(Qt::Orientation::Vertical);
|
||||
setStyleSheet("background: black;");
|
||||
|
||||
const AZStd::vector<Button*> buttons = cluster->GetButtons();
|
||||
const AZStd::vector<Button*> buttons = buttonGroup->GetButtons();
|
||||
for (auto button : buttons)
|
||||
{
|
||||
RegisterButton(button);
|
||||
@@ -39,7 +40,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
AddClusterAction(
|
||||
action,
|
||||
[this, button]() {
|
||||
m_cluster->PressButton(button->m_buttonId);
|
||||
m_buttonGroup->PressButton(button->m_buttonId);
|
||||
},
|
||||
[button](QAction* action) {
|
||||
action->setChecked(button->m_state == Button::State::Selected);
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiWidgetCallbacks.h>
|
||||
#include <QToolBar>
|
||||
|
||||
class Cluster;
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
class ButtonGroup;
|
||||
|
||||
//! Helper class to make clusters (toolbars) for display in Viewport UI.
|
||||
class ViewportUiCluster
|
||||
: public QToolBar
|
||||
@@ -29,7 +29,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ViewportUiCluster(AZStd::shared_ptr<Cluster> cluster);
|
||||
ViewportUiCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup);
|
||||
~ViewportUiCluster() = default;
|
||||
|
||||
//! Adds a new button to the cluster.
|
||||
@@ -49,7 +49,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
//! Removes an action from the Viewport UI Cluster.
|
||||
void RemoveClusterAction(QAction* action);
|
||||
|
||||
AZStd::shared_ptr<Cluster> m_cluster; //!< Data structure which the cluster will be displaying to the Viewport UI.
|
||||
AZStd::shared_ptr<ButtonGroup> m_buttonGroup; //!< Data structure which the cluster will be displaying to the Viewport UI.
|
||||
AZStd::unordered_map<ButtonId, QPointer<QAction>> m_buttonActionMap; //!< Map for buttons to their corresponding actions.
|
||||
ViewportUiWidgetCallbacks m_widgetCallbacks; //!< Registers actions and manages updates.
|
||||
};
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiDisplay.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiCluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiSwitcher.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiTextField.h>
|
||||
#include <QWidget>
|
||||
|
||||
@@ -55,16 +56,16 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
UnparentWidgets(m_viewportUiElements);
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::AddCluster(AZStd::shared_ptr<Cluster> cluster)
|
||||
void ViewportUiDisplay::AddCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup)
|
||||
{
|
||||
if (!cluster.get())
|
||||
if (!buttonGroup.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto viewportUiCluster = AZStd::make_shared<ViewportUiCluster>(cluster);
|
||||
auto viewportUiCluster = AZStd::make_shared<ViewportUiCluster>(buttonGroup);
|
||||
auto id = AddViewportUiElement(viewportUiCluster);
|
||||
cluster->SetViewportUiElementId(id);
|
||||
buttonGroup->SetViewportUiElementId(id);
|
||||
PositionViewportUiElementAnchored(id, Qt::AlignTop | Qt::AlignLeft);
|
||||
}
|
||||
|
||||
@@ -93,6 +94,51 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::AddSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup)
|
||||
{
|
||||
if (!buttonGroup.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto viewportUiSwitcher = AZStd::make_shared<ViewportUiSwitcher>(buttonGroup);
|
||||
auto id = AddViewportUiElement(viewportUiSwitcher);
|
||||
buttonGroup->SetViewportUiElementId(id);
|
||||
PositionViewportUiElementAnchored(id, Qt::AlignTop | Qt::AlignLeft);
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::AddSwitcherButton(const ViewportUiElementId clusterId, Button* button)
|
||||
{
|
||||
if (auto viewportUiSwitcher = qobject_cast<ViewportUiSwitcher*>(GetViewportUiElement(clusterId).get()))
|
||||
{
|
||||
viewportUiSwitcher->AddButton(button);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::RemoveSwitcherButton(ViewportUiElementId clusterId, ButtonId buttonId)
|
||||
{
|
||||
if (auto cluster = qobject_cast<ViewportUiSwitcher*>(GetViewportUiElement(clusterId).get()))
|
||||
{
|
||||
cluster->RemoveButton(buttonId);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::UpdateSwitcher(ViewportUiElementId clusterId)
|
||||
{
|
||||
if (auto cluster = qobject_cast<ViewportUiSwitcher*>(GetViewportUiElement(clusterId).get()))
|
||||
{
|
||||
cluster->Update();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::SetSwitcherActiveButton(ViewportUiElementId clusterId, ButtonId buttonId)
|
||||
{
|
||||
if (auto viewportUiSwitcher = qobject_cast<ViewportUiSwitcher*>(GetViewportUiElement(clusterId).get()))
|
||||
{
|
||||
viewportUiSwitcher->SetActiveButton(buttonId);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::AddTextField(AZStd::shared_ptr<TextField> textField)
|
||||
{
|
||||
if (!textField.get())
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||
#include <AzToolsFramework/ViewportUi/TextField.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiRequestBus.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiDisplayLayout.h>
|
||||
@@ -56,11 +56,17 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
ViewportUiDisplay(QWidget* parent, QWidget* renderOverlay);
|
||||
~ViewportUiDisplay();
|
||||
|
||||
void AddCluster(AZStd::shared_ptr<Cluster> cluster);
|
||||
void AddCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup);
|
||||
void AddClusterButton(ViewportUiElementId clusterId, Button* button);
|
||||
void RemoveClusterButton(ViewportUiElementId clusterId, ButtonId buttonId);
|
||||
void UpdateCluster(const ViewportUiElementId clusterId);
|
||||
|
||||
void AddSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup);
|
||||
void AddSwitcherButton(ViewportUiElementId switcherId, Button* button);
|
||||
void RemoveSwitcherButton(ViewportUiElementId switcherId, ButtonId buttonId);
|
||||
void UpdateSwitcher(ViewportUiElementId switcherId);
|
||||
void SetSwitcherActiveButton(ViewportUiElementId switcherId, ButtonId buttonId);
|
||||
|
||||
void AddTextField(AZStd::shared_ptr<TextField> textField);
|
||||
void UpdateTextField(ViewportUiElementId textFieldId);
|
||||
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
// 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 QHBoxLayout(), 0, 0, Qt::AlignTop | Qt::AlignLeft),
|
||||
CreateSubLayout(new QVBoxLayout(), 0, 0, Qt::AlignTop | Qt::AlignLeft),
|
||||
CreateSubLayout(new QHBoxLayout(), 1, 0, Qt::AlignBottom | Qt::AlignLeft),
|
||||
CreateSubLayout(new QVBoxLayout(), 0, 1, Qt::AlignTop),
|
||||
CreateSubLayout(new QHBoxLayout(), 1, 1, Qt::AlignBottom),
|
||||
@@ -60,7 +60,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
AZStd::pair<Qt::Alignment, QBoxLayout*> ViewportUiDisplayLayout::CreateSubLayout(
|
||||
QBoxLayout* layout, const int row, const int column, const Qt::Alignment alignment)
|
||||
{
|
||||
layout->setAlignment(alignment);
|
||||
layout->setAlignment(alignment);
|
||||
|
||||
// add an invisible spacer (stretch) to occupy empty space
|
||||
// without this, alignment and resizing within the sublayouts becomes difficult
|
||||
|
||||
+119
-39
@@ -14,7 +14,7 @@
|
||||
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiManager.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiDisplay.h>
|
||||
|
||||
@@ -32,36 +32,64 @@ namespace AzToolsFramework::ViewportUi
|
||||
|
||||
const ClusterId ViewportUiManager::CreateCluster()
|
||||
{
|
||||
auto cluster = AZStd::make_shared<Internal::Cluster>();
|
||||
m_viewportUi->AddCluster(cluster);
|
||||
auto buttonGroup = AZStd::make_shared<Internal::ButtonGroup>();
|
||||
m_viewportUi->AddCluster(buttonGroup);
|
||||
|
||||
return RegisterNewCluster(cluster);
|
||||
return RegisterNewCluster(buttonGroup);
|
||||
}
|
||||
|
||||
const SwitcherId ViewportUiManager::CreateSwitcher()
|
||||
{
|
||||
auto buttonGroup = AZStd::make_shared<Internal::ButtonGroup>();
|
||||
m_viewportUi->AddSwitcher(buttonGroup);
|
||||
|
||||
return RegisterNewSwitcher(buttonGroup);
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetClusterActiveButton(const ClusterId clusterId, const ButtonId buttonId)
|
||||
{
|
||||
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
auto cluster = clusterEntry->second;
|
||||
auto cluster = clusterIt->second;
|
||||
cluster->SetHighlightedButton(buttonId);
|
||||
UpdateClusterUi(cluster.get());
|
||||
UpdateButtonGroupUi(cluster.get());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetSwitcherActiveButton(const SwitcherId switcherId, const ButtonId buttonId)
|
||||
{
|
||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||
{
|
||||
auto switcher = switcherIt->second;
|
||||
switcher->SetHighlightedButton(buttonId);
|
||||
m_viewportUi->SetSwitcherActiveButton(switcher->GetViewportUiElementId(), buttonId);
|
||||
UpdateButtonGroupUi(switcher.get());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::RegisterClusterEventHandler(const ClusterId clusterId, AZ::Event<ButtonId>::Handler& handler)
|
||||
{
|
||||
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
auto cluster = clusterEntry->second;
|
||||
auto cluster = clusterIt->second;
|
||||
cluster->ConnectEventHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::RegisterSwitcherEventHandler(const SwitcherId switcherId, AZ::Event<ButtonId>::Handler& handler)
|
||||
{
|
||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||
{
|
||||
auto switcher = switcherIt->second;
|
||||
switcher->ConnectEventHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
const ButtonId ViewportUiManager::CreateClusterButton(const ClusterId clusterId, const AZStd::string& icon)
|
||||
{
|
||||
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
auto cluster = clusterEntry->second;
|
||||
auto cluster = clusterIt->second;
|
||||
auto newId = cluster->AddButton(icon);
|
||||
m_viewportUi->AddClusterButton(cluster->GetViewportUiElementId(), cluster->GetButton(newId));
|
||||
|
||||
@@ -71,12 +99,35 @@ namespace AzToolsFramework::ViewportUi
|
||||
return ButtonId(0);
|
||||
}
|
||||
|
||||
const ButtonId ViewportUiManager::CreateSwitcherButton(const SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name)
|
||||
{
|
||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||
{
|
||||
auto switcher = switcherIt->second;
|
||||
auto newId = switcher->AddButton(icon, name);
|
||||
m_viewportUi->AddSwitcherButton(switcher->GetViewportUiElementId(), switcher->GetButton(newId));
|
||||
|
||||
return newId;
|
||||
}
|
||||
|
||||
return ButtonId(0);
|
||||
}
|
||||
|
||||
void ViewportUiManager::RemoveCluster(const ClusterId clusterId)
|
||||
{
|
||||
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
m_clusters.erase(clusterEntry);
|
||||
m_viewportUi->RemoveViewportUiElement(clusterEntry->second->GetViewportUiElementId());
|
||||
m_clusterButtonGroups.erase(clusterIt);
|
||||
m_viewportUi->RemoveViewportUiElement(clusterIt->second->GetViewportUiElementId());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::RemoveSwitcher(SwitcherId switcherId)
|
||||
{
|
||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||
{
|
||||
m_switcherButtonGroups.erase(switcherIt);
|
||||
m_viewportUi->RemoveViewportUiElement(switcherIt->second->GetViewportUiElementId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,15 +144,24 @@ namespace AzToolsFramework::ViewportUi
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetClusterVisible(ClusterId clusterId, bool visible)
|
||||
void ViewportUiManager::SetClusterVisible(const ClusterId clusterId, bool visible)
|
||||
{
|
||||
if (auto clusterEntry = m_clusters.find(clusterId); clusterEntry != m_clusters.end())
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
auto cluster = clusterEntry->second;
|
||||
auto cluster = clusterIt->second;
|
||||
SetViewportUiElementVisible(m_viewportUi.get(), cluster->GetViewportUiElementId(), visible);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetSwitcherVisible(const SwitcherId switcherId, bool visible)
|
||||
{
|
||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||
{
|
||||
auto switcher = switcherIt->second;
|
||||
SetViewportUiElementVisible(m_viewportUi.get(), switcher->GetViewportUiElementId(), visible);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetClusterGroupVisible(const AZStd::vector<ClusterId>& clusterGroup, bool visible)
|
||||
{
|
||||
for (auto clusterId : clusterGroup)
|
||||
@@ -123,9 +183,9 @@ namespace AzToolsFramework::ViewportUi
|
||||
|
||||
void ViewportUiManager::SetTextFieldText(TextFieldId textFieldId, const AZStd::string& text)
|
||||
{
|
||||
if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end())
|
||||
if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end())
|
||||
{
|
||||
auto textField = textFieldEntry->second;
|
||||
auto textField = textFieldIt->second;
|
||||
textField->m_fieldText = text;
|
||||
UpdateTextFieldUi(textField.get());
|
||||
}
|
||||
@@ -134,27 +194,27 @@ namespace AzToolsFramework::ViewportUi
|
||||
void ViewportUiManager::RegisterTextFieldCallback(
|
||||
TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler)
|
||||
{
|
||||
if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end())
|
||||
if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end())
|
||||
{
|
||||
auto textField = textFieldEntry->second;
|
||||
auto textField = textFieldIt->second;
|
||||
textField->ConnectEventHandler(handler);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::RemoveTextField(TextFieldId textFieldId)
|
||||
{
|
||||
if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end())
|
||||
if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end())
|
||||
{
|
||||
m_textFields.erase(textFieldEntry);
|
||||
m_viewportUi->RemoveViewportUiElement(textFieldEntry->second->m_viewportId);
|
||||
m_textFields.erase(textFieldIt);
|
||||
m_viewportUi->RemoveViewportUiElement(textFieldIt->second->m_viewportId);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetTextFieldVisible(TextFieldId textFieldId, bool visible)
|
||||
{
|
||||
if (auto textFieldEntry = m_textFields.find(textFieldId); textFieldEntry != m_textFields.end())
|
||||
if (auto textFieldIt = m_textFields.find(textFieldId); textFieldIt != m_textFields.end())
|
||||
{
|
||||
auto textField = textFieldEntry->second;
|
||||
auto textField = textFieldIt->second;
|
||||
SetViewportUiElementVisible(m_viewportUi.get(), textField->m_viewportId, visible);
|
||||
}
|
||||
}
|
||||
@@ -173,10 +233,19 @@ namespace AzToolsFramework::ViewportUi
|
||||
void ViewportUiManager::PressButton(ClusterId clusterId, ButtonId buttonId)
|
||||
{
|
||||
// Find cluster using ID and cluster map
|
||||
if (auto clusterEntry = m_clusters.find(clusterId);
|
||||
clusterEntry != m_clusters.end())
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId);
|
||||
clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
clusterEntry->second->PressButton(buttonId);
|
||||
clusterIt->second->PressButton(buttonId);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::PressButton(SwitcherId switcherId, ButtonId buttonId)
|
||||
{
|
||||
// Find cluster using ID and cluster map
|
||||
if (auto switcherIt = m_switcherButtonGroups.find(switcherId); switcherIt != m_switcherButtonGroups.end())
|
||||
{
|
||||
switcherIt->second->PressButton(buttonId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,21 +265,32 @@ namespace AzToolsFramework::ViewportUi
|
||||
{
|
||||
m_viewportUi->Update();
|
||||
|
||||
for (auto clusterEntry : m_clusters)
|
||||
for (auto buttonGroup : m_clusterButtonGroups)
|
||||
{
|
||||
UpdateClusterUi(clusterEntry.second.get());
|
||||
UpdateButtonGroupUi(buttonGroup.second.get());
|
||||
}
|
||||
for (auto textFieldEntry : m_textFields)
|
||||
for (auto buttonGroup : m_switcherButtonGroups)
|
||||
{
|
||||
UpdateTextFieldUi(textFieldEntry.second.get());
|
||||
UpdateButtonGroupUi(buttonGroup.second.get());
|
||||
}
|
||||
for (auto textField : m_textFields)
|
||||
{
|
||||
UpdateTextFieldUi(textField.second.get());
|
||||
}
|
||||
}
|
||||
|
||||
ClusterId ViewportUiManager::RegisterNewCluster(AZStd::shared_ptr<Internal::Cluster>& cluster)
|
||||
ClusterId ViewportUiManager::RegisterNewCluster(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup)
|
||||
{
|
||||
ClusterId newId = ClusterId(m_clusters.size() + 1);
|
||||
cluster->SetClusterId(newId);
|
||||
m_clusters.insert({ newId, cluster });
|
||||
ClusterId newId = ClusterId(m_clusterButtonGroups.size() + 1);
|
||||
m_clusterButtonGroups.insert({ newId, buttonGroup });
|
||||
|
||||
return newId;
|
||||
}
|
||||
|
||||
SwitcherId ViewportUiManager::RegisterNewSwitcher(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup)
|
||||
{
|
||||
SwitcherId newId = SwitcherId(m_switcherButtonGroups.size() + 1);
|
||||
m_switcherButtonGroups.insert({newId, buttonGroup});
|
||||
|
||||
return newId;
|
||||
}
|
||||
@@ -224,9 +304,9 @@ namespace AzToolsFramework::ViewportUi
|
||||
return newId;
|
||||
}
|
||||
|
||||
void ViewportUiManager::UpdateClusterUi(Internal::Cluster* cluster)
|
||||
void ViewportUiManager::UpdateButtonGroupUi(Internal::ButtonGroup* buttonGroup)
|
||||
{
|
||||
m_viewportUi->UpdateCluster(cluster->GetViewportUiElementId());
|
||||
m_viewportUi->UpdateCluster(buttonGroup->GetViewportUiElementId());
|
||||
}
|
||||
|
||||
void ViewportUiManager::UpdateTextFieldUi(Internal::TextField* textField)
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/TextField.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiDisplay.h>
|
||||
|
||||
@@ -21,6 +20,7 @@ namespace AzToolsFramework::ViewportUi
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
class ButtonGroup;
|
||||
class ViewportUiDisplay;
|
||||
}
|
||||
|
||||
@@ -29,26 +29,32 @@ namespace AzToolsFramework::ViewportUi
|
||||
public:
|
||||
ViewportUiManager() = default;
|
||||
~ViewportUiManager() = default;
|
||||
|
||||
|
||||
// ViewportUiRequestBus ...
|
||||
const ClusterId CreateCluster() override;
|
||||
const SwitcherId CreateSwitcher() override;
|
||||
void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) override;
|
||||
void SetSwitcherActiveButton(SwitcherId switcherId, ButtonId buttonId) override;
|
||||
const ButtonId CreateClusterButton(ClusterId clusterId, const AZStd::string& icon) override;
|
||||
const ButtonId CreateSwitcherButton(
|
||||
SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name = AZStd::string()) override;
|
||||
void RegisterClusterEventHandler(ClusterId clusterId, AZ::Event<ButtonId>::Handler& handler) override;
|
||||
void RegisterSwitcherEventHandler(SwitcherId switcherId, AZ::Event<ButtonId>::Handler& handler) override;
|
||||
void RemoveCluster(ClusterId clusterId) override;
|
||||
void RemoveSwitcher(SwitcherId switcherId) override;
|
||||
void SetClusterVisible(ClusterId clusterId, bool visible);
|
||||
void SetSwitcherVisible(SwitcherId switcherId, bool visible);
|
||||
void SetClusterGroupVisible(const AZStd::vector<ClusterId>& clusterGroup, bool visible) override;
|
||||
const TextFieldId CreateTextField(
|
||||
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText,
|
||||
TextFieldValidationType validationType) override;
|
||||
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText, TextFieldValidationType validationType) override;
|
||||
void SetTextFieldText(TextFieldId textFieldId, const AZStd::string& text) override;
|
||||
void RegisterTextFieldCallback(
|
||||
TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler) override;
|
||||
void RegisterTextFieldCallback(TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler) override;
|
||||
void RemoveTextField(TextFieldId textFieldId) override;
|
||||
void SetTextFieldVisible(TextFieldId textFieldId, bool visible) override;
|
||||
void CreateComponentModeBorder(const AZStd::string& borderTitle) override;
|
||||
void RemoveComponentModeBorder() override;
|
||||
void PressButton(ClusterId clusterId, ButtonId buttonId) override;
|
||||
void PressButton(SwitcherId switcherId, ButtonId buttonId) override;
|
||||
|
||||
//! Connects to the correct viewportId bus address.
|
||||
void ConnectViewportUiBus(const int viewportId);
|
||||
@@ -60,17 +66,23 @@ namespace AzToolsFramework::ViewportUi
|
||||
void Update();
|
||||
|
||||
protected:
|
||||
AZStd::unordered_map<ClusterId, AZStd::shared_ptr<Internal::Cluster>> m_clusters; //!< A map of all registered clusters.
|
||||
AZStd::unordered_map<TextFieldId, AZStd::shared_ptr<Internal::TextField>> m_textFields; //!< A map of all registered textFields.
|
||||
AZStd::unordered_map<ClusterId, AZStd::shared_ptr<Internal::ButtonGroup>>
|
||||
m_clusterButtonGroups; //!< A map of all registered Clusters.
|
||||
AZStd::unordered_map<SwitcherId, AZStd::shared_ptr<Internal::ButtonGroup>>
|
||||
m_switcherButtonGroups; //!< A map of all registered Switchers.
|
||||
AZStd::unordered_map<TextFieldId, AZStd::shared_ptr<Internal::TextField>> m_textFields; //!< A map of all registered TextFields.
|
||||
|
||||
AZStd::unique_ptr<Internal::ViewportUiDisplay> m_viewportUi; //!< The lower level graphical API for Viewport UI.
|
||||
|
||||
private:
|
||||
//! Register a new cluster and return its id.
|
||||
ClusterId RegisterNewCluster(AZStd::shared_ptr<Internal::Cluster>& cluster);
|
||||
//! Register a new Cluster and return its id.
|
||||
ClusterId RegisterNewCluster(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup);
|
||||
//! Register a new Switcher and return its id.
|
||||
SwitcherId RegisterNewSwitcher(AZStd::shared_ptr<Internal::ButtonGroup>& buttonGroup);
|
||||
//! Register a new text field and return its id.
|
||||
TextFieldId RegisterNewTextField(AZStd::shared_ptr<Internal::TextField>& textField);
|
||||
//! Update the corresponding ui element for the given cluster.
|
||||
void UpdateClusterUi(Internal::Cluster* cluster);
|
||||
//! Update the corresponding ui element for the given button group.
|
||||
void UpdateButtonGroupUi(Internal::ButtonGroup* buttonGroup);
|
||||
//! Update the corresponding ui element for the given text field.
|
||||
void UpdateTextFieldUi(Internal::TextField* textField);
|
||||
};
|
||||
|
||||
+28
-16
@@ -1,14 +1,14 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -23,11 +23,13 @@ namespace AzToolsFramework::ViewportUi
|
||||
using ViewportUiElementId = IdType<struct ViewportUiIdType>;
|
||||
using ButtonId = IdType<struct ButtonIdType>;
|
||||
using ClusterId = IdType<struct ClusterIdType>;
|
||||
using SwitcherId = IdType<struct SwitcherIdType>;
|
||||
using TextFieldId = IdType<struct TextFieldIdType>;
|
||||
|
||||
inline const ViewportUiElementId InvalidViewportUiElementId = ViewportUiElementId(0);
|
||||
inline const ButtonId InvalidButtonId = ButtonId(0);
|
||||
inline const ClusterId InvalidClusterId = ClusterId(0);
|
||||
inline const SwitcherId InvalidSwitcherId = SwitcherId(0);
|
||||
|
||||
inline const int DefaultViewportId = 0;
|
||||
|
||||
@@ -46,27 +48,36 @@ namespace AzToolsFramework::ViewportUi
|
||||
public:
|
||||
//! Creates and registers a cluster with the Viewport UI system.
|
||||
virtual const ClusterId CreateCluster() = 0;
|
||||
//! Creates and registers a switcher with the Viewport UI system.
|
||||
virtual const SwitcherId CreateSwitcher() = 0;
|
||||
//! Sets the active button of the cluster. This is the button which will display as highlighted.
|
||||
virtual void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) = 0;
|
||||
//! Sets the active button of the switcher. This is the button which has a text label.
|
||||
virtual void SetSwitcherActiveButton(SwitcherId clusterId, ButtonId buttonId) = 0;
|
||||
//! Registers a new button onto a cluster.
|
||||
virtual const ButtonId CreateClusterButton(const ClusterId clusterId, const AZStd::string& icon) = 0;
|
||||
//! Registers a new button onto a switcher.
|
||||
virtual const ButtonId CreateSwitcherButton(
|
||||
SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name = AZStd::string()) = 0;
|
||||
//! Registers an event handler to handle events from the cluster.
|
||||
virtual void RegisterClusterEventHandler(ClusterId clusterId, AZ::Event<ButtonId>::Handler& handler) = 0;
|
||||
//! Registers an event handler to handle events from the cluster.
|
||||
virtual void RegisterSwitcherEventHandler(SwitcherId switcherId, AZ::Event<ButtonId>::Handler& handler) = 0;
|
||||
//! Removes a cluster from the Viewport UI system.
|
||||
virtual void RemoveCluster(ClusterId clusterId) = 0;
|
||||
//!
|
||||
virtual void RemoveSwitcher(SwitcherId switcherId) = 0;
|
||||
//! Sets the visibility of the cluster.
|
||||
virtual void SetClusterVisible(ClusterId clusterId, bool visible) = 0;
|
||||
//! Sets the visibility of multiple clusters.
|
||||
virtual void SetClusterGroupVisible(const AZStd::vector<ClusterId>& clusterGroup, bool visible) = 0;
|
||||
//! Creates and registers a text field with the Viewport UI system.
|
||||
virtual const TextFieldId CreateTextField(
|
||||
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText,
|
||||
TextFieldValidationType validationType) = 0;
|
||||
const AZStd::string& labelText, const AZStd::string& textFieldDefaultText, TextFieldValidationType validationType) = 0;
|
||||
//! Set the text that will go inside the text field.
|
||||
virtual void SetTextFieldText(TextFieldId textFieldId, const AZStd::string& text) = 0;
|
||||
//! Register an event handler to handle when the text field text changes.
|
||||
virtual void RegisterTextFieldCallback(
|
||||
TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler) = 0;
|
||||
virtual void RegisterTextFieldCallback(TextFieldId textFieldId, AZ::Event<AZStd::string>::Handler& handler) = 0;
|
||||
//! Removes a text field from the Viewport UI system.
|
||||
virtual void RemoveTextField(TextFieldId textFieldId) = 0;
|
||||
//! Sets the visibility of the text field.
|
||||
@@ -77,11 +88,12 @@ namespace AzToolsFramework::ViewportUi
|
||||
virtual void RemoveComponentModeBorder() = 0;
|
||||
//! Invoke a button press in a cluster.
|
||||
virtual void PressButton(ClusterId clusterId, ButtonId buttonId) = 0;
|
||||
//!
|
||||
virtual void PressButton(SwitcherId switcherId, ButtonId buttonId) = 0;
|
||||
};
|
||||
|
||||
/// The EBusTraits for ViewportInteractionRequests.
|
||||
class ViewportUiBusTraits
|
||||
: public AZ::EBusTraits
|
||||
class ViewportUiBusTraits : public AZ::EBusTraits
|
||||
{
|
||||
public:
|
||||
using BusIdType = int; ///< ViewportId - used to address requests to this EBus.
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiSwitcher.h>
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
ViewportUiSwitcher::ViewportUiSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup)
|
||||
: m_buttonGroup(buttonGroup)
|
||||
{
|
||||
setOrientation(Qt::Orientation::Horizontal);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
setStyleSheet(QString("QToolBar {background-color: none; border: none; spacing: 3px;}"
|
||||
"QToolButton {background-color: black; border: outset; border-color: white; border-radius: 7px; "
|
||||
"border-width: 2px; padding: 7px; color: white;}"));
|
||||
|
||||
// Add am empty active button (is set in the call to SetActiveMode)
|
||||
m_activeButton = new QToolButton();
|
||||
// No hover effect for the main button as it's not clickable
|
||||
m_activeButton->setProperty("IconHasHoverEffect", false);
|
||||
m_activeButton->setCheckable(false);
|
||||
m_activeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
addWidget(m_activeButton);
|
||||
|
||||
const AZStd::vector<Button*> buttons = buttonGroup->GetButtons();
|
||||
|
||||
for (auto button : buttons)
|
||||
{
|
||||
// Add all the buttons as actions
|
||||
if (button->m_buttonId)
|
||||
{
|
||||
AddButton(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ViewportUiSwitcher::~ViewportUiSwitcher()
|
||||
{
|
||||
delete m_activeButton;
|
||||
}
|
||||
|
||||
void ViewportUiSwitcher::AddButton(Button* button)
|
||||
{
|
||||
QAction* action = new QAction();
|
||||
action->setCheckable(true);
|
||||
action->setIcon(QIcon(QString(button->m_icon.c_str())));
|
||||
|
||||
if (!action)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// set hover to true by default
|
||||
action->setProperty("IconHasHoverEffect", true);
|
||||
|
||||
// add the action
|
||||
addAction(action);
|
||||
|
||||
// resize to fit new action with minimum extra space
|
||||
resize(minimumSizeHint());
|
||||
|
||||
const AZStd::function<void()>& callback = [this, button]() { m_buttonGroup->PressButton(button->m_buttonId); };
|
||||
const AZStd::function<void(QAction*)>& updateCallback = [button](QAction* action) {
|
||||
action->setChecked(button->m_state == Button::State::Selected);
|
||||
};
|
||||
|
||||
// connect the callback if provided
|
||||
if (callback)
|
||||
{
|
||||
QObject::connect(action, &QAction::triggered, action, callback);
|
||||
}
|
||||
|
||||
// register the action
|
||||
m_widgetCallbacks.AddWidget(
|
||||
action, [updateCallback](QPointer<QObject> object) { updateCallback(static_cast<QAction*>(object.data())); });
|
||||
|
||||
m_buttonActionMap.insert({button->m_buttonId, action});
|
||||
}
|
||||
|
||||
void ViewportUiSwitcher::RemoveButton(ButtonId buttonId)
|
||||
{
|
||||
if (auto actionEntry = m_buttonActionMap.find(buttonId); actionEntry != m_buttonActionMap.end())
|
||||
{
|
||||
QAction* action = actionEntry->second;
|
||||
|
||||
// remove the action from the toolbar
|
||||
removeAction(action);
|
||||
|
||||
// deregister from the widget manager
|
||||
m_widgetCallbacks.RemoveWidget(action);
|
||||
|
||||
// resize to fit new area with minimum extra space
|
||||
resize(minimumSizeHint());
|
||||
|
||||
m_buttonActionMap.erase(buttonId);
|
||||
|
||||
// reset current active mode if its the button being removed
|
||||
if (buttonId == m_activeButtonId)
|
||||
{
|
||||
if (auto nextEntry = m_buttonActionMap.find(ButtonId(buttonId + 1)); nextEntry != m_buttonActionMap.end())
|
||||
{
|
||||
SetActiveButton(nextEntry->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiSwitcher::Update()
|
||||
{
|
||||
m_widgetCallbacks.Update();
|
||||
}
|
||||
|
||||
void ViewportUiSwitcher::SetActiveButton(ButtonId buttonId)
|
||||
{
|
||||
// Check if it is the first active mode to be set
|
||||
bool initialActiveMode = (m_activeButtonId == ButtonId(0));
|
||||
|
||||
// Change the toolbutton's name and icon to that button
|
||||
const AZStd::vector<Button*> buttons = m_buttonGroup->GetButtons();
|
||||
auto found = [buttonId](Button* button) { return (button->m_buttonId == buttonId); };
|
||||
|
||||
if (auto buttonIt = AZStd::find_if(buttons.begin(), buttons.end(), found); buttonIt != buttons.end())
|
||||
{
|
||||
QString buttonName = ((*buttonIt)->m_name).c_str();
|
||||
QIcon buttonIcon = QIcon(QString(((*buttonIt)->m_icon).c_str()));
|
||||
m_activeButton->setIcon(buttonIcon);
|
||||
m_activeButton->setText(buttonName);
|
||||
}
|
||||
|
||||
// Look up button ID in map then remove it from its current position
|
||||
auto itr = m_buttonActionMap.find(buttonId);
|
||||
QAction* action = itr->second;
|
||||
removeAction(action);
|
||||
|
||||
if (!initialActiveMode)
|
||||
{
|
||||
// Add the last action removed
|
||||
if (m_activeButtonId != buttonId)
|
||||
{
|
||||
itr = m_buttonActionMap.find(m_activeButtonId);
|
||||
action = itr->second;
|
||||
addAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
m_activeButtonId = buttonId;
|
||||
}
|
||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensors.
|
||||
*
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this
|
||||
* distribution (the "License"). All use of this software is governed by the License,
|
||||
* or, if provided, by the license below or the license accompanying this file. Do not
|
||||
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
#include <AzCore/std/smart_ptr/shared_ptr.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiWidgetCallbacks.h>
|
||||
#include <functional>
|
||||
#include <QPointer>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
class ButtonGroup;
|
||||
|
||||
//! Helper class to make switchers (toolbars) for display in Viewport UI.
|
||||
class ViewportUiSwitcher : public QToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ViewportUiSwitcher(AZStd::shared_ptr<ButtonGroup> buttonGroup);
|
||||
~ViewportUiSwitcher();
|
||||
//! Adds a new button to the switcher.
|
||||
void AddButton(Button* button);
|
||||
//! Removes a button from the switcher.
|
||||
void RemoveButton(ButtonId buttonId);
|
||||
void Update();
|
||||
//! Changes the m_activeButton.
|
||||
void SetActiveButton(ButtonId buttonId);
|
||||
|
||||
private:
|
||||
QToolButton* m_activeButton; //!< The first button in the toolbar. Only button with a label/text.
|
||||
ButtonId m_activeButtonId = ButtonId(0); //!< ButtonId corresponding to the active button in the buttonActionMap.
|
||||
AZStd::shared_ptr<ButtonGroup> m_buttonGroup; //!< Data structure which the cluster will be displaying to the Viewport UI.
|
||||
AZStd::unordered_map<ButtonId, QPointer<QAction>> m_buttonActionMap; //!< Map for buttons to their corresponding actions.
|
||||
ViewportUiWidgetCallbacks m_widgetCallbacks; //!< Registers actions and manages updates.
|
||||
};
|
||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||
@@ -487,8 +487,8 @@ set(FILES
|
||||
Viewport/ViewportTypes.cpp
|
||||
ViewportUi/Button.h
|
||||
ViewportUi/Button.cpp
|
||||
ViewportUi/Cluster.h
|
||||
ViewportUi/Cluster.cpp
|
||||
ViewportUi/ButtonGroup.h
|
||||
ViewportUi/ButtonGroup.cpp
|
||||
ViewportUi/TextField.h
|
||||
ViewportUi/TextField.cpp
|
||||
ViewportUi/ViewportUiDisplay.h
|
||||
@@ -500,6 +500,8 @@ set(FILES
|
||||
ViewportUi/ViewportUiTextField.cpp
|
||||
ViewportUi/ViewportUiCluster.h
|
||||
ViewportUi/ViewportUiCluster.cpp
|
||||
ViewportUi/ViewportUiSwitcher.h
|
||||
ViewportUi/ViewportUiSwitcher.cpp
|
||||
ViewportUi/ViewportUiWidgetCallbacks.h
|
||||
ViewportUi/ViewportUiWidgetCallbacks.cpp
|
||||
ViewportUi/ViewportUiDisplayLayout.h
|
||||
@@ -729,7 +731,7 @@ set(FILES
|
||||
# Prevent the following files from being grouped in UNITY builds
|
||||
set(SKIP_UNITY_BUILD_INCLUSION_FILES
|
||||
# The following files are skipped from unity to avoid duplicated symbols related to an ebus
|
||||
AzToolsFrameworkModule.cpp
|
||||
AzToolsFrameworkModule.cpp
|
||||
Application/ToolsApplication.cpp
|
||||
UI/PropertyEditor/PropertyEntityIdCtrl.cpp
|
||||
UI/PropertyEditor/PropertyManagerComponent.cpp
|
||||
|
||||
@@ -20,35 +20,35 @@
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
using Cluster = AzToolsFramework::ViewportUi::Internal::Cluster;
|
||||
using ButtonGroup = AzToolsFramework::ViewportUi::Internal::ButtonGroup;
|
||||
using ButtonId = AzToolsFramework::ViewportUi::ButtonId;
|
||||
|
||||
TEST(ClusterTest, AddButtonAddsButtonToClusterAndReturnsId)
|
||||
{
|
||||
auto cluster = AZStd::make_unique<Cluster>();
|
||||
auto buttonId = cluster->AddButton("");
|
||||
auto buttonGroup = AZStd::make_unique<ButtonGroup>();
|
||||
auto buttonId = buttonGroup->AddButton("");
|
||||
|
||||
auto button = cluster->GetButton(buttonId);
|
||||
auto button = buttonGroup->GetButton(buttonId);
|
||||
EXPECT_TRUE(button != nullptr);
|
||||
}
|
||||
|
||||
TEST(ClusterTest, SetHighlightedButtonChangesButtonStateToSelected)
|
||||
{
|
||||
auto cluster = AZStd::make_unique<Cluster>();
|
||||
auto buttonId = cluster->AddButton("");
|
||||
auto buttonGroup = AZStd::make_unique<ButtonGroup>();
|
||||
auto buttonId = buttonGroup->AddButton("");
|
||||
|
||||
// check button is not highlighted by default
|
||||
auto button = cluster->GetButton(buttonId);
|
||||
auto button = buttonGroup->GetButton(buttonId);
|
||||
EXPECT_FALSE(button->m_state == AzToolsFramework::ViewportUi::Internal::Button::State::Selected);
|
||||
|
||||
cluster->SetHighlightedButton(buttonId);
|
||||
buttonGroup->SetHighlightedButton(buttonId);
|
||||
EXPECT_TRUE(button->m_state == AzToolsFramework::ViewportUi::Internal::Button::State::Selected);
|
||||
}
|
||||
|
||||
TEST(ClusterTest, ConnectEventHandlerConnectsHandlerToButtonTriggeredEvent)
|
||||
{
|
||||
auto cluster = AZStd::make_unique<Cluster>();
|
||||
auto buttonId = cluster->AddButton("");
|
||||
auto buttonGroup = AZStd::make_unique<ButtonGroup>();
|
||||
auto buttonId = buttonGroup->AddButton("");
|
||||
|
||||
// create a handler which will be triggered by the cluster
|
||||
bool handlerTriggered = false;
|
||||
@@ -62,8 +62,8 @@ namespace UnitTest
|
||||
}
|
||||
});
|
||||
|
||||
cluster->ConnectEventHandler(handler);
|
||||
cluster->PressButton(buttonId);
|
||||
buttonGroup->ConnectEventHandler(handler);
|
||||
buttonGroup->PressButton(buttonId);
|
||||
|
||||
EXPECT_TRUE(handlerTriggered);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <AzCore/std/smart_ptr/make_shared.h>
|
||||
#include <AzFramework/Viewport/ViewportScreen.h>
|
||||
#include <AzTest/AzTest.h>
|
||||
#include <AzToolsFramework/ViewportUi/Cluster.h>
|
||||
#include <AzToolsFramework/ViewportUi/ButtonGroup.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiCluster.h>
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
@@ -23,14 +23,14 @@
|
||||
namespace UnitTest
|
||||
{
|
||||
using ViewportUiCluster = AzToolsFramework::ViewportUi::Internal::ViewportUiCluster;
|
||||
using Cluster = AzToolsFramework::ViewportUi::Internal::Cluster;
|
||||
using ButtonGroup = AzToolsFramework::ViewportUi::Internal::ButtonGroup;
|
||||
using Button = AzToolsFramework::ViewportUi::Internal::Button;
|
||||
using ButtonId = AzToolsFramework::ViewportUi::ButtonId;
|
||||
|
||||
TEST(ViewportUiCluster, RegisterButtonIncreasesClusterHeight)
|
||||
{
|
||||
auto clusterInfo = AZStd::make_shared<Cluster>();
|
||||
ViewportUiCluster viewportUiCluster(clusterInfo);
|
||||
auto buttonGroup = AZStd::make_shared<ButtonGroup>();
|
||||
ViewportUiCluster viewportUiCluster(buttonGroup);
|
||||
viewportUiCluster.resize(viewportUiCluster.minimumSizeHint());
|
||||
|
||||
// need to initialize cluster with a single button or size will be invalid
|
||||
@@ -48,8 +48,8 @@ namespace UnitTest
|
||||
|
||||
TEST(ViewportUiCluster, RemoveClusterButtonDecreasesClusterHeight)
|
||||
{
|
||||
auto clusterInfo = AZStd::make_shared<Cluster>();
|
||||
ViewportUiCluster viewportUiCluster(clusterInfo);
|
||||
auto buttonGroup = AZStd::make_shared<ButtonGroup>();
|
||||
ViewportUiCluster viewportUiCluster(buttonGroup);
|
||||
viewportUiCluster.resize(viewportUiCluster.minimumSizeHint());
|
||||
|
||||
// need to initialize cluster with a single button or size will be invalid
|
||||
@@ -70,8 +70,8 @@ namespace UnitTest
|
||||
|
||||
TEST(ViewportUiCluster, UpdateChangesActiveButton)
|
||||
{
|
||||
auto clusterInfo = AZStd::make_shared<Cluster>();
|
||||
ViewportUiCluster viewportUiCluster(clusterInfo);
|
||||
auto buttonGroup = AZStd::make_shared<ButtonGroup>();
|
||||
ViewportUiCluster viewportUiCluster(buttonGroup);
|
||||
|
||||
// register a button to the cluster
|
||||
auto button = AZStd::make_unique<Button>("", ButtonId(1));
|
||||
@@ -93,8 +93,8 @@ namespace UnitTest
|
||||
|
||||
TEST(ViewportUiCluster, TriggeringActionTriggersClusterEventForButton)
|
||||
{
|
||||
auto clusterInfo = AZStd::make_shared<Cluster>();
|
||||
ViewportUiCluster viewportUiCluster(clusterInfo);
|
||||
auto buttonGroup = AZStd::make_shared<ButtonGroup>();
|
||||
ViewportUiCluster viewportUiCluster(buttonGroup);
|
||||
|
||||
// create a handler which will be triggered by the button
|
||||
bool handlerTriggered = false;
|
||||
@@ -107,7 +107,7 @@ namespace UnitTest
|
||||
handlerTriggered = true;
|
||||
}
|
||||
});
|
||||
clusterInfo->ConnectEventHandler(handler);
|
||||
buttonGroup->ConnectEventHandler(handler);
|
||||
|
||||
// register the button
|
||||
auto button = AZStd::make_unique<Button>("", testButtonId);
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace UnitTest
|
||||
{
|
||||
using ViewportUiDisplay = AzToolsFramework::ViewportUi::Internal::ViewportUiDisplay;
|
||||
using ViewportUiElementId = AzToolsFramework::ViewportUi::ViewportUiElementId;
|
||||
using Cluster = AzToolsFramework::ViewportUi::Internal::Cluster;
|
||||
using ButtonGroup = AzToolsFramework::ViewportUi::Internal::ButtonGroup;
|
||||
|
||||
// sets up a parent widget and render overlay to attach the Viewport UI to
|
||||
// as well as a cluster with one button
|
||||
// as well as a button group with one button
|
||||
class ViewportUiDisplayTestFixture : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
@@ -34,22 +34,22 @@ namespace UnitTest
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
m_cluster = AZStd::make_shared<Cluster>();
|
||||
m_cluster->AddButton("");
|
||||
m_buttonGroup = AZStd::make_shared<ButtonGroup>();
|
||||
m_buttonGroup->AddButton("");
|
||||
m_parentWidget = new QWidget();
|
||||
m_mockRenderOverlay = new QWidget();
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
{
|
||||
m_cluster.reset();
|
||||
m_buttonGroup.reset();
|
||||
delete m_parentWidget;
|
||||
delete m_mockRenderOverlay;
|
||||
}
|
||||
|
||||
QWidget* m_parentWidget = nullptr;
|
||||
QWidget* m_mockRenderOverlay = nullptr;
|
||||
AZStd::shared_ptr<Cluster> m_cluster = nullptr;
|
||||
AZStd::shared_ptr<ButtonGroup> m_buttonGroup = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(ViewportUiDisplayTestFixture, ViewportUiInitializationReturnsProperlyParentedWidgets)
|
||||
@@ -72,13 +72,13 @@ namespace UnitTest
|
||||
TEST_F(ViewportUiDisplayTestFixture, RemoveViewportUiElementRemovesElementFromViewportUi)
|
||||
{
|
||||
ViewportUiDisplay viewportUi(m_parentWidget, m_mockRenderOverlay);
|
||||
viewportUi.AddCluster(m_cluster);
|
||||
auto widget = viewportUi.GetViewportUiElement(m_cluster->GetViewportUiElementId());
|
||||
viewportUi.AddCluster(m_buttonGroup);
|
||||
auto widget = viewportUi.GetViewportUiElement(m_buttonGroup->GetViewportUiElementId());
|
||||
|
||||
EXPECT_TRUE(widget.get() != nullptr);
|
||||
|
||||
viewportUi.RemoveViewportUiElement(m_cluster->GetViewportUiElementId());
|
||||
widget = viewportUi.GetViewportUiElement(m_cluster->GetViewportUiElementId());
|
||||
viewportUi.RemoveViewportUiElement(m_buttonGroup->GetViewportUiElementId());
|
||||
widget = viewportUi.GetViewportUiElement(m_buttonGroup->GetViewportUiElementId());
|
||||
|
||||
EXPECT_TRUE(widget.get() == nullptr);
|
||||
}
|
||||
@@ -89,11 +89,11 @@ namespace UnitTest
|
||||
|
||||
ViewportUiDisplay viewportUi(m_parentWidget, m_mockRenderOverlay);
|
||||
viewportUi.InitializeUiOverlay();
|
||||
viewportUi.AddCluster(m_cluster);
|
||||
viewportUi.AddCluster(m_buttonGroup);
|
||||
viewportUi.Update();
|
||||
viewportUi.ShowViewportUiElement(m_cluster->GetViewportUiElementId());
|
||||
viewportUi.ShowViewportUiElement(m_buttonGroup->GetViewportUiElementId());
|
||||
|
||||
EXPECT_TRUE(viewportUi.IsViewportUiElementVisible(m_cluster->GetViewportUiElementId()));
|
||||
EXPECT_TRUE(viewportUi.IsViewportUiElementVisible(m_buttonGroup->GetViewportUiElementId()));
|
||||
}
|
||||
|
||||
TEST_F(ViewportUiDisplayTestFixture, HideViewportUiElementSetsWidgetVisibilityToFalse)
|
||||
@@ -102,20 +102,20 @@ namespace UnitTest
|
||||
|
||||
ViewportUiDisplay viewportUi(m_parentWidget, m_mockRenderOverlay);
|
||||
viewportUi.InitializeUiOverlay();
|
||||
viewportUi.AddCluster(m_cluster);
|
||||
viewportUi.HideViewportUiElement(m_cluster->GetViewportUiElementId());
|
||||
viewportUi.AddCluster(m_buttonGroup);
|
||||
viewportUi.HideViewportUiElement(m_buttonGroup->GetViewportUiElementId());
|
||||
|
||||
EXPECT_FALSE(viewportUi.IsViewportUiElementVisible(m_cluster->GetViewportUiElementId()));
|
||||
EXPECT_FALSE(viewportUi.IsViewportUiElementVisible(m_buttonGroup->GetViewportUiElementId()));
|
||||
}
|
||||
|
||||
TEST_F(ViewportUiDisplayTestFixture, UpdateUiOverlayGeometryChangesGeometryToMatchViewportUiElements)
|
||||
{
|
||||
ViewportUiDisplay viewportUi(m_parentWidget, m_mockRenderOverlay);
|
||||
viewportUi.InitializeUiOverlay();
|
||||
viewportUi.AddCluster(m_cluster);
|
||||
viewportUi.AddCluster(m_buttonGroup);
|
||||
|
||||
viewportUi.Update();
|
||||
auto widget = viewportUi.GetViewportUiElement(m_cluster->GetViewportUiElementId());
|
||||
auto widget = viewportUi.GetViewportUiElement(m_buttonGroup->GetViewportUiElementId());
|
||||
|
||||
EXPECT_EQ(viewportUi.GetUiMainWindow()->mask(), widget->geometry());
|
||||
}
|
||||
@@ -127,14 +127,14 @@ namespace UnitTest
|
||||
ViewportUiDisplay viewportUi(m_parentWidget, m_mockRenderOverlay);
|
||||
viewportUi.InitializeUiOverlay();
|
||||
|
||||
auto cluster = AZStd::make_shared<Cluster>();
|
||||
cluster->AddButton("");
|
||||
viewportUi.AddCluster(cluster);
|
||||
auto buttonGroup = AZStd::make_shared<ButtonGroup>();
|
||||
buttonGroup->AddButton("");
|
||||
viewportUi.AddCluster(buttonGroup);
|
||||
viewportUi.Update();
|
||||
|
||||
EXPECT_TRUE(viewportUi.GetUiMainWindow()->isVisible());
|
||||
|
||||
viewportUi.RemoveViewportUiElement(cluster->GetViewportUiElementId());
|
||||
viewportUi.RemoveViewportUiElement(buttonGroup->GetViewportUiElementId());
|
||||
viewportUi.Update();
|
||||
EXPECT_FALSE(viewportUi.GetUiMainWindow()->isVisible());
|
||||
}
|
||||
|
||||
@@ -22,19 +22,19 @@ namespace UnitTest
|
||||
{
|
||||
using ViewportUiDisplay = AzToolsFramework::ViewportUi::Internal::ViewportUiDisplay;
|
||||
using ViewportUiElementId = AzToolsFramework::ViewportUi::ViewportUiElementId;
|
||||
using Cluster = AzToolsFramework::ViewportUi::Internal::Cluster;
|
||||
using ButtonGroup = AzToolsFramework::ViewportUi::Internal::ButtonGroup;
|
||||
using ButtonId = AzToolsFramework::ViewportUi::ButtonId;
|
||||
|
||||
// child class of ViewportUiManager which exposes the protected cluster and viewport display
|
||||
// child class of ViewportUiManager which exposes the protected button group and viewport display
|
||||
class ViewportUiManagerTestable : public AzToolsFramework::ViewportUi::ViewportUiManager
|
||||
{
|
||||
public:
|
||||
ViewportUiManagerTestable() = default;
|
||||
~ViewportUiManagerTestable() = default;
|
||||
|
||||
const AZStd::unordered_map<AzToolsFramework::ViewportUi::ClusterId, AZStd::shared_ptr<Cluster>>& GetClusterMap()
|
||||
const AZStd::unordered_map<AzToolsFramework::ViewportUi::ClusterId, AZStd::shared_ptr<ButtonGroup>>& GetClusterMap()
|
||||
{
|
||||
return m_clusters;
|
||||
return m_clusterButtonGroups;
|
||||
}
|
||||
|
||||
ViewportUiDisplay* GetViewportUiDisplay()
|
||||
|
||||
Reference in New Issue
Block a user