On Dec 18, 2008, at 6:20 PM, Sciss wrote:
not sure this has been made clear, but in the current svn version,
stringBounds _is_ asynchronous and must be called on a routine. i
don't see any other way of accomplishing the functionality
otherwise...
If it's asynchronous, then at least all of the following break.
There might be some other cases that I missed.
The crucial stuff is especially painful. It means you will not be
able to put any GUI that uses something that uses String:bounds
into any view that has a flow layout decorator, because the
decorator needs to know the bounds synchronously to update properly.
It won't be possible to wrap the uses within crucial library inside
routines, because the user might be putting other views in the same
container. The user's code will continue before crucial's code gets
the bounds back from the swing server. Then the FlowLayout is all
screwed up. That pushes the responsibility for routine-izing gui
code onto users who have the intention of writing crucialized,
cross-platform code ("crucialized" including such basic extensions
as ActionButton, for instance).
I'm not sure if it's possible, but if it is, the best solution
would be to have compiler switches in _String_GetBounds so that it
can be done transparently. The current hack in String:bounds (which
replaces the call to the swing server with an estimate by
multiplication) is an inaccurate hack; asking the server for exact
bounds but requiring every user to be aware of this is (IMO) an
ugly hack. But they're both hacks.
Sorry for being blunt -- I know this is a difficult problem, and I
don't know anything about how to solve it in Linux or Windows. So
maybe I should keep my mouth shut :-)
hjh
StringPlusGUI
drawLeftJustIn { arg rect, font, color;
var pos, bounds;
bounds = this.bounds( font );
pos = bounds.centerIn(rect);
pos.x = rect.left + 2;
this.drawAtPoint(pos, font, color);
}
drawRightJustIn { arg rect, font, color;
var pos, bounds;
bounds = this.bounds( font );
pos = bounds.centerIn(rect);
pos.x = rect.right - 2 - bounds.width;
this.drawAtPoint(pos, font, color);
}
ActionButton
init { arg
layout,title,function,minWidth=20,minHeight,color,backcolor,font;
var environment,optimalWidth;
title = title.asString;
if(title.size > 40,{ title = title.copyRange(0,40) });
if(font.isNil,{ font = GUI.font.new(*GUI.skin.fontSpecs) });
optimalWidth = title.bounds(font).width;
PatchGui
argNameWidth = model.instr.argNames.maxValue({ |an|
an.asString.bounds(font).width + 7 });
: 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