载入中...
搜索中...
未找到
UiThemeProperty.cpp
浏览该文件的文档.
3
4#include <algorithm>
5#include <optional>
6#include <utility>
7
8namespace eve::ui_editing {
9namespace {
10
11} // namespace
12
13bool UiThemeCatalogTarget::matches(const SelectionSnapshot& selection) const {
14 if (selection.items.empty()) return false;
15 for (const auto& item : selection.items) {
16 if (item.target != TargetId(id_) || item.type != "ui.theme" || !findTheme(ObjectId(item.item.value())))
17 return false;
18 }
19 return true;
20}
21
28
30
32 if (!matches(selection) || !schema(selection).find(path)) return {};
33 std::optional<EditorValue> common;
34 for (const auto& item : selection.items) {
35 const UiThemeAsset* asset = findTheme(ObjectId(item.item.value()));
37 if (!common)
38 common = value;
39 else if (*common != value)
40 return {PropertyReadState::Mixed, {}, {}};
41 }
42 return {PropertyReadState::Value, *common, {}};
43}
44
46 const PropertyPath& path, const EditorValue& value,
47 PropertySetMode mode) const {
48 if (mode == PropertySetMode::Reset) return makeReset(selection, path);
49 auto descriptor = schema(selection).find(path);
50 if (!matches(selection) || !descriptor || mode != PropertySetMode::Absolute ||
52 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.ui-theme.set"),
53 "Theme property edit is invalid");
54 auto candidate = *this;
55 for (const auto& item : selection.items) {
56 UiThemeAsset* asset = candidate.mutableTheme(ObjectId(item.item.value()));
57 if (!asset)
58 return eve::editing::failed<DomainOperation>(EditorStatus::NotFound, RuleId("editor.ui-theme.missing"),
59 "Theme asset does not exist");
60 auto assigned = assignThemeToken(asset->tokens, path, value);
61 if (!assigned.ok())
62 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.ui-theme.token"),
63 "Theme token could not be assigned");
64 if (asset->id.value() != "dark" && asset->id.value() != "light")
66 }
67 auto diagnostics = candidate.validate();
68 if (std::any_of(diagnostics.begin(), diagnostics.end(),
69 [](const EditorDiagnostic& item) { return item.severity() == DiagnosticSeverity::Error; }))
70 return eve::editing::failed<DomainOperation>(EditorStatus::Rejected, RuleId("editor.ui-theme.invalid"),
71 "Theme property edit is out of range");
72 return replacement(candidate.contentValue(), path.value());
73}
74
76 const PropertyPath& path) const {
77 auto descriptor = schema(selection).find(path);
78 if (!descriptor)
79 return eve::editing::failed<DomainOperation>(EditorStatus::Unsupported, RuleId("editor.ui-theme.property"),
80 "Unknown theme property");
81 return makeSet(selection, path, descriptor->defaultValue, PropertySetMode::Absolute);
82}
83
84} // namespace eve::ui_editing
double value
std::string descriptor
std::string path
Definition PlayHost.cpp:110
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Revision revisionValue() const noexcept
Return the revision as the shared protocol revision type.
Dotted property path (layout.size) compared and persisted as text.
Definition EditingIds.h:78
Deterministic owning value tree shared by authoring hosts.
eve::Result< eve::Revision > currentRevision(const SelectionSnapshot &selection) const override
Current revision.
PropertySchema schema(const SelectionSnapshot &selection) const override
Schema.
PropertyReadResult read(const SelectionSnapshot &selection, const PropertyPath &path) const override
Reads .
Result< DomainOperation > makeReset(const SelectionSnapshot &selection, const PropertyPath &path) const override
Make reset.
Result< DomainOperation > makeSet(const SelectionSnapshot &selection, const PropertyPath &path, const EditorValue &value, PropertySetMode mode) const override
Make set.
editing::ObjectId ObjectId
editing::TargetId TargetId
Result< void > validatePropertyValue(const PropertyDescriptor &descriptor, const Value &value)
Validate property value.
EditorValue readThemeToken(const ui::Theme &theme, const PropertyPath &path)
Reads theme token.
Result< void > assignThemeToken(ui::Theme &theme, const PropertyPath &path, const EditorValue &value)
Assign theme token.
PropertySchema themeTokenSchema()
Theme token schema.
PropertyReadResult public API.
EVENGINE_API_PLATFORM public API.
PropertyDescriptorLookup find(const PropertyPath &path) const
Finds find.
SelectionSnapshot public API.
std::vector< SelectionItem > items
One named, fully snapshotted Theme asset.
Definition UiTheme.h:47
UiThemeBasePreset basePreset
Definition UiTheme.h:50