5#include <__stddef_offsetof.h>
6#include "cyd_fabric_modules/headers/macros/async_events.h"
8#define STYLE_SETTER_RETURN_TYPE void
9#define STYLE_SETTER_RETURN_EXPR
18import fabric.templates.functor_arguments;
26export import :event_dispatcher;
27export import :attributes;
28export import :contexts;
34 using sptr = std::shared_ptr<component_base_t>;
35 using wptr = std::weak_ptr<component_base_t>;
58 virtual std::string
name()
const = 0;
61 virtual std::shared_ptr<component_state_t> create_state_instance() = 0;
68 virtual bool update_with(std::shared_ptr<component_base_t> other) = 0;
70 virtual void mount() = 0;
71 virtual void dismount() = 0;
75 if (state_.has_value()) {
76 return state_.value().lock();
84 using type = std::remove_const_t<std::remove_reference_t<T>>;
85 static auto tid = refl::type_id<type>;
87 if (not data_map_.contains(tid)) {
88 data_map_[tid] = refl::any::make<type>();
91 return data_map_.at(tid).template as<type>();
96 using type = std::remove_const_t<std::remove_reference_t<T>>;
97 static auto tid = refl::type_id<type>;
99 if (data_map_.contains(tid)) {
100 data_map_.erase(tid);
106 template<
typename ContextType>
108 context_store_.add_context<ContextType>(ptr);
111 template<
typename ContextType>
113 if (not context_store_.empty()) {
114 auto context = context_store_.find_context<ContextType>();
115 if (context.has_value()) {
121 return parent.value()->find_context<ContextType>();
160 void tag(
const std::string& tag_) {
164 void untag(
const std::string& tag_) {
173 for (
const auto & child :
children) {
174 if (child->get_id() ==
id) {
177 auto descendant = child->find_child(
id);
178 if (descendant.has_value()) {
186 std::list<sptr> result{};
187 for (
const auto & child :
children) {
188 if (child->get_id() ==
id) {
189 result.push_back(child);
191 auto descendants = child->find_children(
id);
192 for (
const auto & d : descendants) {
207 friend class ::with_context;
209 template<
typename ContextType>
212 template<
typename ContextType>
213 void add_context(
const std::shared_ptr<ContextType> &ptr) {
214 context_store_.add_context<ContextType>(ptr);
217 auto& get_context_store() {
218 return context_store_;
224 std::optional<component_base_t*>
parent = std::nullopt;
225 std::list<std::shared_ptr<component_base_t>>
children{};
234 std::optional<std::weak_ptr<component_state_t>> state_ = std::nullopt;
236 std::unordered_map<refl::type_id_t, refl::any> data_map_ { };
246 return component->create_state_instance();
250 return component->update_with(other);
257 component->dismount();
262template<
typename ContextType>
266 for (
auto &c: holder.get_components()) {
267 if (not c->get_context_store().find_context<ContextType>().has_value()) {
268 c->add_context(context_);
void set_id(const std::string &id)
std::shared_ptr< style_data_base_t > style_data
component_base_t(identifier_t identifier={})
void set_state(const component_state_ref &state)
std::list< std::shared_ptr< component_base_t > > children
component_state_ref state() const
std::string get_id() const
std::optional< sptr > find_child(const std::string &id)
std::weak_ptr< component_base_t > wptr
virtual component_dimensional_relations_t get_dimensional_relations()=0
virtual void * get_props()=0
internal_relations_t & get_internal_relations()
void y(const dimension_t &value)
virtual component_base_t * find_by_coords(dimension_t::value_type x, dimension_t::value_type y)=0
style_base_t & get_style()
void add_context(provide_context< ContextType > &ptr)
friend struct cydui::provide_context
internal_relations_t internal_relations
virtual attrs_component * attrs()=0
std::optional< std::shared_ptr< event_dispatcher_base_t > > event_dispatcher
void untag(const std::string &tag_)
std::list< sptr > find_children(const std::string &id)
virtual std::shared_ptr< dimension_ctx_t > get_dimensional_context()=0
bool has_tag(const std::string &tag_) const
void tag(const std::string &tag_)
virtual const refl::type_info & get_style_type_info() const =0
std::optional< component_base_t * > parent
void x(const dimension_t &value)
style_data_base_t & get_style_data()
std::shared_ptr< component_base_t > sptr
virtual ~component_base_t()=default
virtual std::string name() const =0
event_dispatcher_base_t * get_event_dispatcher()
friend struct component_actor_t
std::optional< ContextType * > find_context()
dimensions::screen_measure value_type
std::shared_ptr< component_state_t > component_state_ref
static void dismount_component(component_base_t *component)
static void set_component_state(component_base_t *component, component_state_ref state)
static void mount_component(component_base_t *component)
static bool update_component_with(component_base_t *component, std::shared_ptr< component_base_t > other)
static std::shared_ptr< component_state_t > create_state_instance(component_base_t *component)
components::component_holder_t operator>(with_context &&components)