Wire XCUI layout lab panel keyboard navigation

This commit is contained in:
2026-04-05 12:53:05 +08:00
parent e5e9f348a3
commit a35adf14d3
4 changed files with 293 additions and 1 deletions

View File

@@ -46,6 +46,33 @@ const char* GetPreviewStateLabel(
return previewStats.presented ? "live" : "idle";
}
bool ShouldCaptureKeyboardNavigation(
const ::XCEngine::Editor::XCUIBackend::XCUIPanelCanvasSession& canvasSession,
const ::XCEngine::Editor::XCUIBackend::XCUILayoutLabFrameResult& previousFrame) {
if (!canvasSession.validCanvas) {
return false;
}
return canvasSession.hovered ||
(canvasSession.windowFocused &&
!previousFrame.stats.selectedElementId.empty());
}
void PopulateKeyboardNavigationInput(
::XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState& input,
bool captureKeyboardNavigation) {
if (!captureKeyboardNavigation) {
return;
}
input.navigatePrevious = ImGui::IsKeyPressed(ImGuiKey_UpArrow);
input.navigateNext = ImGui::IsKeyPressed(ImGuiKey_DownArrow);
input.navigateHome = ImGui::IsKeyPressed(ImGuiKey_Home);
input.navigateEnd = ImGui::IsKeyPressed(ImGuiKey_End);
input.navigateCollapse = ImGui::IsKeyPressed(ImGuiKey_LeftArrow);
input.navigateExpand = ImGui::IsKeyPressed(ImGuiKey_RightArrow);
}
} // namespace
XCUILayoutLabPanel::XCUILayoutLabPanel(::XCEngine::Editor::XCUIBackend::XCUIWin32InputSource* inputSource)
@@ -79,6 +106,10 @@ const ::XCEngine::Editor::XCUIBackend::XCUIHostedPreviewStats& XCUILayoutLabPane
return m_lastPreviewStats;
}
bool XCUILayoutLabPanel::TryGetElementRect(const std::string& elementId, ::XCEngine::UI::UIRect& outRect) const {
return m_runtime.TryGetElementRect(elementId, outRect);
}
void XCUILayoutLabPanel::SetHostedPreviewPresenter(
std::unique_ptr<::XCEngine::Editor::XCUIBackend::IXCUIHostedPreviewPresenter> previewPresenter) {
m_previewPresenter = std::move(previewPresenter);
@@ -168,6 +199,9 @@ void XCUILayoutLabPanel::Render() {
input.pointerInside = validCanvas && canvasSession.hovered;
}
input.pointerPressed = input.pointerInside && ImGui::IsMouseClicked(ImGuiMouseButton_Left);
PopulateKeyboardNavigationInput(
input,
ShouldCaptureKeyboardNavigation(canvasSession, m_runtime.GetFrameResult()));
const ::XCEngine::Editor::XCUIBackend::XCUILayoutLabFrameResult& frame = m_runtime.Update(input);

View File

@@ -8,6 +8,7 @@
#include "XCUIBackend/XCUILayoutLabRuntime.h"
#include <memory>
#include <string>
namespace XCEngine {
namespace NewEditor {
@@ -31,6 +32,7 @@ public:
bool IsUsingNativeHostedPreview() const;
const ::XCEngine::Editor::XCUIBackend::XCUILayoutLabFrameResult& GetFrameResult() const;
const ::XCEngine::Editor::XCUIBackend::XCUIHostedPreviewStats& GetLastPreviewStats() const;
bool TryGetElementRect(const std::string& elementId, ::XCEngine::UI::UIRect& outRect) const;
private:
bool m_lastReloadSucceeded = false;