mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Cleaned up button's sizeToFit.
Reviewed by me.
This commit is contained in:
+41
-37
@@ -122,25 +122,22 @@ CPButtonStateMixed = CPThemeState("mixed");
|
||||
CPControlSize _controlSize;
|
||||
}
|
||||
|
||||
+ (id)standardButtonWithTitle:(CPString)aTitle
|
||||
+ (id)buttonWithTitle:(CPString)aTitle
|
||||
{
|
||||
var button = [[CPButton alloc] init];
|
||||
return [self buttonWithTitle:aTitle theme:[CPTheme defaultTheme]];
|
||||
}
|
||||
|
||||
+ (id)buttonWithTitle:(CPString)aTitle theme:(CPTheme)aTheme
|
||||
{
|
||||
var button = [[self alloc] init];
|
||||
|
||||
[button setTheme:aTheme];
|
||||
[button setTitle:aTitle];
|
||||
[button sizeToFit];
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
+ (id)standardCheckBoxWithTitle:(CPString)aTitle
|
||||
{
|
||||
return [CPCheckBox standardButtonWithTitle:aTitle];
|
||||
}
|
||||
|
||||
- (id)standardRadioWithTitle:(CPString)aTitle
|
||||
{
|
||||
return [CPRadio standardButtonWithTitle:aTitle];
|
||||
}
|
||||
|
||||
+ (CPString)themeClass
|
||||
{
|
||||
return @"button";
|
||||
@@ -148,8 +145,8 @@ CPButtonStateMixed = CPThemeState("mixed");
|
||||
|
||||
+ (id)themeAttributes
|
||||
{
|
||||
return [CPDictionary dictionaryWithObjects:[_CGInsetMakeZero(), _CGInsetMakeZero(), nil, 24.0]
|
||||
forKeys:[@"bezel-inset", @"content-inset", @"bezel-color", @"default-height"]];
|
||||
return [CPDictionary dictionaryWithObjects:[_CGInsetMakeZero(), _CGInsetMakeZero(), nil]
|
||||
forKeys:[@"bezel-inset", @"content-inset", @"bezel-color"]];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
@@ -472,12 +469,12 @@ CPButtonStateMixed = CPThemeState("mixed");
|
||||
|
||||
if (_CGInsetIsEmpty(bezelInset))
|
||||
return bounds;
|
||||
|
||||
|
||||
bounds.origin.x += bezelInset.left;
|
||||
bounds.origin.y += bezelInset.top;
|
||||
bounds.size.width -= bezelInset.left + bezelInset.right;
|
||||
bounds.size.height -= bezelInset.top + bezelInset.bottom;
|
||||
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
@@ -486,11 +483,21 @@ CPButtonStateMixed = CPThemeState("mixed");
|
||||
*/
|
||||
- (void)sizeToFit
|
||||
{
|
||||
var size = [([self title] || " ") sizeWithFont:[self font]],
|
||||
var size = [([self title] || " ") sizeWithFont:[self currentValueForThemeAttribute:@"font"]],//[self font]],
|
||||
contentInset = [self currentValueForThemeAttribute:@"content-inset"],
|
||||
defaultHeight = [self currentValueForThemeAttribute:@"default-height"];
|
||||
minSize = [self currentValueForThemeAttribute:@"min-size"],
|
||||
maxSize = [self currentValueForThemeAttribute:@"max-size"];
|
||||
|
||||
[self setFrameSize:CGSizeMake(size.width + contentInset.left + contentInset.right, defaultHeight)];
|
||||
size.width = MAX(size.width + contentInset.left + contentInset.right, minSize.width);
|
||||
size.height = MAX(size.height + contentInset.top + contentInset.bottom, minSize.height);
|
||||
|
||||
if (maxSize.width >= 0.0)
|
||||
size.width = MIN(size.width, maxSize.width);
|
||||
|
||||
if (maxSize.height >= 0.0)
|
||||
size.height = MIN(size.height, maxSize.height);
|
||||
|
||||
[self setFrameSize:size];
|
||||
}
|
||||
|
||||
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aName
|
||||
@@ -558,18 +565,6 @@ CPButtonStateMixed = CPThemeState("mixed");
|
||||
[self unsetThemeState:CPThemeStateDefault];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPButton (NS)
|
||||
|
||||
- (void)setBezelStyle:(unsigned)aBezelStyle
|
||||
{
|
||||
}
|
||||
|
||||
- (unsigned)bezelStyle
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setBordered:(BOOL)shouldBeBordered
|
||||
{
|
||||
if (shouldBeBordered)
|
||||
@@ -585,13 +580,24 @@ CPButtonStateMixed = CPThemeState("mixed");
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPButton (NS)
|
||||
|
||||
- (void)setBezelStyle:(unsigned)aBezelStyle
|
||||
{
|
||||
}
|
||||
|
||||
- (unsigned)bezelStyle
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
var CPButtonImageKey = @"CPButtonImageKey",
|
||||
CPButtonAlternateImageKey = @"CPButtonAlternateImageKey",
|
||||
CPButtonTitleKey = @"CPButtonTitleKey",
|
||||
CPButtonAlternateTitleKey = @"CPButtonAlternateTitleKey",
|
||||
CPButtonIsBorderedKey = @"CPButtonIsBorderedKey",
|
||||
CPButtonBezelStyleKey = @"CPButtonBezelStyleKey";
|
||||
CPButtonIsBorderedKey = @"CPButtonIsBorderedKey";
|
||||
|
||||
@implementation CPButton (CPCoding)
|
||||
|
||||
@@ -627,14 +633,12 @@ var CPButtonImageKey = @"CPButtonImageKey",
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
|
||||
|
||||
[aCoder encodeObject:_image forKey:CPButtonImageKey];
|
||||
[aCoder encodeObject:_alternateImage forKey:CPButtonAlternateImageKey];
|
||||
|
||||
|
||||
[aCoder encodeObject:_title forKey:CPButtonTitleKey];
|
||||
[aCoder encodeObject:_alternateTitle forKey:CPButtonAlternateTitleKey];
|
||||
|
||||
[aCoder encodeInt:_bezelStyle forKey:CPButtonBezelStyleKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
+6
-5
@@ -27,13 +27,14 @@
|
||||
{
|
||||
}
|
||||
|
||||
+ (CPButton)standardButtonWithTitle:(CPString)aTitle
|
||||
+ (id)checkBoxWithTitle:(CPString)aTitle theme:(CPTheme)aTheme
|
||||
{
|
||||
var button = [[CPCheckBox alloc] init];
|
||||
return [self buttonWithTitle:aTitle theme:aTheme];
|
||||
}
|
||||
|
||||
[button setTitle:aTitle];
|
||||
|
||||
return button;
|
||||
+ (id)checkBoxWithTitle:(CPString)aTitle
|
||||
{
|
||||
return [self buttonWithTitle:aTitle];
|
||||
}
|
||||
|
||||
+ (CPString)themeClass
|
||||
|
||||
+22
-3
@@ -109,9 +109,28 @@ var CPControlBlackColor = [CPColor blackColor];
|
||||
|
||||
+ (CPDictionary)themeAttributes
|
||||
{
|
||||
return [CPDictionary dictionaryWithObjects:[
|
||||
CPLeftTextAlignment, CPTopVerticalTextAlignment, CPLineBreakByClipping, [CPColor blackColor], [CPFont systemFontOfSize:12.0], nil, _CGSizeMakeZero(), CPImageLeft, CPScaleToFit]
|
||||
forKeys:[@"alignment", @"vertical-alignment", @"line-break-mode", @"text-color", @"font", @"text-shadow-color", @"text-shadow-offset", @"image-position", @"image-scaling"]];
|
||||
return [CPDictionary dictionaryWithObjects:[CPLeftTextAlignment,
|
||||
CPTopVerticalTextAlignment,
|
||||
CPLineBreakByClipping,
|
||||
[CPColor blackColor],
|
||||
[CPFont systemFontOfSize:12.0],
|
||||
nil,
|
||||
_CGSizeMakeZero(),
|
||||
CPImageLeft,
|
||||
CPScaleToFit,
|
||||
_CGSizeMakeZero(),
|
||||
_CGSizeMake(-1.0, -1.0)]
|
||||
forKeys:[@"alignment",
|
||||
@"vertical-alignment",
|
||||
@"line-break-mode",
|
||||
@"text-color",
|
||||
@"font",
|
||||
@"text-shadow-color",
|
||||
@"text-shadow-offset",
|
||||
@"image-position",
|
||||
@"image-scaling",
|
||||
@"min-size",
|
||||
@"max-size"]];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
|
||||
@@ -67,6 +67,16 @@
|
||||
CPRadioGroup _radioGroup;
|
||||
}
|
||||
|
||||
+ (id)radioWithTitle:(CPString)aTitle theme:(CPTheme)aTheme
|
||||
{
|
||||
return [self buttonWithTitle:aTitle theme:aTheme];
|
||||
}
|
||||
|
||||
+ (id)radioWithTitle:(CPString)aTitle
|
||||
{
|
||||
return [self buttonWithTitle:aTitle];
|
||||
}
|
||||
|
||||
+ (CPButton)standardButtonWithTitle:(CPString)aTitle
|
||||
{
|
||||
var button = [[CPRadio alloc] init];
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* AppController.j
|
||||
* A
|
||||
* Aristo
|
||||
*
|
||||
* Created by __Me__ on __Date__.
|
||||
* Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
* Created by Francisco Tolmasky.
|
||||
* Copyright 2009, 280 North, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
@@ -250,7 +250,8 @@
|
||||
[button setValue:defaultHighlightedBezelColor forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered|CPThemeStateHighlighted|CPThemeStateDefault];
|
||||
[button setValue:[CPColor colorWithCalibratedRed:13.0/255.0 green:51.0/255.0 blue:70.0/255.0 alpha:1.0] forThemeAttribute:@"text-color" inState:CPThemeStateDefault];
|
||||
|
||||
[button setValue:24.0 forThemeAttribute:@"default-height"];
|
||||
[button setValue:CGSizeMake(0.0, 24.0) forThemeAttribute:@"min-size"];
|
||||
[button setValue:CGSizeMake(-1.0, 24.0) forThemeAttribute:@"max-size"];
|
||||
|
||||
return button;
|
||||
}
|
||||
@@ -278,6 +279,8 @@
|
||||
[button setValue:bezelColor forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
|
||||
[button setValue:bezelColorSelected forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateSelected];
|
||||
|
||||
[button setValue:CGSizeMake(0.0, 17.0) forThemeAttribute:@"min-size"];
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -304,6 +307,8 @@
|
||||
[button setValue:bezelColor forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
|
||||
[button setValue:bezelColorSelected forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateSelected];
|
||||
|
||||
[button setValue:CGSizeMake(0.0, 16.0) forThemeAttribute:@"min-size"];
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -563,7 +568,8 @@
|
||||
[button setValue:highlightedBezelColor forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered|CPThemeStateHighlighted];
|
||||
[button setValue:CGInsetMake(2.0, 5.0, 4.0, 5.0) forThemeAttribute:@"content-inset" inState:CPThemeStateBordered];
|
||||
|
||||
[button setValue:20.0 forThemeAttribute:@"default-height"];
|
||||
[button setValue:CGSizeMake(0.0, 20.0) forThemeAttribute:@"min-size"];
|
||||
[button setValue:CGSizeMake(-1.0, 20.0) forThemeAttribute:@"max-size"];
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user