Sync editor rendering and UI workspace updates

This commit is contained in:
2026-04-09 02:59:36 +08:00
parent 23b23a56be
commit d46bf87970
107 changed files with 10918 additions and 430 deletions

View File

@@ -1,49 +1,158 @@
#include <XCEngine/UI/Widgets/UISelectionModel.h>
#include <algorithm>
namespace XCEngine {
namespace UI {
namespace Widgets {
bool UISelectionModel::HasSelection() const {
return !m_selectedId.empty();
return !m_primarySelectedId.empty();
}
const std::string& UISelectionModel::GetSelectedId() const {
return m_selectedId;
return m_primarySelectedId;
}
const std::vector<std::string>& UISelectionModel::GetSelectedIds() const {
return m_selectedIds;
}
std::size_t UISelectionModel::GetSelectionCount() const {
return m_selectedIds.size();
}
bool UISelectionModel::HasMultipleSelection() const {
return m_selectedIds.size() > 1u;
}
bool UISelectionModel::IsSelected(std::string_view id) const {
return !m_selectedId.empty() && m_selectedId == id;
return std::find(m_selectedIds.begin(), m_selectedIds.end(), id) != m_selectedIds.end();
}
bool UISelectionModel::SetSelection(std::string selectionId) {
if (m_selectedId == selectionId) {
return SetSelections(
selectionId.empty() ? std::vector<std::string> {} : std::vector<std::string> { std::move(selectionId) });
}
bool UISelectionModel::SetSelections(
std::vector<std::string> selectionIds,
std::string primarySelectionId) {
NormalizeSelectionIds(selectionIds);
if (selectionIds.empty()) {
return ClearSelection();
}
if (primarySelectionId.empty()) {
primarySelectionId = selectionIds.back();
}
std::vector<std::string> normalizedSelections = std::move(selectionIds);
const auto preferredPrimaryIt =
std::find(normalizedSelections.begin(), normalizedSelections.end(), primarySelectionId);
if (preferredPrimaryIt == normalizedSelections.end()) {
primarySelectionId = normalizedSelections.back();
}
if (m_selectedIds == normalizedSelections &&
m_primarySelectedId == primarySelectionId) {
return false;
}
m_selectedId = std::move(selectionId);
m_selectedIds = std::move(normalizedSelections);
m_primarySelectedId = std::move(primarySelectionId);
return true;
}
bool UISelectionModel::SetPrimarySelection(std::string selectionId) {
if (!IsSelected(selectionId)) {
return false;
}
if (m_primarySelectedId == selectionId) {
return false;
}
m_primarySelectedId = std::move(selectionId);
return true;
}
bool UISelectionModel::AddSelection(std::string selectionId, bool makePrimary) {
if (selectionId.empty()) {
return false;
}
if (IsSelected(selectionId)) {
return makePrimary ? SetPrimarySelection(std::move(selectionId)) : false;
}
m_selectedIds.push_back(selectionId);
if (makePrimary || m_primarySelectedId.empty()) {
m_primarySelectedId = std::move(selectionId);
}
return true;
}
bool UISelectionModel::RemoveSelection(std::string_view selectionId) {
const auto it = std::find(m_selectedIds.begin(), m_selectedIds.end(), selectionId);
if (it == m_selectedIds.end()) {
return false;
}
const bool removedPrimary = m_primarySelectedId == selectionId;
m_selectedIds.erase(it);
if (m_selectedIds.empty()) {
m_primarySelectedId.clear();
} else if (removedPrimary) {
m_primarySelectedId = m_selectedIds.back();
}
return true;
}
bool UISelectionModel::ClearSelection() {
if (m_selectedId.empty()) {
if (m_selectedIds.empty()) {
return false;
}
m_selectedId.clear();
m_selectedIds.clear();
m_primarySelectedId.clear();
return true;
}
bool UISelectionModel::ToggleSelection(std::string selectionId) {
if (m_selectedId == selectionId) {
m_selectedId.clear();
return true;
if (selectionId.empty()) {
return false;
}
m_selectedId = std::move(selectionId);
return true;
if (IsSelected(selectionId)) {
return RemoveSelection(selectionId);
}
return AddSelection(std::move(selectionId), true);
}
void UISelectionModel::NormalizeSelectionIds(std::vector<std::string>& selectionIds) {
selectionIds.erase(
std::remove_if(
selectionIds.begin(),
selectionIds.end(),
[](const std::string& selectionId) {
return selectionId.empty();
}),
selectionIds.end());
std::vector<std::string> normalized = {};
normalized.reserve(selectionIds.size());
for (std::string& selectionId : selectionIds) {
if (std::find(normalized.begin(), normalized.end(), selectionId) != normalized.end()) {
continue;
}
normalized.push_back(std::move(selectionId));
}
selectionIds = std::move(normalized);
}
} // namespace Widgets
} // namespace UI
} // namespace XCEngine