Add XCUI runtime screen layer and demo textarea
This commit is contained in:
29
engine/include/XCEngine/UI/Runtime/UIScreenDocumentHost.h
Normal file
29
engine/include/XCEngine/UI/Runtime/UIScreenDocumentHost.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/Runtime/UIScreenTypes.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace UI {
|
||||
namespace Runtime {
|
||||
|
||||
class IUIScreenDocumentHost {
|
||||
public:
|
||||
virtual ~IUIScreenDocumentHost() = default;
|
||||
|
||||
virtual UIScreenLoadResult LoadScreen(const UIScreenAsset& asset) = 0;
|
||||
virtual UIScreenFrameResult BuildFrame(
|
||||
const UIScreenDocument& document,
|
||||
const UIScreenFrameInput& input) = 0;
|
||||
};
|
||||
|
||||
class UIDocumentScreenHost final : public IUIScreenDocumentHost {
|
||||
public:
|
||||
UIScreenLoadResult LoadScreen(const UIScreenAsset& asset) override;
|
||||
UIScreenFrameResult BuildFrame(
|
||||
const UIScreenDocument& document,
|
||||
const UIScreenFrameInput& input) override;
|
||||
};
|
||||
|
||||
} // namespace Runtime
|
||||
} // namespace UI
|
||||
} // namespace XCEngine
|
||||
39
engine/include/XCEngine/UI/Runtime/UIScreenPlayer.h
Normal file
39
engine/include/XCEngine/UI/Runtime/UIScreenPlayer.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/Runtime/UIScreenDocumentHost.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace UI {
|
||||
namespace Runtime {
|
||||
|
||||
class UIScreenPlayer {
|
||||
public:
|
||||
explicit UIScreenPlayer(IUIScreenDocumentHost& documentHost);
|
||||
|
||||
bool Load(const UIScreenAsset& asset);
|
||||
void Unload();
|
||||
|
||||
bool IsLoaded() const;
|
||||
const UIScreenAsset* GetAsset() const;
|
||||
const UIScreenDocument* GetDocument() const;
|
||||
const UIScreenFrameResult& GetLastFrame() const;
|
||||
const std::string& GetLastError() const;
|
||||
std::uint64_t GetPresentedFrameCount() const;
|
||||
|
||||
const UIScreenFrameResult& Update(const UIScreenFrameInput& input);
|
||||
|
||||
private:
|
||||
IUIScreenDocumentHost* m_documentHost = nullptr;
|
||||
UIScreenAsset m_asset = {};
|
||||
UIScreenDocument m_document = {};
|
||||
UIScreenFrameResult m_lastFrame = {};
|
||||
std::string m_lastError = {};
|
||||
std::uint64_t m_presentedFrameCount = 0;
|
||||
};
|
||||
|
||||
} // namespace Runtime
|
||||
} // namespace UI
|
||||
} // namespace XCEngine
|
||||
100
engine/include/XCEngine/UI/Runtime/UIScreenTypes.h
Normal file
100
engine/include/XCEngine/UI/Runtime/UIScreenTypes.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/Resources/UI/UIDocumentTypes.h>
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace UI {
|
||||
namespace Runtime {
|
||||
|
||||
using UIScreenLayerId = std::uint64_t;
|
||||
|
||||
struct UIScreenAsset {
|
||||
std::string screenId = {};
|
||||
std::string documentPath = {};
|
||||
std::string themePath = {};
|
||||
|
||||
bool IsValid() const {
|
||||
return !documentPath.empty();
|
||||
}
|
||||
};
|
||||
|
||||
struct UIScreenDocument {
|
||||
std::string sourcePath = {};
|
||||
std::string displayName = {};
|
||||
std::vector<std::string> dependencies = {};
|
||||
Resources::UIDocumentModel viewDocument = {};
|
||||
Resources::UIDocumentModel themeDocument = {};
|
||||
bool hasThemeDocument = false;
|
||||
|
||||
bool IsValid() const {
|
||||
return !sourcePath.empty();
|
||||
}
|
||||
|
||||
const Resources::UIDocumentModel* GetThemeDocument() const {
|
||||
return hasThemeDocument ? &themeDocument : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct UIScreenLoadResult {
|
||||
bool succeeded = false;
|
||||
std::string errorMessage = {};
|
||||
UIScreenDocument document = {};
|
||||
};
|
||||
|
||||
struct UIScreenFrameInput {
|
||||
UIRect viewportRect = {};
|
||||
std::vector<UIInputEvent> events = {};
|
||||
double deltaTimeSeconds = 0.0;
|
||||
std::uint64_t frameIndex = 0;
|
||||
bool focused = false;
|
||||
};
|
||||
|
||||
struct UIScreenFrameStats {
|
||||
bool documentLoaded = false;
|
||||
std::size_t drawListCount = 0;
|
||||
std::size_t commandCount = 0;
|
||||
std::size_t inputEventCount = 0;
|
||||
std::size_t nodeCount = 0;
|
||||
std::size_t filledRectCommandCount = 0;
|
||||
std::size_t textCommandCount = 0;
|
||||
std::uint64_t presentedFrameIndex = 0;
|
||||
};
|
||||
|
||||
struct UIScreenFrameResult {
|
||||
UIDrawData drawData = {};
|
||||
UIScreenFrameStats stats = {};
|
||||
std::string errorMessage = {};
|
||||
};
|
||||
|
||||
struct UIScreenLayerOptions {
|
||||
std::string debugName = {};
|
||||
bool visible = true;
|
||||
bool acceptsInput = true;
|
||||
bool blocksLayersBelow = false;
|
||||
};
|
||||
|
||||
struct UISystemPresentedLayer {
|
||||
UIScreenLayerId layerId = 0;
|
||||
UIScreenAsset asset = {};
|
||||
UIScreenLayerOptions options = {};
|
||||
UIScreenFrameStats stats = {};
|
||||
};
|
||||
|
||||
struct UISystemFrameResult {
|
||||
UIDrawData drawData = {};
|
||||
std::vector<UISystemPresentedLayer> layers = {};
|
||||
std::size_t presentedLayerCount = 0;
|
||||
std::size_t skippedLayerCount = 0;
|
||||
std::uint64_t frameIndex = 0;
|
||||
std::string errorMessage = {};
|
||||
};
|
||||
|
||||
} // namespace Runtime
|
||||
} // namespace UI
|
||||
} // namespace XCEngine
|
||||
50
engine/include/XCEngine/UI/Runtime/UISystem.h
Normal file
50
engine/include/XCEngine/UI/Runtime/UISystem.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/Runtime/UIScreenPlayer.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace UI {
|
||||
namespace Runtime {
|
||||
|
||||
class UISystem {
|
||||
public:
|
||||
explicit UISystem(IUIScreenDocumentHost& documentHost);
|
||||
|
||||
UIScreenPlayer& CreatePlayer(const UIScreenLayerOptions& options = UIScreenLayerOptions());
|
||||
UIScreenLayerId PushScreen(
|
||||
const UIScreenAsset& asset,
|
||||
const UIScreenLayerOptions& options = UIScreenLayerOptions());
|
||||
bool RemoveLayer(UIScreenLayerId layerId);
|
||||
bool SetLayerVisibility(UIScreenLayerId layerId, bool visible);
|
||||
bool SetLayerOptions(UIScreenLayerId layerId, const UIScreenLayerOptions& options);
|
||||
const UIScreenLayerOptions* FindLayerOptions(UIScreenLayerId layerId) const;
|
||||
UIScreenLayerId GetLayerId(std::size_t index) const;
|
||||
void DestroyAllPlayers();
|
||||
|
||||
std::size_t GetPlayerCount() const;
|
||||
std::size_t GetLayerCount() const;
|
||||
|
||||
const UISystemFrameResult& Update(const UIScreenFrameInput& input);
|
||||
void Tick(const UIScreenFrameInput& input);
|
||||
const UISystemFrameResult& GetLastFrame() const;
|
||||
|
||||
const std::vector<std::unique_ptr<UIScreenPlayer>>& GetPlayers() const;
|
||||
|
||||
private:
|
||||
std::size_t FindLayerIndex(UIScreenLayerId layerId) const;
|
||||
|
||||
IUIScreenDocumentHost* m_documentHost = nullptr;
|
||||
std::vector<std::unique_ptr<UIScreenPlayer>> m_players = {};
|
||||
std::vector<UIScreenLayerId> m_layerIds = {};
|
||||
std::vector<UIScreenLayerOptions> m_layerOptions = {};
|
||||
UISystemFrameResult m_lastFrame = {};
|
||||
UIScreenLayerId m_nextLayerId = 1;
|
||||
};
|
||||
|
||||
} // namespace Runtime
|
||||
} // namespace UI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user