Add XCUI expansion state and coverage tests
This commit is contained in:
@@ -521,8 +521,10 @@ add_library(XCEngine STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/UI/Text/UITextEditing.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/UI/Text/UITextInputController.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/UI/Widgets/UIEditorCollectionPrimitives.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/UI/Widgets/UIExpansionModel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/UI/Widgets/UISelectionModel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/UI/Widgets/UIEditorCollectionPrimitives.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/UI/Widgets/UIExpansionModel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/UI/Widgets/UISelectionModel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/UI/Runtime/UIScreenTypes.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/UI/Runtime/UIScreenDocumentHost.h
|
||||
|
||||
30
engine/include/XCEngine/UI/Widgets/UIExpansionModel.h
Normal file
30
engine/include/XCEngine/UI/Widgets/UIExpansionModel.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace UI {
|
||||
namespace Widgets {
|
||||
|
||||
class UIExpansionModel {
|
||||
public:
|
||||
bool HasExpandedItems() const;
|
||||
std::size_t GetExpandedCount() const;
|
||||
bool IsExpanded(std::string_view id) const;
|
||||
|
||||
bool SetExpanded(std::string itemId, bool expanded);
|
||||
bool Expand(std::string itemId);
|
||||
bool Collapse(std::string itemId);
|
||||
bool ToggleExpanded(std::string itemId);
|
||||
bool Clear();
|
||||
|
||||
private:
|
||||
std::unordered_set<std::string> m_expandedIds = {};
|
||||
};
|
||||
|
||||
} // namespace Widgets
|
||||
} // namespace UI
|
||||
} // namespace XCEngine
|
||||
@@ -64,6 +64,7 @@ bool UsesUIEditorCollectionPrimitiveColumnLayout(UIEditorCollectionPrimitiveKind
|
||||
bool IsUIEditorCollectionPrimitiveHoverable(UIEditorCollectionPrimitiveKind kind) {
|
||||
return kind == UIEditorCollectionPrimitiveKind::TreeItem ||
|
||||
kind == UIEditorCollectionPrimitiveKind::ListItem ||
|
||||
kind == UIEditorCollectionPrimitiveKind::PropertySection ||
|
||||
kind == UIEditorCollectionPrimitiveKind::FieldRow;
|
||||
}
|
||||
|
||||
|
||||
57
engine/src/UI/Widgets/UIExpansionModel.cpp
Normal file
57
engine/src/UI/Widgets/UIExpansionModel.cpp
Normal 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
|
||||
Reference in New Issue
Block a user