23template<
typename T,
size_t S = 8>
49 const int32_t index = mObservers.findIndex([view](
const Observer& item)
51 return view == item.view;
58 obs.callback = callback;
60 mObservers.append(obs);
80 const int32_t index = mObservers.find([view](
const Observer &item)
82 return view == item.view;
86 mObservers.removeAtPos(index);
88 if (mObservers.size() == 0)
132 if (&
value != &mValue)
156 lambda<bool(T&)> callback;
165 void onViewStateChange(
DsView* view,
bool isVisible)
override final
167 if (mIsValid && isVisible)
172 Observer &obs = mObservers.
current();
174 if (obs.view == view)
180 if (obs.callback(
value))
193 Observer &obs = mObservers.
current();
194 if (obs.view->isVisible())
200 if (obs.callback(
value))
LiveData is an observable data holder class.
Definition ds_live_data.h:25
void post(void)
Posts the same value again.
Definition ds_live_data.h:106
void post(const T &value)
Posts a new value.
Definition ds_live_data.h:130
void invalidate(void)
Marks the contained data as invalid. The observer callbacks will not be called for updates until the ...
Definition ds_live_data.h:97
void observe(DsView *view, const lambda< bool(T &)> &callback)
Registers a new observer.
Definition ds_live_data.h:45
T & value(void)
Returns a reference to the contained value.
Definition ds_live_data.h:147
void remove(DsView *view)
Removes the registered observer.
Definition ds_live_data.h:76
DsLiveData()
Default constructor.
Definition ds_live_data.h:30
DsScreen is class of type DsView (inherits from DsView) that implements a physical screen.
Definition ds_screen.h:29
bool isUiThread(void) const
Returns true if the caller is running in the UI thread.
void queueLambda(const lambda< void(void), 64 > &lambda)
Queues a lambda to get executed in the UI thread event loop.
StateObserver is a pure virtual class implementing the interface for notifying state observers of cha...
Definition ds_view.h:47
DsView is a base class that represents any view on the screen.
Definition ds_view.h:40
DsScreen & getScreen(void)
Returns a reference to the screen to which this view belongs.
void removeStateObserver(StateObserver *observer)
Removes a state observer object.
void addStateObserver(StateObserver *observer)
Adds a state observer object.
Definition ds_types_lambda.h:24
void startFirst(void)
Initializes the internal element pointer to the first one in the list.
Definition ds_types_list.h:444
bool valid(void) const
Is the internal element pointer valid?
Definition ds_types_list.h:479
T & current(void)
Returns the element pointed by the internal pointer. If the internal pointer is not valid it will lik...
Definition ds_types_list.h:490
void goNext(void)
Advances the internal element pointer to the next one (going forward).
Definition ds_types_list.h:460
static_list is a specialization of the list class. It pre-allocates all elements in the list....
Definition ds_types_list.h:524