MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ read_element()

template<typename Source, typename Access>
bool MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::read_element ( const Source & element,
InstanceInfo & info )
inlineprivate

An element declares what C++ declares for one placed form: its name, the initial state, the Layer calls that follow placement (visible, interactive, relate, front, back, clip, spelled as the Layer and Element members are), one form that calls a registered function, and the actions on its events.

Definition at line 565 of file Instantiate.hpp.

566 {
567 const auto name = claim_name(element);
568 if (!name)
569 return false;
570 info.id = *name;
571
572 bool visible = true;
576 return true;
577 if (attribute == "visible")
579 if (attribute == "front")
580 return read_flag(element, attribute, value, info.layer.front);
581 if (attribute == "back")
582 return read_flag(element, attribute, value, info.layer.back);
583 if (attribute == "interactive") {
584 bool flag {};
586 return false;
587 info.layer.interactive = flag;
588 return true;
589 }
590 if (attribute == "relate") {
591 if (value.empty())
592 return fail(element, "<element> needs an element name in relate");
593 info.layer.relate = std::string(value);
594 return true;
595 }
596 if (attribute == "clip") {
600 return fail(element, "<element> needs four numbers in clip");
601 if (!(region.max.x > region.min.x) || !(region.max.y > region.min.y))
602 return fail(element, "clip needs a positive width and height");
603 info.layer.clip = region;
604 return true;
605 }
606 return fail(element, "<element> has an unsupported attribute " + std::string(attribute));
607 });
608 if (!read)
609 return false;
610 info.layer.hidden = !visible;
611 if (info.layer.front && info.layer.back)
612 return fail(element, "front and back cannot both be set");
613
614 const bool traversed = Access::for_each_child(element, [&](const Source& child) {
615 const auto kind = Access::name(child);
616 if (kind == "form") {
617 if (info.form)
618 return fail(child, "<element> may hold only one <form>");
619 info.form = child;
620 return check_form(child);
621 }
623 return read_action(child, info);
624 if (is_hit_child(kind))
626 return fail(child, "<" + std::string(kind) + "> is not allowed in <element>");
627 });
628 if (!traversed)
629 return false;
630 if (!info.form)
631 return fail(element, "<element> needs a <form>");
632 return true;
633 }
bool read_flag(const Source &instance, std::string_view name, std::string_view value, bool &out)
bool fail(const Source &at, std::string message)
std::optional< std::string > claim_name(const Source &source)
bool read_action(const Source &on, InstanceInfo &info)
bool check_form(const Source &form)
A form either calls a registered function or gives vertices to draw, as C++ either passes a function'...
bool read_hit_child(const Source &child, ElementHit &hit, std::string &error)
Read one spatial child of an element into hit.
bool is_hit_child(std::string_view name)
Whether an element of this name sets spatial fields: bounds, or a region.

References MayaFlux::Portal::Forma::Detail::LayerAttributes::back, check_form(), claim_name(), MayaFlux::Portal::Forma::Detail::LayerAttributes::clip, MayaFlux::Portal::Forma::element_name_attribute, fail(), MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::InstanceInfo::form, MayaFlux::Portal::Forma::Detail::LayerAttributes::front, MayaFlux::Portal::Forma::Detail::LayerAttributes::hidden, MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::InstanceInfo::hit, MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::InstanceInfo::id, MayaFlux::Portal::Forma::Detail::LayerAttributes::interactive, MayaFlux::Reflect::Invalid, MayaFlux::Portal::Forma::is_hit_child(), MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::InstanceInfo::layer, m_error, MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, read_action(), read_flag(), MayaFlux::Portal::Forma::read_hit_child(), MayaFlux::Portal::Forma::Detail::LayerAttributes::relate, MayaFlux::Portal::Forma::reserved_action_element, and MayaFlux::Portal::Forma::reserved_state_attribute.

Referenced by check_instances().

Here is the call graph for this function:
Here is the caller graph for this function: