Styling and Review Feedback Changes
This commit is contained in:
+20
-16
@@ -441,7 +441,7 @@ namespace AzToolsFramework
|
||||
clusterId);
|
||||
}
|
||||
|
||||
static void RemoveTestSwitcher(const ViewportUi::ClusterId clusterId)
|
||||
static void RemoveComponentModeSwitcher(const ViewportUi::ClusterId clusterId)
|
||||
{
|
||||
ViewportUi::ViewportUiRequestBus::Event(
|
||||
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::RemoveCluster,
|
||||
@@ -475,14 +475,13 @@ namespace AzToolsFramework
|
||||
return buttonId;
|
||||
}
|
||||
|
||||
static ViewportUi::ButtonId RegisterSwitcherButton(
|
||||
ViewportUi::ClusterId clusterId, const char* iconName, const char* buttonName)
|
||||
static ViewportUi::ButtonId RegisterSwitcherButton(ViewportUi::ClusterId clusterId, const char* iconPath, const char* buttonName)
|
||||
{
|
||||
ViewportUi::ButtonId buttonId;
|
||||
ViewportUi::ViewportUiRequestBus::EventResult(
|
||||
buttonId, ViewportUi::DefaultViewportId,
|
||||
&ViewportUi::ViewportUiRequestBus::Events::CreateSwitcherButton, clusterId,
|
||||
AZStd::string::format("Editor/Icons/Switcher/%s.svg", iconName), buttonName);
|
||||
iconPath, buttonName);
|
||||
|
||||
return buttonId;
|
||||
}
|
||||
@@ -1043,7 +1042,7 @@ namespace AzToolsFramework
|
||||
EditorEntityLockComponentNotificationBus::Router::BusRouterConnect();
|
||||
EditorManipulatorCommandUndoRedoRequestBus::Handler::BusConnect(entityContextId);
|
||||
|
||||
CreateTestSwitcher();
|
||||
CreateComponentModeSwitcher();
|
||||
|
||||
CreateTransformModeSelectionCluster();
|
||||
RegisterActions();
|
||||
@@ -1059,7 +1058,7 @@ namespace AzToolsFramework
|
||||
DestroyTransformModeSelectionCluster(m_transformModeClusterId);
|
||||
UnregisterActions();
|
||||
|
||||
RemoveTestSwitcher(m_testSwitcherId);
|
||||
RemoveComponentModeSwitcher(m_testSwitcherId);
|
||||
|
||||
m_pivotOverrideFrame.Reset();
|
||||
|
||||
@@ -2584,20 +2583,25 @@ namespace AzToolsFramework
|
||||
m_transformModeSelectionHandler);
|
||||
}
|
||||
|
||||
void EditorTransformComponentSelection::CreateTestSwitcher()
|
||||
void EditorTransformComponentSelection::CreateComponentModeSwitcher()
|
||||
{
|
||||
// Create test switcher
|
||||
// & Set Current Active Mode
|
||||
// Create the switcher
|
||||
ViewportUi::ViewportUiRequestBus::EventResult(
|
||||
m_testSwitcherId, ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::CreateSwitcher,
|
||||
ViewportUi::ButtonId(1));
|
||||
m_testSwitcherId, ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::CreateSwitcher);
|
||||
|
||||
// create and register the buttons
|
||||
m_boxShapeButtonId = RegisterSwitcherButton(m_testSwitcherId, "BoxShape", "Box Shape");
|
||||
m_physxColliderButtonId = RegisterSwitcherButton(m_testSwitcherId, "PhysXCollider", "PhysX Collider");
|
||||
m_transformButtonId = RegisterSwitcherButton(m_testSwitcherId, "Transform", "Transform");
|
||||
// Create and register the buttons
|
||||
m_boxShapeButtonId =
|
||||
RegisterSwitcherButton(m_testSwitcherId, AZStd::string::format("Editor/Icons/Switcher/%s.svg", "BoxShape").c_str(), "Box Shape");
|
||||
m_physxColliderButtonId = RegisterSwitcherButton(
|
||||
m_testSwitcherId, AZStd::string::format("Editor/Icons/Switcher/%s.svg", "PhysXCollider").c_str(), "PhysX Collider");
|
||||
m_transformButtonId = RegisterSwitcherButton(
|
||||
m_testSwitcherId, AZStd::string::format("Editor/Icons/Switcher/%s.svg", "Transform").c_str(), "Transform");
|
||||
|
||||
// Set the initial active button
|
||||
ViewportUi::ViewportUiRequestBus::Event(
|
||||
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::SetSwitcherActiveButton, m_testSwitcherId,
|
||||
m_physxColliderButtonId);
|
||||
|
||||
// Change current active button for now
|
||||
const auto onButtonClicked = [this](ViewportUi::ButtonId buttonId) {
|
||||
if (buttonId == m_boxShapeButtonId)
|
||||
{
|
||||
|
||||
+1
-1
@@ -283,7 +283,7 @@ namespace AzToolsFramework
|
||||
AZ::Event<ViewportUi::ButtonId>::Handler m_transformModeSelectionHandler; ///< Event handler for the Viewport UI cluster.
|
||||
|
||||
//! Create the Viewport UI Switcher. TEST
|
||||
void CreateTestSwitcher();
|
||||
void CreateComponentModeSwitcher();
|
||||
|
||||
ViewportUi::ClusterId m_testSwitcherId;
|
||||
ViewportUi::ButtonId m_boxShapeButtonId;
|
||||
|
||||
@@ -27,12 +27,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 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;
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
auto buttonId = ButtonId(m_buttons.size() + 1);
|
||||
|
||||
if (name == AZStd::string())
|
||||
if (name.empty())
|
||||
{
|
||||
m_buttons.insert({buttonId, AZStd::make_unique<Button>(icon, buttonId)});
|
||||
}
|
||||
|
||||
@@ -94,14 +94,14 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::AddSwitcher(AZStd::shared_ptr<Cluster> cluster, ButtonId currMode)
|
||||
void ViewportUiDisplay::AddSwitcher(AZStd::shared_ptr<Cluster> cluster)
|
||||
{
|
||||
if (!cluster.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto viewportUiSwitcher = AZStd::make_shared<ViewportUiSwitcher>(cluster, currMode);
|
||||
auto viewportUiSwitcher = AZStd::make_shared<ViewportUiSwitcher>(cluster);
|
||||
auto id = AddViewportUiElement(viewportUiSwitcher);
|
||||
cluster->SetViewportUiElementId(id);
|
||||
PositionViewportUiElementAnchored(id, Qt::AlignTop | Qt::AlignLeft);
|
||||
@@ -131,11 +131,11 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::SetSwitcherActiveMode(ViewportUiElementId clusterId, ButtonId buttonId)
|
||||
void ViewportUiDisplay::SetSwitcherActiveButton(ViewportUiElementId clusterId, ButtonId buttonId)
|
||||
{
|
||||
if (auto viewportUiSwitcher = qobject_cast<ViewportUiSwitcher*>(GetViewportUiElement(clusterId).get()))
|
||||
{
|
||||
viewportUiSwitcher->SetActiveMode(buttonId);
|
||||
viewportUiSwitcher->SetActiveButton(buttonId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,11 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
void RemoveClusterButton(ViewportUiElementId clusterId, ButtonId buttonId);
|
||||
void UpdateCluster(const ViewportUiElementId clusterId);
|
||||
|
||||
void AddSwitcher(AZStd::shared_ptr<Cluster> cluster, ButtonId currMode);
|
||||
void AddSwitcher(AZStd::shared_ptr<Cluster> cluster);
|
||||
void AddSwitcherButton(ViewportUiElementId clusterId, Button* button);
|
||||
void RemoveSwitcherButton(ViewportUiElementId clusterId, ButtonId buttonId);
|
||||
void UpdateSwitcher(const ViewportUiElementId clusterId);
|
||||
void SetSwitcherActiveMode(ViewportUiElementId clusterId, ButtonId buttonId);
|
||||
void UpdateSwitcher(ViewportUiElementId clusterId);
|
||||
void SetSwitcherActiveButton(ViewportUiElementId clusterId, 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
|
||||
|
||||
@@ -38,10 +38,10 @@ namespace AzToolsFramework::ViewportUi
|
||||
return RegisterNewCluster(cluster);
|
||||
}
|
||||
|
||||
const ClusterId ViewportUiManager::CreateSwitcher(ButtonId currMode)
|
||||
const ClusterId ViewportUiManager::CreateSwitcher()
|
||||
{
|
||||
auto cluster = AZStd::make_shared<Internal::Cluster>();
|
||||
m_viewportUi->AddSwitcher(cluster, currMode);
|
||||
m_viewportUi->AddSwitcher(cluster);
|
||||
|
||||
return RegisterNewCluster(cluster);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace AzToolsFramework::ViewportUi
|
||||
{
|
||||
auto cluster = clusterEntry->second;
|
||||
cluster->SetHighlightedButton(buttonId);
|
||||
m_viewportUi->SetSwitcherActiveMode(cluster->GetViewportUiElementId(), buttonId);
|
||||
m_viewportUi->SetSwitcherActiveButton(cluster->GetViewportUiElementId(), buttonId);
|
||||
UpdateSwitcherUi(cluster.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace AzToolsFramework::ViewportUi
|
||||
|
||||
// ViewportUiRequestBus ...
|
||||
const ClusterId CreateCluster() override;
|
||||
const ClusterId CreateSwitcher(ButtonId currMode) override;
|
||||
const ClusterId CreateSwitcher() override;
|
||||
void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) override;
|
||||
void SetSwitcherActiveButton(ClusterId clusterId, ButtonId buttonId) override;
|
||||
const ButtonId CreateClusterButton(ClusterId clusterId, const AZStd::string& icon) override;
|
||||
|
||||
@@ -47,11 +47,10 @@ namespace AzToolsFramework::ViewportUi
|
||||
//! 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 ClusterId CreateSwitcher(ButtonId currMode) = 0;
|
||||
virtual const ClusterId 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 will display as highlighted.
|
||||
//! Maybe update this comment
|
||||
//! Sets the active button of the switcher. This is the button which has a text label.
|
||||
virtual void SetSwitcherActiveButton(ClusterId clusterId, ButtonId buttonId) = 0;
|
||||
//! Registers a new button onto a cluster.
|
||||
virtual const ButtonId CreateClusterButton(const ClusterId clusterId, const AZStd::string& icon) = 0;
|
||||
|
||||
+42
-48
@@ -3,20 +3,27 @@
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
ViewportUiSwitcher::ViewportUiSwitcher(AZStd::shared_ptr<Cluster> switcher, ButtonId currentMode)
|
||||
ViewportUiSwitcher::ViewportUiSwitcher(AZStd::shared_ptr<Cluster> switcher)
|
||||
: m_switcher(switcher)
|
||||
, m_currentMode(currentMode)
|
||||
{
|
||||
setOrientation(Qt::Orientation::Horizontal);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
setStyleSheet(QString("QToolBar {background-color: none; border: none; spacing: 3px;}"
|
||||
"QToolButton {background-color: #464646; border: outset; border-color: white; border-radius: 7px; "
|
||||
"border-width: 2px; padding: 7px; color: white;}"));
|
||||
"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 = switcher->GetButtons();
|
||||
|
||||
for (auto button : buttons)
|
||||
{
|
||||
// add all the other buttons after
|
||||
// Add all the buttons as actions
|
||||
if (button->m_buttonId)
|
||||
{
|
||||
AddButton(button);
|
||||
@@ -26,6 +33,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
ViewportUiSwitcher::~ViewportUiSwitcher()
|
||||
{
|
||||
delete m_activeButton;
|
||||
}
|
||||
|
||||
void ViewportUiSwitcher::AddButton(Button* button)
|
||||
@@ -42,26 +50,8 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
// set hover to true by default
|
||||
action->setProperty("IconHasHoverEffect", true);
|
||||
|
||||
// if its the first button added to the switcher add it as a button instead of action
|
||||
if (button->m_buttonId == m_currentMode)
|
||||
{
|
||||
QString buttonName = (button->m_name).c_str();
|
||||
QIcon buttonIcon = QString((button->m_icon).c_str());
|
||||
|
||||
m_activeButton = new QToolButton();
|
||||
|
||||
// No hover effect for the main button as it's not clickable
|
||||
m_activeButton->setProperty("IconHasHoverEffect", false);
|
||||
m_activeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
m_activeButton->setIcon(buttonIcon);
|
||||
m_activeButton->setText(buttonName);
|
||||
addWidget(m_activeButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the action
|
||||
addAction(action);
|
||||
}
|
||||
// add the action
|
||||
addAction(action);
|
||||
|
||||
// resize to fit new action with minimum extra space
|
||||
resize(minimumSizeHint());
|
||||
@@ -104,50 +94,54 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
m_buttonActionMap.erase(buttonId);
|
||||
|
||||
// reset current active mode if its the button being removed
|
||||
if (buttonId == m_currentMode)
|
||||
if (buttonId == m_activeButtonId)
|
||||
{
|
||||
if (auto nextEntry = m_buttonActionMap.find(ButtonId(buttonId + 1)); nextEntry != m_buttonActionMap.end())
|
||||
{
|
||||
SetActiveMode(nextEntry->first);
|
||||
SetActiveButton(nextEntry->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ViewportUiSwitcher::Update()
|
||||
{
|
||||
m_widgetCallbacks.Update();
|
||||
}
|
||||
|
||||
void ViewportUiSwitcher::SetActiveMode(ButtonId buttonId)
|
||||
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_switcher->GetButtons();
|
||||
for (auto button : buttons)
|
||||
{
|
||||
if (button->m_buttonId == buttonId)
|
||||
{
|
||||
QString buttonName = (button->m_name).c_str();
|
||||
QIcon buttonIcon = QString((button->m_icon).c_str());
|
||||
m_activeButton->setIcon(buttonIcon);
|
||||
m_activeButton->setText(buttonName);
|
||||
}
|
||||
}
|
||||
auto found = [buttonId](Button* button) { return (button->m_buttonId == buttonId); };
|
||||
|
||||
// look up button ID in map then remove it from its current position
|
||||
if (auto buttonIt = AZStd::find_if(buttons.begin(), buttons.end(), found); buttonIt != buttons.end())
|
||||
{
|
||||
QString buttonName = ((*buttonIt)->m_name).c_str();
|
||||
QIcon buttonIcon = 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); // call remove button?
|
||||
removeAction(action);
|
||||
|
||||
// add the last action removed
|
||||
if (m_currentMode != buttonId)
|
||||
if (!initialActiveMode)
|
||||
{
|
||||
itr = m_buttonActionMap.find(m_currentMode);
|
||||
action = itr->second;
|
||||
|
||||
addAction(action);
|
||||
// Add the last action removed
|
||||
if (m_activeButtonId != buttonId)
|
||||
{
|
||||
itr = m_buttonActionMap.find(m_activeButtonId);
|
||||
action = itr->second;
|
||||
addAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
m_currentMode = buttonId;
|
||||
m_activeButtonId = buttonId;
|
||||
}
|
||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
|
||||
|
||||
class Cluster;
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
@@ -20,22 +19,21 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ViewportUiSwitcher(AZStd::shared_ptr<Cluster> switcher, ButtonId currentMode);
|
||||
ViewportUiSwitcher(AZStd::shared_ptr<Cluster> switcher);
|
||||
~ViewportUiSwitcher();
|
||||
//! Adds a new button to the cluster.
|
||||
//! Adds a new button to the switcher.
|
||||
void AddButton(Button* button);
|
||||
//! Removes a button from the cluster.
|
||||
//! Removes a button from the switcher.
|
||||
void RemoveButton(ButtonId buttonId);
|
||||
void Update();
|
||||
void SetActiveMode(ButtonId buttonId);
|
||||
//! Changes the m_activeButton.
|
||||
void SetActiveButton(ButtonId buttonId);
|
||||
|
||||
private:
|
||||
QToolButton* m_activeButton;
|
||||
ButtonId m_currentMode;
|
||||
AZStd::shared_ptr<Cluster> m_switcher; //!< Data structure which the cluster will be displaying to the Viewport UI.
|
||||
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<Cluster> m_switcher; //!< Data structure which the switcher 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
|
||||
|
||||
Reference in New Issue
Block a user