17template <
typename Self,
typename Finished>
30 for(
const auto& itr : m_callbacks) {
31 m_cb_deleter(itr.second);
36 auto itr = m_callbacks.find(event);
37 if (itr != m_callbacks.end()) {
38 (*m_cb_trampoline)(itr->second, state);
42 void add(
const std::string& event,
void *cb) {
43 auto itr = m_callbacks.find(event);
44 if(itr != m_callbacks.end()) {
48 m_callbacks[event] = cb;
56 CallbacksHolder& operator=(
const WidgetState&) =
delete;
58 std::map<std::string, void*> m_callbacks;
85 float x()
const {
return float(
_x)/10.f; }
86 float y()
const {
return float(
_y)/10.f; }
87 float w()
const {
return float(
_w)/10.f; }
88 float h()
const {
return float(
_h)/10.f; }
103 template <
typename Self,
typename Finished>
107 WidgetState(uint16_t
uuid,
float x,
float y,
float w,
float h, uint16_t tab);
109 uint16_t
uuid()
const {
return m_uuid; }
110 const rbjson::Object&
data()
const {
return m_data; }
112 bool set(
const std::string& key, rbjson::Value* value);
113 bool setInnerObjectProp(
const std::string& objectName,
const std::string& propertyName,
114 rbjson::Value* value);
119 return bool(m_cb_holder);
132 static std::mutex m_mutex;
137 rbjson::Object&
data() {
return m_data; }
139 void update(rbjson::Object* other) {
141 for (
auto itr : other->members()) {
142 const std::string name_str(itr.name, itr.name_len);
143 m_data.set(name_str, itr.value->copy());
144 markGlobalChangedLocked(name_str);
151 m_cb_holder.reset(
new CallbacksHolder(trampoline, deleter));
153 m_cb_holder->add(event, cb);
156 void call(
const std::string& event) {
159 m_cb_holder->call(
this, event);
162 void markChangedLocked(
const std::string& key);
163 void markGlobalChangedLocked(
const std::string& key);
164 inline bool wasChangedInTickLocked(
const char *key,
size_t key_len)
const;
166 bool popChanges(rbjson::Object& state);
167 bool remarkAllChanges();
169 rbjson::Object m_data;
170 std::unique_ptr<CallbacksHolder> m_cb_holder;
172 const uint16_t m_uuid;
174 uint16_t m_bloom_global;
175 uint16_t m_bloom_tick;
242 return data().getInt(
"tab");
245 void setCss(
const std::string& propertyName,
const std::string& value) {
249 std::string
css(
const std::string& propertyName)
const {
250 auto*
css =
data().getObject(
"css");
253 return css->getString(propertyName);
void call(WidgetState *state, const std::string &event)
void(* cb_trampoline_t)(void *, WidgetState *)
void add(const std::string &event, void *cb)
void(* cb_deleter_t)(void *)