[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sc-devel] relative coordinates in SCCompositeView ?

I have almost got FlowView working with relative-origin composite views, but there is still a bug in SCCompositeView that I can't work around.

w = SCWindow.new("test", Rect(50, 50, 500, 500)).front;
f = SCCompositeView(w, Rect(50, 50, 150, 200)).background_(Color.red(alpha: 0.3))
g = SCCompositeView(w, Rect(10, 10, 100, 100)).background_(Color.blue(alpha: 0.3))
SCStaticText(g, Rect(10, 10, 50, 20)).background_(Color.white).string_("hello");

"g" should draw relative to its parent's origin (f = (50, 50)) but instead it draws as if it had absolute coordinates. (svnx tells me I'm using the latest sources, no diffs in source directories.)

I'm afraid I'm not following the cocoa code quite well, so I don't understand how cocoa determines the physical drawing coordinates from the relative widgets. As far as I can see, the only way to do it reliably is to iterate over the parents until you get to a container view that is not set for relative origin (or the window's top view, which by definition is pinned to (0, 0)). It looks like, in this example, "g" does not take "f"'s origin into account.

I haven't committed it yet, but I'm planning to adding in my library a method to get the physical bounds of any view -- would this be valuable to have in the main library?

absoluteBounds {
var bounds = this.bounds;
this.getParents.do({ |parent|
(parent.tryPerform(\relativeOrigin) == true).if({
bounds = bounds.moveBy(parent.bounds.left, parent.bounds.top)
}, {

Sorry to dump more work on you Jan -- but we're very nearly there I think.


: H. James Harkins

: jamshark70@xxxxxxxxxxxxxxxxx

: http://www.dewdrop-world.net


"Come said the Muse,

Sing me a song no poet has yet chanted,

Sing me the universal."  -- Whitman