[haiku-development] Re: Glass Elevator proposal: templated BControl

  • From: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Wed, 11 Jul 2018 14:00:27 +0200

On Wed, Jul 11, 2018 at 01:50:57PM +0200, Stephan Aßmus wrote:

Hi,

I agree with both of what Adrien and waddlesplash said. The design goal of
the API should be to make it easy for developers to write correctly behaving
applications and to minimize the code necessary to wire everything together.
I think the Be API isn't perfect in this regard. So whether or not we need
BTypedControl... What common problem does it solve? Would there be a much
better way to solve it? IMHO, the Interface Kit tries to make it easy to
process UI events in other threads, but they have to be BLoopers if you want
to minimize the necessary code. What I think is missing is a notion to
separate UI from data and to bind the two together, possibly in an automated
fashion. I don't yet see how BTypedControl helps much with that.

Actually we have StartWatching/SendNotices which works quite well for
this. The UI code just calls SendNotices when something happens, and the
controller can just register for events using StartWatching. This gets
somewhat similar to Qt signal/slots pattern (except you still get to
process the messages in the MessageReceived of a BLooper).

If the default BControl would call SendNotices already, we could use
this pattern a lot more, and in the simplest case, not need a custom
message loop in BWindow at all.

For R2, we could likely augment this with a way to register a callback
directly (last time I experimented with this, I needed to use variadic
templates, but I'd think C++17 may have even better ways now). And we
could do away with writing MessageReceived manually completely.

-- 
Adrien.

Other related posts: