22 using sptr = std::shared_ptr<component_updater_t>;
25 return std::make_shared<component_updater_t>();
28 fabric::wiring::output_signal<component_updater_t, const component_base_t::sptr&>
queue_render_signal{};
29 fabric::wiring::output_signal<component_updater_t, const component_base_t::sptr&>
apply_style_signal{};
33 ZoneScopedN(
"Update");
34 component->state()->_dirty =
false;
40 std::shared_ptr<component_base_t>,
41 std::list<std::shared_ptr<component_base_t>>::iterator>
43 std::list<std::shared_ptr<component_base_t>> pending_redraw { };
44 for (
auto it = component->children.begin(); it != component->children.end(); ++it) {
45 pending_remove.emplace(*it, it);
49 std::vector<component_builder_t> &content_children = component->attrs()->_content;
50 for (
auto &item: content_children) {
51 for (
auto &component: item.get_component_constructors()) {
52 content_children_builder.append_component(component);
58 std::vector<component_holder_t> new_children = component->get_event_dispatcher()->update(style_archive, content_children_builder);
61 component->get_style_data().apply_override();
63 add_children(component, new_children, pending_redraw, pending_remove, style_archive);
65 for (
const auto &remove: pending_remove) {
66 dismount_child(component, remove.second);
69 for (
const auto &child: pending_redraw) {
71 update(child, style_archive);
78 std::vector<component_holder_t> &children_to_add,
79 std::list<std::shared_ptr<component_base_t>> &pending_redraw,
81 std::shared_ptr<component_base_t>,
82 std::list<std::shared_ptr<component_base_t> >::iterator> &pending_remove,
85 ZoneScopedN(
"Add Children");
86 std::optional<std::shared_ptr<component_base_t>> prev {std::nullopt};
90 std::unordered_map<std::string, std::size_t> used_ids{};
92 for (
auto &item: children_to_add) {
93 for (
const auto &child: item.get_components()) {
94 std::string name = child->name();
95 std::string _id = child->get_id();
96 std::string
id = std::format(
"{}:{}", name, _id);
98 if (used_ids.contains(
id)) {
99 id = std::format(
"{}[{}]",
id, used_ids[
id]++);
102 id = std::format(
"{}[0]",
id);
105 auto mounted_child = mount_child(component,
id, child, pending_redraw, pending_remove, style_archive);
110 prev.emplace(mounted_child);
115 std::shared_ptr<component_base_t> mount_child(
117 const std::string &
id,
118 std::shared_ptr<component_base_t> child,
119 std::list<std::shared_ptr<component_base_t>> &pending_redraw,
121 std::shared_ptr<component_base_t>,
122 std::list<std::shared_ptr<component_base_t>>::iterator> &pending_remove,
123 StyleArchive &style_archive
125 ZoneScopedN(
"Mount Children");
126 std::shared_ptr<component_base_t> mounted_child {child};
129 if (component->state()->children_states.contains(
id)) {
130 child_state = component->state()->children_states[id];
133 component->state()->add_children_state(
id, child_state);
136 if (child_state->component_instance.has_value()) {
137 pending_remove.erase(child_state->component_instance.value());
138 mounted_child = child_state->component_instance.value();
142 pending_redraw.push_back(child_state->component_instance.value());
146 child->parent = component.get();
147 auto c_dims = child->get_dimensional_relations();
148 child->get_internal_relations().cx = component->get_internal_relations().cx + c_dims.x
149 + c_dims.margin_left + c_dims.padding_left;
150 child->get_internal_relations().cy = component->get_internal_relations().cy + c_dims.y
151 + c_dims.margin_top + c_dims.padding_top;
156 child_state->component_instance = child;
157 component->children.push_back(child);
166 pending_redraw.push_back(child);
169 return mounted_child;
172 void dismount_child(
const component_base_t::sptr& component,
const std::list<std::shared_ptr<component_base_t>>::iterator &child) {
173 ZoneScopedN(
"Unmount Children");
175 component->children.erase(child);