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

  • From: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 12 Jul 2018 16:57:58 +0200

Hi,

On Tue, Jul 10, 2018 at 11:57 PM John Scipione <jscipione@xxxxxxxxx> wrote:


Currently the value of fa BControl is always of type int32. This falls
down when the value of a BControl does not neatly fit into an int32.
For most controls like in the IK like buttons, checkboxes this is not
a problem, however, one example from IK that suffers is BColorControl
which tries to take an rgb_color value. In this case the API gets
around the int32 type limitation by packing an rgb_color stuffed into
an int32 into BColorControl::SetValue() method and implementing
ValueAColor(). Another place where I ran into this deficiency was in
BDecimalSpinner where I overloaded SetValue() to take a double. The
overloaded SetValue() method requires the caller to do casting or
specify their types carefully on the implementation side in order to
avoid ambiguous type warnings/errors.

My proposed class would look something like this:

template<typename T>
class BTypedControl: public BView, public BInvoker {
public:
   ...
    virtual void SetValue(T value);
    T Value() const;
   ...
};

A BControl would be the equivalent of a BTypedControl<int32> at least
conceptually.


I agree completely with john, that we need to look for ways to create more
type agnostic code.

However, in this case, I think the right solution would be to introduce a
BValue class in the support kit rather than using templates. There are a
lot of situations like that, and there's a large use case for it in the
media_kit too.

-- 
Saluti,
Dario

Other related posts: