www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - View model separation X and D.

reply Igor <Vladamir.I google.com> writes:
Suppose I create a model in D and would like it to support a gui 
written in another language such as Qt C++ or WPF .NET.

Can anyone think of an efficient and very easy way to hook up the 
"bindings"? The gui doesn't need to be updated more than about 30 
times a second and it should run in it's own thread.

I would think a simple message queue would work that uses 
commands to tell the gui that value X has changed. The gui then 
checks the queue and updates the values visually. This should be 
quick except one needs to deal with potential multiple changes of 
the same value so the queue is not flooded with useless 
changes(changes that are not able to be displayed due to the fps 
limitation).

Does this seem relatively viable? It would need a rather minimal 
api and should be relatively fast?

The other problem of the gui updating the or changing the model 
is a bit harder but commands could also be used. Seems like most 
of the work would be done in creating the bindings to the model 
so the view can act on them. I imagine a simple syntax in the gui 
design could be used to bind view to model actions.

Any ideas on the subject?
Jan 29 2016
parent Igor <Vladamir.I google.com> writes:
On Friday, 29 January 2016 at 20:04:59 UTC, Igor wrote:
 Suppose I create a model in D and would like it to support a 
 gui written in another language such as Qt C++ or WPF .NET.

 Can anyone think of an efficient and very easy way to hook up 
 the "bindings"? The gui doesn't need to be updated more than 
 about 30 times a second and it should run in it's own thread.

 I would think a simple message queue would work that uses 
 commands to tell the gui that value X has changed. The gui then 
 checks the queue and updates the values visually. This should 
 be quick except one needs to deal with potential multiple 
 changes of the same value so the queue is not flooded with 
 useless changes(changes that are not able to be displayed due 
 to the fps limitation).

 Does this seem relatively viable? It would need a rather 
 minimal api and should be relatively fast?

 The other problem of the gui updating the or changing the model 
 is a bit harder but commands could also be used. Seems like 
 most of the work would be done in creating the bindings to the 
 model so the view can act on them. I imagine a simple syntax in 
 the gui design could be used to bind view to model actions.

 Any ideas on the subject?
If the above is a good way, then the approach I would take is I: Use attributes on properties to attach them to the message queue. All marked properties are automatically modified so they "add a message" to the queue. This should somehow be real fast(messages would be statically created). II: Use attributes on methods and objects to export them so they can be called by the view. The goal is to use attributes and allow the meta programming to do all the heavy lifting behind the scenes. Sounds good? Anyone see any performance issues with this? My main goal is to avoid the model from being bogged down in step I.
Jan 29 2016