[Drawkit] Minor fix for text selection in DrawDemo
Brad Larson
larson at sonoplot.com
Wed Oct 29 10:03:35 PDT 2008
I had lifted some code from the DrawDemo application to add an
inspector to our drawing program when I noticed that one of the text
cells wasn't properly responding to mouse selection of the text. In
the drawing layer inspector, the custom
RSVerticallyCenteredTextFieldCell is used to provide vertically
aligned text within the layer table. However, the hit testing in that
custom cell is still using the traditional top-aligned text location,
which causes some frustration when you're trying to edit the cell.
To fix this, you can add the following to
RSVerticallyCenteredTextFieldCell's implementation:
- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:
(NSRect)cellFrame ofView:(NSView *)controlView
{
NSRect newRect = [super drawingRectForBounds:cellFrame];
// Get our ideal size for current text
NSSize textSize = [self cellSizeForBounds:cellFrame];
// Center that in the proposed rect
float heightDelta = newRect.size.height - textSize.height;
if (heightDelta > 0)
{
newRect.size.height -= heightDelta;
newRect.origin.y += (heightDelta / 2);
}
return [super hitTestForEvent:event inRect:newRect ofView:controlView];
}
This is not strictly DrawKit-related, but it does affect the DrawDemo
sample application.
______________________
Brad Larson
SonoPlot, Inc.
3030 Laura Lane, Suite 120
Middleton, WI 53562
More information about the Drawkit
mailing list