Skip to content

Commit

Permalink
* Render badges using the new style system
Browse files Browse the repository at this point in the history
* Use the style box model to calculate the size of styled views
* Re-organized the xcode project a bit
  • Loading branch information
joehewitt committed Apr 10, 2009
1 parent 2df5f69 commit 779169b
Show file tree
Hide file tree
Showing 24 changed files with 403 additions and 137 deletions.
5 changes: 3 additions & 2 deletions samples/TTCatalog/Classes/ActivityTestController.m
Expand Up @@ -8,8 +8,9 @@ - (void)loadView {
self.view = [[[UIView alloc] init] autorelease];
self.view.backgroundColor = [UIColor blackColor];

TTShinyLabel* label = [[[TTShinyLabel alloc] initWithFrame:CGRectMake(0,150,320,100)] autorelease];
label.text = @"One Shiny Label";
TTSearchlightLabel* label = [[[TTSearchlightLabel alloc] initWithFrame:CGRectMake(0,150,320,100)]
autorelease];
label.text = @"Searchlight Label";
label.font = [UIFont systemFontOfSize:25];
label.textAlignment = UITextAlignmentCenter;
label.contentMode = UIViewContentModeCenter;
Expand Down
14 changes: 8 additions & 6 deletions samples/TTCatalog/Classes/RootViewController.m
Expand Up @@ -54,10 +54,12 @@ - (void)viewDidLoad {
[nav addView:@"youTubeTest" controller:[YouTubeTestController class]];
[nav addView:@"imageTest2" controller:[TableImageTestController class]];
[nav addView:@"scrollViewTest" controller:[ScrollViewTestController class]];

// [self validateView];
// NSIndexPath* indexPath = [NSIndexPath indexPathForRow:1 inSection:3];
// [self.tableView touchRowAtIndexPath:indexPath animated:NO];

#ifdef JOE
[self validateView];
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:1 inSection:3];
[self.tableView touchRowAtIndexPath:indexPath animated:NO];
#endif
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -72,7 +74,7 @@ - (void)viewDidLoad {
url:@"tt://photoTest2"] autorelease],

@"Text Fields",
[[[TTTableField alloc] initWithText:@"Composer"
[[[TTTableField alloc] initWithText:@"Message Composer"
url:@"tt://composerTest"] autorelease],
[[[TTTableField alloc] initWithText:@"Search Bar"
url:@"tt://searchTest"] autorelease],
Expand Down Expand Up @@ -104,7 +106,7 @@ - (void)viewDidLoad {
url:@"tt://imageTest1"] autorelease],
[[[TTTableField alloc] initWithText:@"YouTube Player"
url:@"tt://youTubeTest"] autorelease],
[[[TTTableField alloc] initWithText:@"Activity Views"
[[[TTTableField alloc] initWithText:@"Activity Labels"
url:@"tt://activityTest"] autorelease],
[[[TTTableField alloc] initWithText:@"Scroll View"
url:@"tt://scrollViewTest"] autorelease],
Expand Down
2 changes: 1 addition & 1 deletion samples/TTCatalog/Classes/StyleTestController.m
Expand Up @@ -87,7 +87,7 @@ - (void)loadView {
width:1 lightSource:270 next:nil]]]]]],


// New bubble
// Badge
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:TT_ROUNDED] next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(1.5, 1.5, 1.5, 1.5) next:
[TTShadowStyle styleWithColor:RGBACOLOR(0,0,0,0.8) blur:2 offset:CGSizeMake(0, 5) next:
Expand Down
53 changes: 53 additions & 0 deletions src/TTBadgeView.m
@@ -0,0 +1,53 @@
#import "Three20/TTBadgeView.h"
#import "Three20/TTDefaultStyleSheet.h"

///////////////////////////////////////////////////////////////////////////////////////////////////

@implementation TTBadgeView

@synthesize message = _message;

///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject

- (id)initWithMessage:(NSString*)message {
if (self = [self initWithFrame:CGRectZero]) {
self.message = message;
}
return self;
}

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_message = nil;

self.style = TTSTYLE(badge);
self.backgroundColor = [UIColor clearColor];
}
return self;
}

