Why is rectangle not a subclass of canvas?

This is just a question of curiosity, but the reason I ask is because I’m using a third party color picker class with a canvas super which has a property c = color and I’d like to have that property show in the Inspector.

I right-clicked and added that and so now I can set and see the color at design time and I don’t have to add the color in the instance’s open event. Nice.

But on the layout, of course the control, being a canvas, only shows the thin outline of the canvas and not the “fillcolor” (as expected).

But that got me wondering just why a rectangle is not a subclass of canvas, but rather of rectangle control. Especially since canvas also inherits from rectangle control and it certainly seems like rectangle is for painting.

So, a theoretical, not practical question.

Though in practical terms, I’m considering rewriting the colorpicker as a subclass of rectangle unless there is a difference which might lead me to leave things as they are.

Probably ( and I know someone will shoot me down if not) because a canvas detects mousedown etc and so can be moved about at design time.
When at run time, it can be implemented using drawrect and simply drawn on demand. It doesnt have any events

probably for the same reason a VW Bug isn’t in the same class as a Ferrari…
A canvas has alot more events, methods, properties that a mere “rectangle” does
so it makes more sense to subclass them from the same parent.

A Canvas and Rectangle are both subclass of RectControl, the Canvas is more “powerful” than Rectangle
in the same way that a VW Bug and Ferrari are both subclass of Automobile, the Ferrari is more “powerful” than the Bug

No. Not “Rectangle Control”. RectControl, which is the base class for all UI controls.

As for why you only see the outline of the rectangle, it is because you used DrawRect, instead of FillRect.

As pointed out they are both subclasses of RectControl - not “rectangle control”
Think of “RectControl” as a control, since it is a subclass of control, that will occupy some rectangular area on a layout (its a visible control that has UI) Hence RectControls and their subclasses have properties like top, left, width and height where other “controls” like timers etc added to a layout do not.
And RectControls also have events for UI related actions (mouse events etc)

Class hierarchy design comprises entire University courses and quite likely could be done for a PhD thesis.
There are lots of different viewpoints about “best” way to design them
You’ll find lots of books & references on this in Amazon etc
Should a subclass be a narrowing one (it restricts what the super does down more) or widening (adds features and functionality to a super class that doesn’t do much)
I’m sure that some where way back in history there was a discussion about what the class hierarchy should be and that this set up made sense and so it has persisted for a very long time
And, there’s no really compelling reason to alter it especially since doing so could affect peoples projects silently (which we REALLY try to avoid doing)

That may / may not matter much for this control since both can detect mouse events (down move etc)

[quote=337415:@Michel Bujardet]No. Not “Rectangle Control”. RectControl, which is the base class for all UI controls.

As for why you only see the outline of the rectangle, it is because you used DrawRect, instead of FillRect.[/quote]

Yes, my mistake in writing Rectangle control. They are both subclasses of RectControl, which is what I meant (though not what I said :P). So, it’s the same question, really.

As for the outline, no I mean in the IDE while designing. Like here where you can see boxes that are canvases (the color pickers) and a rectangle I added for comaprison.

The color pickers have a property “c” which is a colour, and I can change and see that in the inspector, but of course I cannot set that property as the “background” on the layout (I know it’s not really a background.)

@Norman Palardy Thanks, that was interesting. I can see why you would not change it now, of course. Now I just need to decide if I want the eye candy of seeing the color of the picker on the layout, instead of just in the Inspector panel.

[quote=337400:@Dave Kondris]But that got me wondering just why a rectangle is not a subclass of canvas, but rather of rectangle control rectcontrol. Especially since canvas also inherits from rectangle control rectcontrol and it certainly seems like rectangle is for painting.

So, a theoretical, not practical question.

Though in practical terms, I’m considering rewriting the colorpicker as a subclass of rectangle unless there is a difference which might lead me to leave things as they are.[/quote]

EDITED: sorry for the sloppiness in the original. I meant that they are both subclassed from the same class and the rectangle only does things which the canvas can do already.