Refactor new_editor window architecture and routing
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <string_view>
|
||||
#include "Ports/SystemInteractionPort.h"
|
||||
#include "System/SystemInteractionService.h"
|
||||
#include "Project/EditorProjectRuntime.h"
|
||||
#include "State/EditorCommandFocusService.h"
|
||||
#include <XCEditor/Fields/UIEditorFieldStyle.h>
|
||||
@@ -46,8 +46,8 @@ inline constexpr float kGridTileWidth = 92.0f;
|
||||
inline constexpr float kGridTileHeight = 92.0f;
|
||||
inline constexpr float kGridTileGapX = 12.0f;
|
||||
inline constexpr float kGridTileGapY = 12.0f;
|
||||
inline constexpr float kGridPreviewWidth = 68.0f;
|
||||
inline constexpr float kGridPreviewHeight = 54.0f;
|
||||
inline constexpr float kGridPreviewWidth = 80.0f;
|
||||
inline constexpr float kGridPreviewHeight = 64.0f;
|
||||
inline constexpr float kHeaderFontSize = 12.0f;
|
||||
inline constexpr float kTileLabelFontSize = 11.0f;
|
||||
|
||||
@@ -298,6 +298,48 @@ void AppendContextMenuSeparator(
|
||||
items.push_back(BuildContextMenuSeparatorItem(std::move(itemId)));
|
||||
}
|
||||
|
||||
std::size_t FindContextMenuItemIndexById(
|
||||
const std::vector<Widgets::UIEditorMenuPopupItem>& items,
|
||||
std::string_view itemId) {
|
||||
for (std::size_t index = 0u; index < items.size(); ++index) {
|
||||
if (items[index].itemId == itemId) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return Widgets::UIEditorMenuPopupInvalidIndex;
|
||||
}
|
||||
|
||||
Widgets::UIEditorMenuPopupState PreserveContextMenuWidgetState(
|
||||
const std::vector<Widgets::UIEditorMenuPopupItem>& previousItems,
|
||||
const Widgets::UIEditorMenuPopupState& previousState,
|
||||
const std::vector<Widgets::UIEditorMenuPopupItem>& rebuiltItems) {
|
||||
Widgets::UIEditorMenuPopupState preserved = {};
|
||||
preserved.focused = previousState.focused;
|
||||
|
||||
if (previousState.hoveredIndex < previousItems.size()) {
|
||||
const std::size_t hoveredIndex =
|
||||
FindContextMenuItemIndexById(
|
||||
rebuiltItems,
|
||||
previousItems[previousState.hoveredIndex].itemId);
|
||||
if (hoveredIndex < rebuiltItems.size() && rebuiltItems[hoveredIndex].enabled) {
|
||||
preserved.hoveredIndex = hoveredIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (previousState.submenuOpenIndex < previousItems.size()) {
|
||||
const std::size_t submenuOpenIndex =
|
||||
FindContextMenuItemIndexById(
|
||||
rebuiltItems,
|
||||
previousItems[previousState.submenuOpenIndex].itemId);
|
||||
if (submenuOpenIndex < rebuiltItems.size() && rebuiltItems[submenuOpenIndex].enabled) {
|
||||
preserved.submenuOpenIndex = submenuOpenIndex;
|
||||
}
|
||||
}
|
||||
|
||||
return preserved;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
EditorProjectRuntime* ProjectPanel::ResolveProjectRuntime() {
|
||||
@@ -371,7 +413,7 @@ void ProjectPanel::SetCommandFocusService(
|
||||
}
|
||||
|
||||
void ProjectPanel::SetSystemInteractionHost(
|
||||
Ports::SystemInteractionPort* systemInteractionHost) {
|
||||
System::SystemInteractionService* systemInteractionHost) {
|
||||
m_systemInteractionHost = systemInteractionHost;
|
||||
}
|
||||
|
||||
@@ -883,6 +925,11 @@ void ProjectPanel::RebuildContextMenu() {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::vector<Widgets::UIEditorMenuPopupItem> previousItems =
|
||||
m_contextMenu.items;
|
||||
const Widgets::UIEditorMenuPopupState previousWidgetState =
|
||||
m_contextMenu.widgetState;
|
||||
|
||||
const AssetCommandTarget assetTarget =
|
||||
ResolveAssetCommandTarget(
|
||||
m_contextMenu.targetItemId,
|
||||
@@ -1008,7 +1055,11 @@ void ProjectPanel::RebuildContextMenu() {
|
||||
placement.rect,
|
||||
m_contextMenu.items,
|
||||
popupMetrics);
|
||||
m_contextMenu.widgetState = {};
|
||||
m_contextMenu.widgetState =
|
||||
PreserveContextMenuWidgetState(
|
||||
previousItems,
|
||||
previousWidgetState,
|
||||
m_contextMenu.items);
|
||||
m_contextMenu.widgetState.focused = true;
|
||||
}
|
||||
|
||||
@@ -1057,8 +1108,8 @@ bool ProjectPanel::HandleContextMenuEvent(const UIInputEvent& event) {
|
||||
hitTarget.index < m_contextMenu.items.size() &&
|
||||
m_contextMenu.items[hitTarget.index].enabled) {
|
||||
const std::string itemId = m_contextMenu.items[hitTarget.index].itemId;
|
||||
DispatchContextMenuItem(itemId);
|
||||
CloseContextMenu();
|
||||
DispatchContextMenuItem(itemId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1539,6 +1590,14 @@ UIEditorHostCommandDispatchResult ProjectPanel::DispatchEditCommand(
|
||||
m_hoveredAssetItemId.clear();
|
||||
m_lastPrimaryClickedAssetId.clear();
|
||||
m_lastPrimaryClickTime = {};
|
||||
if (HasValidBounds(m_layout.bounds)) {
|
||||
RebuildPanelLayout(m_layout.bounds);
|
||||
RebuildBrowserScrollLayout();
|
||||
ApplyBrowserLayout(
|
||||
m_layout.bounds,
|
||||
m_browserScrollFrame.layout.contentRect,
|
||||
m_browserVerticalOffset);
|
||||
}
|
||||
if (hadAssetSelection && !ResolveProjectRuntime()->HasSelection()) {
|
||||
EmitSelectionClearedEvent(EventSource::GridPrimary);
|
||||
}
|
||||
@@ -2218,12 +2277,12 @@ ProjectPanel::Layout ProjectPanel::BuildLayout(
|
||||
tile.tileRect = UIRect(tileX, tileY, kGridTileWidth, kGridTileHeight);
|
||||
tile.previewRect = UIRect(
|
||||
tile.tileRect.x + (tile.tileRect.width - kGridPreviewWidth) * 0.5f,
|
||||
tile.tileRect.y + 6.0f,
|
||||
tile.tileRect.y + 4.0f,
|
||||
kGridPreviewWidth,
|
||||
kGridPreviewHeight);
|
||||
tile.labelRect = UIRect(
|
||||
tile.tileRect.x + 4.0f,
|
||||
tile.previewRect.y + tile.previewRect.height + 8.0f,
|
||||
tile.previewRect.y + tile.previewRect.height + 6.0f,
|
||||
tile.tileRect.width - 8.0f,
|
||||
18.0f);
|
||||
layout.assetTiles.push_back(tile);
|
||||
|
||||
Reference in New Issue
Block a user