- (void)dealloc {
[_message release];
[super dealloc];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// TTStyleDelegate

- (NSString*)textForLayerWithStyle:(TTStyle*)style {
return _message;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// public

- (void)setMessage:(NSString*)message {
if (message != _message) {
[_message release];
_message = [message copy];
[self setNeedsDisplay];
}
}

@end
4 changes: 2 additions & 2 deletions src/TTButton.m
Expand Up @@ -156,7 +156,7 @@ - (UIFont*)defaultFont {
- (CGRect)rectForTitle:(NSString*)title forSize:(CGSize)size withFont:(UIFont*)font {
CGRect rect = CGRectZero;
if (self.contentHorizontalAlignment == UIControlContentHorizontalAlignmentLeft
&& self.contentHorizontalAlignment == UIControlContentVerticalAlignmentTop) {
&& self.contentVerticalAlignment == UIControlContentVerticalAlignmentTop) {
rect.size = size;
} else {
CGSize textSize = [title sizeWithFont:font];
Expand Down Expand Up @@ -336,7 +336,7 @@ - (void)setEnabled:(BOOL)enabled {
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTStyleDelegate

- (void)drawContent:(CGRect)rect withStyle:(TTStyle*)style shape:(TTShape*)shape {
- (void)drawLayer:(CGRect)rect withStyle:(TTStyle*)style shape:(TTShape*)shape {
NSString* title = [self titleForCurrentState];
UIEdgeInsets shapeInsets = [shape insetsForSize:rect.size];
CGRect innerRect = TTRectInset(rect, shapeInsets);
Expand Down
13 changes: 13 additions & 0 deletions src/TTDefaultStyleSheet.m
Expand Up @@ -177,6 +177,19 @@ - (TTStyle*)whiteBezel {
[TTSolidBorderStyle styleWithColor:RGBCOLOR(178, 178, 178) width:1 next:nil]]];
}

- (TTStyle*)badge {
return
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:TT_ROUNDED] next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(1, 1, 1, 1) next:
[TTShadowStyle styleWithColor:RGBACOLOR(0,0,0,1) blur:3 offset:CGSizeMake(0, 4) next:
[TTReflectiveFillStyle styleWithColor:RGBCOLOR(221, 17, 27) next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(-1, -1, -1, -1) next:
[TTSolidBorderStyle styleWithColor:[UIColor whiteColor] width:2 next:
[TTPaddingStyle styleWithPadding:UIEdgeInsetsMake(-4, 0, -4, 0) next:
[TTTextStyle styleWithFont:[UIFont boldSystemFontOfSize:13]
color:[UIColor whiteColor] next:nil]]]]]]]];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// public colors

Expand Down
7 changes: 5 additions & 2 deletions src/TTImageView.m
Expand Up @@ -136,13 +136,16 @@ - (void)requestDidCancelLoad:(TTURLRequest*)request {
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTStyleDelegate

- (void)drawContent:(CGRect)rect withStyle:(TTStyle*)style shape:(TTShape*)shape {
- (void)drawLayer:(CGRect)rect withStyle:(TTStyle*)style shape:(TTShape*)shape {
if ([style isKindOfClass:[TTContentStyle class]]) {
[shape addToPath:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);

[shape addToPath:rect];
CGContextClip(context);

[self drawContent:rect];

CGContextRestoreGState(context);
}
}
Expand Down
17 changes: 4 additions & 13 deletions src/TTLinkView.m → src/TTLink.m
@@ -1,18 +1,17 @@
#include "Three20/TTLinkView.h"
#include "Three20/TTLink.h"
#include "Three20/TTNavigationCenter.h"
#include "Three20/TTShape.h"
#include "Three20/TTStyledView.h"
#include "Three20/TTDefaultStyleSheet.h"

///////////////////////////////////////////////////////////////////////////////////////////////////

@implementation TTLinkView
@implementation TTLink

@synthesize delegate = _delegate, url = _url;
@synthesize url = _url;

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_delegate = nil;
_url = nil;
_screenView = nil;

Expand All @@ -31,15 +30,7 @@ - (void)dealloc {
///////////////////////////////////////////////////////////////////////////////////////////////////

- (void)tapped {
BOOL okToDispatch = YES;
if ([_delegate respondsToSelector:@selector(linkVisited:link:animated:)]) {
okToDispatch = (BOOL)(int)[_delegate performSelector:@selector(linkVisited:link:animated:)
withObject:_url withObject:self withObject:(id)(int)YES];
}

if (okToDispatch) {
[[TTNavigationCenter defaultCenter] displayObject:_url];
}
[[TTNavigationCenter defaultCenter] displayObject:_url];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/TTShinyLabel.m → src/TTSearchlightLabel.m
@@ -1,6 +1,6 @@
#import "Three20/TTShinyLabel.h"
#import "Three20/TTSearchlightLabel.h"

@implementation TTShinyLabel
@implementation TTSearchlightLabel

@synthesize text = _text, font = _font, textColor, spotlightColor = _spotlightColor,
textAlignment = _textAlignment;
Expand Down

0 comments on commit 779169b

Please sign in to comment.