Refactor new editor state ownership model
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "HierarchyPanelInternal.h"
|
||||
|
||||
#include "Scene/EditorSceneRuntime.h"
|
||||
#include "State/EditorCommandFocusService.h"
|
||||
|
||||
#include <XCEditor/Collections/UIEditorTreePanelBehavior.h>
|
||||
#include <XCEditor/Fields/UIEditorFieldStyle.h>
|
||||
@@ -37,6 +38,13 @@ bool HasValidBounds(const UIRect& bounds) {
|
||||
return bounds.width > 0.0f && bounds.height > 0.0f;
|
||||
}
|
||||
|
||||
bool ContainsPoint(const UIRect& rect, const UIPoint& point) {
|
||||
return point.x >= rect.x &&
|
||||
point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y &&
|
||||
point.y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void HierarchyPanel::Initialize() {
|
||||
@@ -52,6 +60,11 @@ void HierarchyPanel::SetSceneRuntime(EditorSceneRuntime* sceneRuntime) {
|
||||
SyncModelFromScene();
|
||||
}
|
||||
|
||||
void HierarchyPanel::SetCommandFocusService(
|
||||
EditorCommandFocusService* commandFocusService) {
|
||||
m_commandFocusService = commandFocusService;
|
||||
}
|
||||
|
||||
void HierarchyPanel::SetBuiltInIcons(const BuiltInIcons* icons) {
|
||||
m_icons = icons;
|
||||
RebuildItems();
|
||||
@@ -319,6 +332,31 @@ void HierarchyPanel::SyncTreeFocusState(
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyPanel::ClaimCommandFocus(
|
||||
const std::vector<UIInputEvent>& inputEvents,
|
||||
const UIRect& bounds,
|
||||
bool allowInteraction) {
|
||||
if (m_commandFocusService == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const UIInputEvent& event : inputEvents) {
|
||||
if (event.type == ::XCEngine::UI::UIInputEventType::FocusGained) {
|
||||
m_commandFocusService->ClaimFocus(EditorActionRoute::Hierarchy);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowInteraction ||
|
||||
event.type != ::XCEngine::UI::UIInputEventType::PointerButtonDown ||
|
||||
!ContainsPoint(bounds, event.position)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
m_commandFocusService->ClaimFocus(EditorActionRoute::Hierarchy);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
UIRect HierarchyPanel::BuildRenameBounds(
|
||||
std::string_view itemId,
|
||||
const Widgets::UIEditorTreeViewLayout& layout) const {
|
||||
@@ -564,6 +602,7 @@ void HierarchyPanel::Update(
|
||||
.captureActive = HasActivePointerCapture()
|
||||
});
|
||||
SyncTreeFocusState(filteredEvents);
|
||||
ClaimCommandFocus(filteredEvents, panelState->bounds, allowInteraction);
|
||||
|
||||
const Widgets::UIEditorTreeViewMetrics treeMetrics =
|
||||
ResolveUIEditorTreeViewMetrics();
|
||||
|
||||
Reference in New Issue
Block a user