Skip to content

Commit

Permalink
add size to fit for buttons. Closes cappuccino#34.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Boucher committed May 6, 2009
1 parent 81d23aa commit ae8fd0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions AppKit/CPButton.j
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ var _CPButtonClassName = nil,

+ (id)themedAttributes
{
return [CPDictionary dictionaryWithObjects:[_CGInsetMakeZero(), _CGInsetMakeZero(), nil]
forKeys:[@"bezel-inset", @"content-inset", @"bezel-color"]];
return [CPDictionary dictionaryWithObjects:[_CGInsetMakeZero(), _CGInsetMakeZero(), nil, 24.0]
forKeys:[@"bezel-inset", @"content-inset", @"bezel-color", @"default-height"]];
}

- (id)initWithFrame:(CGRect)aFrame
Expand Down Expand Up @@ -374,6 +374,18 @@ var _CPButtonClassName = nil,
return bounds;
}

/*!
Adjust the size of the button to fit the title and surrounding button image.
*/
- (void)sizeToFit
{
var size = [([self title] || " ") sizeWithFont:[self font]],
contentInset = [self currentValueForThemedAttributeName:@"content-inset"],
defaultHeight = [self currentValueForThemedAttributeName:@"default-height"];

[self setFrameSize:CGSizeMake(size.width + contentInset.left + contentInset.right, defaultHeight)];
}

- (CGRect)rectForEphemeralSubviewNamed:(CPString)aName
{
if (aName === "bezel-view")
Expand Down
6 changes: 6 additions & 0 deletions AppKit/CoreGraphics/CGGeometry.j
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,9 @@ function CGPointFromEvent(anEvent)
{
return _CGPointMake(anEvent.clientX, anEvent.clientY);
}

function CPStringFromInset(anInset)
{
return anInset.top+" "+anInset.left+" "+anInset.bottom+" "+anInset.right;
}

0 comments on commit ae8fd0c

Please sign in to comment.