Expand XCUI layout lab editor widgets
This commit is contained in:
@@ -388,6 +388,15 @@ void EmitNode(
|
||||
++stats.textCommandCount;
|
||||
}
|
||||
|
||||
if (tagName == "Button" && title.empty() && subtitle.empty()) {
|
||||
drawList.AddText(
|
||||
UIPoint(node.rect.x + 12.0f, node.rect.y + 12.0f),
|
||||
ResolveNodeText(source),
|
||||
ToUIColor(Color(0.95f, 0.97f, 1.0f, 1.0f)),
|
||||
kDefaultFontSize);
|
||||
++stats.textCommandCount;
|
||||
}
|
||||
|
||||
for (const RuntimeLayoutNode& child : node.children) {
|
||||
EmitNode(child, drawList, stats);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,43 @@
|
||||
#include <XCEngine/UI/Runtime/UISystem.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace UI {
|
||||
namespace Runtime {
|
||||
|
||||
namespace {
|
||||
|
||||
std::size_t FindTopInputLayerIndex(
|
||||
const std::vector<UIScreenLayerOptions>& layerOptions,
|
||||
std::size_t lowestPresentedIndex) {
|
||||
if (layerOptions.empty() || lowestPresentedIndex >= layerOptions.size()) {
|
||||
return static_cast<std::size_t>(-1);
|
||||
}
|
||||
|
||||
for (std::size_t index = layerOptions.size(); index-- > lowestPresentedIndex;) {
|
||||
if (layerOptions[index].visible && layerOptions[index].acceptsInput) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<std::size_t>(-1);
|
||||
}
|
||||
|
||||
std::size_t FindLowestPresentedLayerIndex(const std::vector<UIScreenLayerOptions>& layerOptions) {
|
||||
if (layerOptions.empty()) {
|
||||
return 0u;
|
||||
}
|
||||
|
||||
for (std::size_t index = layerOptions.size(); index-- > 0u;) {
|
||||
if (layerOptions[index].visible && layerOptions[index].blocksLayersBelow) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return 0u;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
UISystem::UISystem(IUIScreenDocumentHost& documentHost)
|
||||
: m_documentHost(&documentHost) {
|
||||
}
|
||||
@@ -27,7 +59,8 @@ UIScreenLayerId UISystem::PushScreen(
|
||||
m_layerOptions.pop_back();
|
||||
return 0;
|
||||
}
|
||||
return m_layerIds.empty() ? 0 : m_layerIds.back();
|
||||
|
||||
return m_layerIds.back();
|
||||
}
|
||||
|
||||
bool UISystem::RemoveLayer(UIScreenLayerId layerId) {
|
||||
@@ -52,9 +85,7 @@ bool UISystem::SetLayerVisibility(UIScreenLayerId layerId, bool visible) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UISystem::SetLayerOptions(
|
||||
UIScreenLayerId layerId,
|
||||
const UIScreenLayerOptions& options) {
|
||||
bool UISystem::SetLayerOptions(UIScreenLayerId layerId, const UIScreenLayerOptions& options) {
|
||||
const std::size_t index = FindLayerIndex(layerId);
|
||||
if (index >= m_layerOptions.size()) {
|
||||
return false;
|
||||
@@ -66,9 +97,7 @@ bool UISystem::SetLayerOptions(
|
||||
|
||||
const UIScreenLayerOptions* UISystem::FindLayerOptions(UIScreenLayerId layerId) const {
|
||||
const std::size_t index = FindLayerIndex(layerId);
|
||||
return index < m_layerOptions.size()
|
||||
? &m_layerOptions[index]
|
||||
: nullptr;
|
||||
return index < m_layerOptions.size() ? &m_layerOptions[index] : nullptr;
|
||||
}
|
||||
|
||||
UIScreenLayerId UISystem::GetLayerId(std::size_t index) const {
|
||||
@@ -94,71 +123,54 @@ const UISystemFrameResult& UISystem::Update(const UIScreenFrameInput& input) {
|
||||
m_lastFrame = {};
|
||||
m_lastFrame.frameIndex = input.frameIndex;
|
||||
|
||||
std::vector<std::size_t> presentedIndices;
|
||||
presentedIndices.reserve(m_players.size());
|
||||
for (std::size_t index = m_players.size(); index > 0; --index) {
|
||||
const std::size_t layerIndex = index - 1;
|
||||
if (!m_layerOptions[layerIndex].visible) {
|
||||
if (m_players.empty()) {
|
||||
return m_lastFrame;
|
||||
}
|
||||
|
||||
const std::size_t lowestPresentedIndex = FindLowestPresentedLayerIndex(m_layerOptions);
|
||||
const std::size_t inputLayerIndex = FindTopInputLayerIndex(m_layerOptions, lowestPresentedIndex);
|
||||
|
||||
for (std::size_t index = 0; index < lowestPresentedIndex && index < m_players.size(); ++index) {
|
||||
++m_lastFrame.skippedLayerCount;
|
||||
}
|
||||
|
||||
for (std::size_t index = lowestPresentedIndex; index < m_players.size(); ++index) {
|
||||
if (!m_layerOptions[index].visible) {
|
||||
++m_lastFrame.skippedLayerCount;
|
||||
continue;
|
||||
}
|
||||
|
||||
presentedIndices.push_back(layerIndex);
|
||||
if (m_layerOptions[layerIndex].blocksLayersBelow) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::reverse(presentedIndices.begin(), presentedIndices.end());
|
||||
|
||||
std::size_t interactiveLayerIndex = m_players.size();
|
||||
for (std::size_t index = presentedIndices.size(); index > 0; --index) {
|
||||
const std::size_t layerIndex = presentedIndices[index - 1];
|
||||
if (m_layerOptions[layerIndex].acceptsInput) {
|
||||
interactiveLayerIndex = layerIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::size_t layerIndex : presentedIndices) {
|
||||
UIScreenFrameInput layerInput = input;
|
||||
if (layerIndex != interactiveLayerIndex) {
|
||||
if (index != inputLayerIndex) {
|
||||
layerInput.events.clear();
|
||||
layerInput.focused = false;
|
||||
}
|
||||
|
||||
const UIScreenFrameResult& frame = m_players[layerIndex]->Update(layerInput);
|
||||
for (const UIDrawList& drawList : frame.drawData.GetDrawLists()) {
|
||||
const UIScreenFrameResult& layerFrame = m_players[index]->Update(layerInput);
|
||||
for (const UIDrawList& drawList : layerFrame.drawData.GetDrawLists()) {
|
||||
m_lastFrame.drawData.AddDrawList(drawList);
|
||||
}
|
||||
|
||||
UISystemPresentedLayer presentedLayer = {};
|
||||
presentedLayer.layerId = m_layerIds[layerIndex];
|
||||
if (const UIScreenAsset* asset = m_players[layerIndex]->GetAsset();
|
||||
asset != nullptr) {
|
||||
presentedLayer.layerId = m_layerIds[index];
|
||||
if (const UIScreenAsset* asset = m_players[index]->GetAsset(); asset != nullptr) {
|
||||
presentedLayer.asset = *asset;
|
||||
}
|
||||
presentedLayer.options = m_layerOptions[layerIndex];
|
||||
presentedLayer.stats = frame.stats;
|
||||
presentedLayer.options = m_layerOptions[index];
|
||||
presentedLayer.stats = layerFrame.stats;
|
||||
m_lastFrame.layers.push_back(std::move(presentedLayer));
|
||||
++m_lastFrame.presentedLayerCount;
|
||||
|
||||
if (m_lastFrame.errorMessage.empty() && !frame.errorMessage.empty()) {
|
||||
m_lastFrame.errorMessage = frame.errorMessage;
|
||||
if (m_lastFrame.errorMessage.empty() && !layerFrame.errorMessage.empty()) {
|
||||
m_lastFrame.errorMessage = layerFrame.errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
m_lastFrame.presentedLayerCount = m_lastFrame.layers.size();
|
||||
m_lastFrame.skippedLayerCount =
|
||||
m_players.size() > m_lastFrame.presentedLayerCount
|
||||
? m_players.size() - m_lastFrame.presentedLayerCount
|
||||
: 0;
|
||||
return m_lastFrame;
|
||||
}
|
||||
|
||||
void UISystem::Tick(const UIScreenFrameInput& input) {
|
||||
for (const std::unique_ptr<UIScreenPlayer>& player : m_players) {
|
||||
if (player) {
|
||||
player->Update(input);
|
||||
}
|
||||
}
|
||||
Update(input);
|
||||
}
|
||||
|
||||
const UISystemFrameResult& UISystem::GetLastFrame() const {
|
||||
@@ -176,7 +188,7 @@ std::size_t UISystem::FindLayerIndex(UIScreenLayerId layerId) const {
|
||||
}
|
||||
}
|
||||
|
||||
return m_layerIds.size();
|
||||
return static_cast<std::size_t>(-1);
|
||||
}
|
||||
|
||||
} // namespace Runtime
|
||||
|
||||
Reference in New Issue
Block a user