8 #ifndef Guit_VarProp_hpp
9 #define Guit_VarProp_hpp
10 #include <gproplist.hpp>
55 using IsVarProp = bool;
56 using IsGadgetOrVarProp = bool;
58 using BindTag = int8_t;
65 return omodes_.immutable ?
nullptr :
this;
68 bool isMutable()
const override {
return !omodes_.immutable;}
72 virtual void set(GString
const& value) = 0;
77 virtual void set(
GProp const& value) = 0;
81 virtual void blend(
GProp const& value1,
GProp const& value2,
float mix);
85 bool read(GString
const& filename);
86 virtual void read(std::istream& in);
87 friend std::istream& operator>>(std::istream& in,
GVarProp&);
99 void unbind(GVarProp::BindTag bindtag = 0);
104 void blink(GString
const& msg =
"", GTime duration = 500);
115 virtual void addFun(GFunction
const& fun);
116 virtual void add(
GProp&);
117 virtual void add(
GCond&);
118 virtual void addBegin(
GProp&);
119 virtual void remove(
GProp&);
122 virtual void removeFromGadgets();
126 bool changing()
const {
return pmodes_.changing;}
127 void changing(
bool val) {pmodes_.changing = val;}
128 void bindImpl(GExpr& sender);
129 void bindImpl(GVarProp& sender, GFunction fun, BindTag);
130 void bindImpl(GVarProp& sender,
class GChangeNotifier&, BindTag,
bool recv_is_master);
131 void fireCallbacks(GEvent&);
132 void fireDefaultCallbacks();
133 bool hasActiveNotifiers();
134 void startNotify(Gadget&, std::function<
void(Gadget&)>
const& fun);
135 void startNotifyGadget(Gadget&);
136 void stopNotify(Gadget&);
137 bool testMasterValue();
138 void propagateChange();
139 void immutableError(
const char*);
140 class GChangeNotifier* getMaster();
142 uint8_t changing:1, removing:1, isSet:1, hasMaster:1, autoReset:1;
163 T
const&
value()
const {
return value_;}
164 T
const& operator()()
const {
return value_;}
171 GString
stringValue()
const override {
return guit::toString(value_);}
178 virtual void set(T
const& value,
bool callalways) {
179 if (omodes_.immutable) immutableError(
"set");
180 else if (doChange(value) || callalways)
185 void set(GString
const& str)
override {
186 T val{}; gconvert(str, val);
set(val,
false);
190 if (
auto* p =
dynamic_cast<GVarProp_<T> const*
>(&value)) {
191 set(p->value(),
false);
193 else if (value.isString()) {
196 else error(
"set(GProp)",
"incompatible argument");
199 bool operator==(T
const& value)
const {
return value_ ==
value;}
202 bool operator==(GVarProp_<V>
const& other)
const {
return value_ == other.value_;}
205 virtual bool isValid(T
const&)
const {
return true;}
207 virtual bool doChange(T
const& v) {
208 if (v == value_ && pmodes_.isSet)
return false;
232 explicit GNumPropRef(
GProp& prop) : prop_(prop) {}
238 template <
class P>
class GPropRef_ :
public GPropRef {
240 explicit GPropRef_(P& prop) : GPropRef(prop) {}
243 template <
class P>
class GNumPropRef_ :
public GNumPropRef {
245 explicit GNumPropRef_(P& prop) : GNumPropRef(prop) {}
256 template <
class P,
class F>
259 GPropField(P& prop, F& field) : prop_(prop), field_(field) {}
264 template <
class P,
class F>
265 class GNumPropField :
public GPropField<P,F> {
267 GNumPropField(P& prop, F& field) :
GPropField<P,F>(prop,field) {}
268 GNumPropRef operator~();