Add XCUI expansion state and coverage tests

This commit is contained in:
2026-04-05 07:29:27 +08:00
parent 646e5855ce
commit 511e94fd30
18 changed files with 1213 additions and 53 deletions

View File

@@ -64,6 +64,7 @@ bool UsesUIEditorCollectionPrimitiveColumnLayout(UIEditorCollectionPrimitiveKind
bool IsUIEditorCollectionPrimitiveHoverable(UIEditorCollectionPrimitiveKind kind) {
return kind == UIEditorCollectionPrimitiveKind::TreeItem ||
kind == UIEditorCollectionPrimitiveKind::ListItem ||
kind == UIEditorCollectionPrimitiveKind::PropertySection ||
kind == UIEditorCollectionPrimitiveKind::FieldRow;
}

View File

@@ -0,0 +1,57 @@
#include <XCEngine/UI/Widgets/UIExpansionModel.h>
#include <utility>
namespace XCEngine {
namespace UI {
namespace Widgets {
bool UIExpansionModel::HasExpandedItems() const {
return !m_expandedIds.empty();
}
std::size_t UIExpansionModel::GetExpandedCount() const {
return m_expandedIds.size();
}
bool UIExpansionModel::IsExpanded(std::string_view id) const {
return m_expandedIds.contains(std::string(id));
}
bool UIExpansionModel::SetExpanded(std::string itemId, bool expanded) {
return expanded
? Expand(std::move(itemId))
: Collapse(std::move(itemId));
}
bool UIExpansionModel::Expand(std::string itemId) {
return m_expandedIds.insert(std::move(itemId)).second;
}
bool UIExpansionModel::Collapse(std::string itemId) {
return m_expandedIds.erase(itemId) > 0u;
}
bool UIExpansionModel::ToggleExpanded(std::string itemId) {
const auto it = m_expandedIds.find(itemId);
if (it != m_expandedIds.end()) {
m_expandedIds.erase(it);
return true;
}
m_expandedIds.insert(std::move(itemId));
return true;
}
bool UIExpansionModel::Clear() {
if (m_expandedIds.empty()) {
return false;
}
m_expandedIds.clear();
return true;
}
} // namespace Widgets
} // namespace UI
} // namespace XCEngine