|
|
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » GetProperty() / SetProperty() for Ctrl
GetProperty() / SetProperty() for Ctrl [message #29796] |
Wed, 17 November 2010 17:46 |
|
kohait00
Messages: 939 Registered: July 2009 Location: Germany
|
Experienced Contributor |
|
|
hi guys
in my struggle with a 'scriptable' layout for OSC interfaces i came along the need / idea to make the controls more open to manipulation in terms of their properties (not the hardwired things like callbacks).
so one could imagine a uniform interface like
void Ctrl::SetProperty(const String& name, const Value& v);
void Ctrl::GetProperty(const String& name, Value& v);
now this would enable / map things like
c.SetProperty("background", Black);
c.GetProperty("background", v);
c.SetProperty("min", 123);
c.GetProperty("max", v);
c.SetProperty("xalign", "left");
c.SetProperty("xpos", 123);
c.SetProperty("yalign", "center");
c.SetProperty("ypos", 45);
c.SetProperty("pattern", "%.g");
c.SetProperty("grid" ValueArray(Vector<int>() << 5 << 6));
//would map to GetData / SetData directly i.e.
c.SetProperty("data", 345);
c.GetProperty("data", v);
c.GetProperty("count", v);
c.SetProperty("enable", true);
c.GetProperty("enable, v);
c.SetProperty("show", false);
c.SetProperty("title", "MyTitle");
c.SetProperty("tip", "GoHelp");
//query all getable properties
c.GetProperty("rprops", v);
//query all setable properties
c.GetProperty("wprops", v);
..
and many more..
this would ease things like a custom gui creation / live edit of controls..
this is just an idea, where std Ctrl could already map to a lot of things by itself.. and derived Ctrls simply extending the 'dictionary' of properties and managing the properties..
i imagine to extend it on template base if not desired in upp, but having a uniform polymorphic interface already from Ctrl level would help a great deal in this.
i might provide an example implementation soon..
just wanted to know your opinion.
cheers
[Updated on: Wed, 17 November 2010 17:50] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: GetProperty() / SetProperty() for Ctrl [message #29968 is a reply to message #29941] |
Wed, 01 December 2010 18:00 |
|
mirek
Messages: 14039 Registered: November 2005
|
Ultimate Member |
|
|
kohait00 wrote on Wed, 01 December 2010 04:04 | i think macros wont do in my case..since i need it at runtime. macros would fix everything at compile time..
or did i get you wrong? some example?
|
Oh, no, I mean macros to automate what you are already doing, just with less code.
I believe that something like
CTRL_PROPERTIES(EditInt)
PROPERTY(int, Min)
PROPERTY_SET(bool, "NotNull", NotNull)
PROPERTY_GET(bool, "NotNull", IsNotNull)
END_CTRL_PROPERTIES
should be possible.
Mirek
|
|
|
|
|
|
|
Re: GetProperty() / SetProperty() for Ctrl [message #29989 is a reply to message #29984] |
Thu, 02 December 2010 11:18 |
|
kohait00
Messages: 939 Registered: July 2009 Location: Germany
|
Experienced Contributor |
|
|
what would be the benefit in terms of organisation of the callback structures? you mean to automate the checking for even unregistered types? that would probably be an advantage, but then, i'd have to check for a whole bunch of types (performance) for each property. i couldnt use mapping anymore..
a help would be so kind of a
virtual String Ctrl::PropertyHook() const { return "Upp::Ctrl"; }
which i could use for querying maps..
then, derived controls, that dont extend property stuff would still be mapped easily (because their base specifies the hook correctly)..but this means extending the Ctrl API. but only this one single method..what do you think about it?
a EditInt i.e would, then, need to
virtual String EditInt::PropertyHook() const { return "Upp::EditInt"; }
to anounce, that it wants own property entrance in the map
also, String(typeid(CLASSNAME).name()) could be used..
then, a #define would do it to anounc
#define HASPROPERTY \
virtual String PropertyHook() const { return String(typeid(CLASSNAME).name()); }
[Updated on: Thu, 02 December 2010 11:24] Report message to a moderator
|
|
|
Re: GetProperty() / SetProperty() for Ctrl [message #29990 is a reply to message #29989] |
Thu, 02 December 2010 11:22 |
|
mirek
Messages: 14039 Registered: November 2005
|
Ultimate Member |
|
|
kohait00 wrote on Thu, 02 December 2010 05:18 | what would be the benefit in terms of organisation of the callback structures? you mean to automate the checking for even unregistered types? that would probably be an advantage, but then, i'd have to check for a whole bunch of types (performance) for each property. i couldnt use mapping anymore..
a help would be so kind of a
virtual String Ctrl::PropertyHook() const { return "Upp::Ctrl"; }
which i could use for querying maps..
then, derived controls, that dont extend property stuff would still be mapped easily..but this means extending the Ctrl API..what do you thing about it?
a EditInt i.e would, then, need to
virtual String EditInt::PropertyHook() const { return "Upp::EditInt"; }
to anounce, that it wants own property entrance in the map
also, String(typeid(CLASSNAME).name()) could be used..
then, a #define would do it to anounc
#define HASPROPERTY \
virtual String PropertyHook() const { return String(typeid(CLASSNAME).name()); }
|
Overengineering.
Mirek
|
|
|
|
Re: GetProperty() / SetProperty() for Ctrl [message #29994 is a reply to message #29991] |
Thu, 02 December 2010 13:33 |
|
mirek
Messages: 14039 Registered: November 2005
|
Ultimate Member |
|
|
kohait00 wrote on Thu, 02 December 2010 05:24 | sure, it's not easy to think simple
so what do you mean with dynamic_cast? how to use that here?
|
CTRL_PROPERTIES(EditInt)
PROPERTY(int, Min)
PROPERTY_SET(bool, "NotNull", NotNull)
PROPERTY_GET(bool, "NotNull", IsNotNull)
END_CTRL_PROPERTIES
static void GetSet_uniquebyline(Ctrl& c, Value& v, const String& prop, bool set)
{
EditInt *c = dynamic_cast<EditInt>(&x);
if(!c) return;
if(prop == "Min" && set)
c->Min(v);
if(prop == "Min" && !set)
v = c->GetMin();
....
}
INITBLOCK { RegisterCtrlGetSet(GetSet_uniquebyline); }
(Will take some effort to really squeeze to macros, but should be possible to do so).
|
|
|
Goto Forum:
Current Time: Fri Sep 20 23:40:56 CEST 2024
Total time taken to generate the page: 0.04155 seconds
|
|
|