99 std::initializer_list<PopupEntry> entries,
101 std::vector<PopupEntry> owning(entries);
103 std::make_shared<Description<PopupMenu>>(detail::popupMenuRecipe(owning, options, {},
DEFAULT_MENU_POLICY));
107 [reference, owning = std::move(owning), options,
108 declarations](SceneResourceArguments arguments) -> std::expected<Description<PopupMenu>,
ManagedError> {
111 auto effective = options;
112 auto frame = detail::controlFrameOptions(arguments.settings, effective.frame, {});
115 return std::unexpected(frame.error());
119 effective.frame = **frame;
145 template <
class T,
class Factory>
147 std::expected<void, SceneResourceErrorCode>
add(std::string_view name, Factory factory,
bool children =
false) {
148 return insert(makeEntry<T>(name, std::move(factory), children));
162 template <
class T,
class Factory,
class Schema>
164 std::same_as<std::remove_cvref_t<Schema>, std::span<const ControlPropertyDescriptor>>
165 std::expected<void, SceneResourceErrorCode>
add(std::string_view name, Factory factory, Schema &&schema) {
166 const auto semantic = semanticSchema(schema);
172 auto entry = makeEntry<T>(name, std::move(factory),
false, *semantic);
175 entry.sized = *semantic == detail::ControlFactoryKind::NOTIFICATION_BINDING;
176 entry.factoryKind = *semantic;
177 entry.semanticPropertyCount = schema.size();
179 if (*semantic == detail::ControlFactoryKind::MESSAGE_BINDING) {
182 entry.messageChoiceCount = choice->enumNames.size();
185 return insert(std::move(entry));
189 friend struct detail::ResourceAccess;
191 static std::optional<detail::ControlFactoryKind>
192 semanticSchema(std::span<const ControlPropertyDescriptor> schema)
noexcept;
197 std::string name = std::string(0,
'\0');
203 bool protectedEditor{};
206 bool declaredDialog{};
208 bool declaredChoice{};
209 bool declaredSwitch{};
210 bool declaredRadio{};
211 bool unknownDialog{};
212 std::string_view virtualView{};
213 std::optional<std::size_t> semanticPropertyCount{};
214 std::size_t messageChoiceCount{};
215 detail::ControlFactoryKind factoryKind{detail::ControlFactoryKind::USER};
216 std::function<std::expected<Description<Widget>, ManagedError>(SceneResourceArguments)> create;
220 template <
class T,
class Factory>
221 requires detail::ResourceFactory<T, std::remove_cvref_t<Factory>>
222 static Entry makeEntry(std::string_view name, Factory &&factory,
bool children =
false,
223 detail::ControlFactoryKind semantic = detail::ControlFactoryKind::USER) {
227 entry.children = children;
228 entry.sized = std::derived_from<T, SizedWidget>;
229 entry.protectedEditor = std::same_as<T, Password>;
230 entry.declaredSwitch = std::same_as<T, Switch>;
231 if constexpr (std::same_as<T, Switch>) {
232 entry.checked =
true;
234 entry.declaredHelp = std::derived_from<T, HelpView>;
235 entry.unknownHelp = std::same_as<T, Widget>;
236 entry.declaredDialog = std::derived_from<T, Dialog>;
237 entry.declaredHost = std::derived_from<T, OverlayHost>;
238 entry.declaredChoice = std::derived_from<T, ComboBox>;
239 entry.declaredRadio = std::same_as<T, RadioGroup>;
240 if constexpr (std::same_as<T, RadioGroup>) {
243 entry.unknownDialog = std::same_as<T, Widget>;
245 if constexpr (std::derived_from<T, Slider>) {
247 entry.virtualView =
"Slider";
248 }
else if constexpr (std::same_as<T, SpinBox>) {
249 entry.virtualView =
"SpinBox";
252 if constexpr (detail::IsVirtualList<T>::value || detail::IsVirtualTable<T>::value || detail::IsChart<T>::value) {
256 entry.create = [factory = std::forward<Factory>(factory), semantic](
257 SceneResourceArguments arguments)
mutable -> std::expected<Description<Widget>, ManagedError> {
259 const auto sizing = detail::controlSizing(arguments.settings);
261 if constexpr (!std::derived_from<T, SizedWidget>) {
262 if (semantic != detail::ControlFactoryKind::NOTIFICATION_BINDING && (sizing.width || sizing.height)) {
263 return std::unexpected(detail::frameContextError(ControlContextErrorCode::UNSUPPORTED_PROPERTY,
"sizing"));
266 const auto switchState = arguments.settings.state;
267 const auto switchCycle = arguments.settings.cycle;
268 const auto switchReadOnly = arguments.settings.readOnly;
269 const auto switchOrigin = arguments.settings.origin;
270 std::vector<ControlPropertyOrigin> switchOrigins(0);
272 if constexpr (std::same_as<T, Switch>) {
273 for (
const auto path : {
"state",
"cycle",
"readOnly"}) {
274 const bool present = path == std::string_view(
"state") ? switchState.has_value()
275 : path == std::string_view(
"cycle") ? switchCycle.has_value()
276 : switchReadOnly.has_value();
283 switchOrigins.push_back(
284 {std::string(path), found == arguments.settings.origins.end() ? switchOrigin : found->source});
287 const auto visible = arguments.visible;
288 const auto enabled = arguments.enabled;
289 const auto classes = arguments.classes;
290 const auto materialized = detail::controlSettingsPresenceSet(arguments.settings);
291 std::optional<ControlSettings> numericSettings;
293 if constexpr (std::derived_from<T, Slider> || std::same_as<T, SpinBox>) {
294 numericSettings.emplace();
295 auto &patch = *numericSettings;
296 const auto &source = arguments.settings;
298 patch.value = source.value;
299 patch.minimum = source.minimum;
300 patch.maximum = source.maximum;
301 patch.step = source.step;
302 patch.pageSteps = source.pageSteps;
303 patch.readOnly = source.readOnly;
304 patch.preferredWidth = source.preferredWidth;
305 patch.maxPaintCells = source.maxPaintCells;
306 patch.sliderSkin = source.sliderSkin;
307 if constexpr (std::derived_from<T, Slider>) {
308 patch.sliderTrack = source.sliderTrack;
309 patch.sliderFill = source.sliderFill;
310 patch.sliderThumb = source.sliderThumb;
312 if constexpr (std::same_as<T, SpinBox>) {
313 patch.text = source.text;
314 patch.editMode = source.editMode;
315 patch.programmaticChange = source.programmaticChange;
316 patch.displayMode = source.displayMode;
317 patch.placeholder = source.placeholder;
318 patch.history = source.history;
319 patch.limits = source.limits;
320 patch.origins = source.origins;
322 patch.origin = source.origin;
323 const std::pair<std::string_view, bool> fields[]{{
"value", patch.value.has_value()},
324 {
"minimum", patch.minimum.has_value()},
325 {
"maximum", patch.maximum.has_value()},
326 {
"step", patch.step.has_value()},
327 {
"pageSteps", patch.pageSteps.has_value()},
328 {
"readOnly", patch.readOnly.has_value()},
329 {
"preferredWidth", patch.preferredWidth.has_value()},
330 {
"maxPaintCells", patch.maxPaintCells.has_value()},
331 {
"skin", patch.sliderSkin.has_value()},
332 {
"glyphs.track", patch.sliderTrack.has_value()},
333 {
"glyphs.fill", patch.sliderFill.has_value()},
334 {
"glyphs.thumb", patch.sliderThumb.has_value()}};
336 for (
const auto &[path, present] : fields) {
338 ControlPropertyOrigin origin;
342 origin.source = found == source.origins.end() ? source.origin : found->source;
344 if (existing == patch.origins.end()) {
345 patch.origins.push_back(std::move(origin));
347 existing->source = origin.source;
352 std::optional<ControlSettings> frameSettings;
354 if (detail::hasFrameSettings(arguments.settings.frame) && !std::same_as<T, PopupMenu>) {
355 if constexpr (!std::derived_from<T, SizedWidget>) {
356 return std::unexpected(detail::frameContextError(ControlContextErrorCode::UNSUPPORTED_PROPERTY,
"frame"));
358 frameSettings.emplace();
359 frameSettings->frame = arguments.settings.frame;
360 frameSettings->origin = arguments.settings.origin;
361 frameSettings->origins = arguments.settings.origins;
364 [[maybe_unused]]
const auto rowHeight = arguments.settings.rowHeight;
365 [[maybe_unused]]
const auto overscanRows = arguments.settings.overscanRows;
366 [[maybe_unused]]
const auto maxColumns = arguments.settings.maxColumns;
367 [[maybe_unused]]
const auto maxPreparedCells = arguments.settings.maxPreparedCells;
368 [[maybe_unused]]
const auto maxPreparedTextBytes = arguments.settings.maxPreparedTextBytes;
369 [[maybe_unused]]
const auto mode = arguments.settings.mode;
370 [[maybe_unused]]
const auto chartGlyphSet = arguments.settings.chartGlyphSet;
371 [[maybe_unused]]
const auto candleGap = arguments.settings.candleGap;
372 [[maybe_unused]]
const auto yRange = arguments.settings.yRange;
373 std::optional<ControlSettings> semanticSettings;
375 if (semantic != detail::ControlFactoryKind::USER) {
376 semanticSettings.emplace(arguments.settings);
379 const auto radioReadOnly = arguments.settings.readOnly;
380 const auto radioInitial = arguments.settings.radioInitial;
381 const auto radioSelectionMode = arguments.settings.radioSelectionMode;
382 auto id = arguments.id;
383 auto recipe = std::expected<Description<T>, ManagedError>(std::invoke(factory, std::move(arguments)));
386 return std::unexpected(recipe.error());
389 if constexpr (std::derived_from<T, Slider> || std::same_as<T, SpinBox>) {
393 if constexpr (std::same_as<T, Switch>) {
395 .cycle = switchCycle,
396 .readOnly = switchReadOnly,
397 .origin = switchOrigin,
398 .origins = std::move(switchOrigins)});
401 if constexpr (std::same_as<T, RadioGroup>) {
402 (void)std::move(*recipe).settings(ControlSettings{
403 .readOnly = radioReadOnly, .radioInitial = radioInitial, .radioSelectionMode = radioSelectionMode});
405 if (semanticSettings) {
409 return std::unexpected(staged.error());
420 if constexpr (detail::IsVirtualList<T>::value || detail::IsVirtualTable<T>::value) {
422 (void)std::move(*recipe).rowHeight(*rowHeight);
426 (void)std::move(*recipe).overscanRows(*overscanRows);
430 if constexpr (detail::IsVirtualTable<T>::value) {
432 (void)std::move(*recipe).maxColumns(*maxColumns);
435 if (maxPreparedCells) {
436 (void)std::move(*recipe).maxPreparedCells(*maxPreparedCells);
439 if (maxPreparedTextBytes) {
440 (void)std::move(*recipe).maxPreparedTextBytes(*maxPreparedTextBytes);
444 if constexpr (detail::IsChart<T>::value) {
446 *recipe, {.mode = mode, .chartGlyphSet = chartGlyphSet, .candleGap = candleGap, .yRange = yRange});
450 (void)std::move(*recipe).visible(*visible);
454 (void)std::move(*recipe).enabled(*enabled);
458 (void)std::move(*recipe).classes(*classes);
462 (void)std::move(*recipe).id(
id);
465 if constexpr (std::derived_from<T, SizedWidget>) {
467 if (semantic != detail::ControlFactoryKind::NOTIFICATION_BINDING) {
478 std::expected<void, SceneResourceErrorCode> insert(Entry entry);
479 std::vector<Entry> entries_ = std::vector<Entry>(0);