Skip to content

Commit

Permalink
* New class: TTPageControl - just like UIPageControl, but with stylab…
Browse files Browse the repository at this point in the history
…le dots.

* Fixed: infinite loop in TTTableViewController (thanks to Gary B. for fix)
* Fixed: TTWebController back/forward buttons got out of sync (thanks to holtwick fix)
* Fixed: TTTextStyle doesn't respect vertical alignment for multi-line text
* Fixed: During TTNavigator-imposed delay, TTTableViewDataSource should appear to be loading
* Fixed: diffstrings omits some strings from generated xml file
  • Loading branch information
joehewitt committed Aug 6, 2009
1 parent fa8cb3f commit c4048ee
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 36 deletions.
9 changes: 5 additions & 4 deletions diffstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def diff(self, localizedStrings):
if source in localizedStrings.strings:
target = localizedStrings.strings[source]
translation.translated[sourceEnum] = True

targetEnum = enumerateStringVariables(target)
translation.strings[sourceEnum] = targetEnum

Expand Down Expand Up @@ -322,7 +322,7 @@ def mergeReport(self, sourceStrings, translation):
if sourceEnum in translation.strings:
targetEnum = translation.strings[sourceEnum]
target = denumerateStringVariables(targetEnum)
if target != self.strings[source]:
if source not in self.strings or target != self.strings[source]:
updatedStrings.append(source)
else:
ignoredStrings.append(source)
Expand Down Expand Up @@ -491,13 +491,14 @@ def __parse(self, filePath):
def __invertSourceMap(self, sourceMap):
sourceFileMap = {}

for source in self.strings:
for sourceEnum in self.strings:
source = denumerateStringVariables(sourceEnum)
if source in sourceMap:
sourcePaths = sourceMap[source]
for sourcePath in sourcePaths:
if sourcePath not in sourceFileMap:
sourceFileMap[sourcePath] = []
sourceFileMap[sourcePath].append(source)
sourceFileMap[sourcePath].append(sourceEnum)
break

for sourceName, sourceFileStrings in sourceFileMap.iteritems():
Expand Down
22 changes: 19 additions & 3 deletions src/TTDefaultStyleSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ - (TTStyle*)photoStatusLabel {
shadowOffset:CGSizeMake(0, -1) next:nil]]];
}

- (TTStyle*)pageDot:(UIControlState)state {
if (state == UIControlStateSelected) {
return [self pageDotWithColor:[UIColor whiteColor]];
} else {
return [self pageDotWithColor:RGBCOLOR(77, 77, 77)];
}
}

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

Expand Down Expand Up @@ -653,6 +661,11 @@ - (UIColor*)toolbarButtonTextColorForState:(UIControlState)state {
///////////////////////////////////////////////////////////////////////////////////////////////////
// public

- (TTStyle*)selectionFillStyle:(TTStyle*)next {
return [TTLinearGradientFillStyle styleWithColor1:RGBCOLOR(5,140,245)
color2:RGBCOLOR(1,93,230) next:next];
}

- (TTStyle*)toolbarButtonForState:(UIControlState)state shape:(TTShape*)shape
tintColor:(UIColor*)tintColor font:(UIFont*)font {
UIColor* stateTintColor = [self toolbarButtonColorWithTintColor:tintColor forState:state];
Expand All @@ -677,9 +690,12 @@ - (TTStyle*)toolbarButtonForState:(UIControlState)state shape:(TTShape*)shape
shadowOffset:CGSizeMake(0, -1) next:nil]]]]]]]]]];
}

- (TTStyle*)selectionFillStyle:(TTStyle*)next {
return [TTLinearGradientFillStyle styleWithColor1:RGBCOLOR(5,140,245)
color2:RGBCOLOR(1,93,230) next:next];
- (TTStyle*)pageDotWithColor:(UIColor*)color {
return
[TTBoxStyle styleWithMargin:UIEdgeInsetsMake(0,0,0,10) padding:UIEdgeInsetsMake(6,6,0,0) next:
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:2.5] next:
[TTSolidFillStyle styleWithColor:color next:nil]]];
}


@end
8 changes: 6 additions & 2 deletions src/TTModelViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ - (void)updateViewStates {
}
}

- (void)createInterstitialModel {
self.model = [[[TTModel alloc] init] autorelease];
}

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

Expand Down Expand Up @@ -235,7 +239,7 @@ - (void)modelDidEndUpdates:(id<TTModel>)model {
[self createModel];
}
if (!_model) {
self.model = [[[TTModel alloc] init] autorelease];
[self createInterstitialModel];
}
}
return _model;
Expand Down Expand Up @@ -308,7 +312,7 @@ - (void)reload {
}

- (void)reloadIfNeeded {
if ([self shouldReload]) {
if ([self shouldReload] && !self.model.isLoading) {
[self reload];
}
}
Expand Down
130 changes: 130 additions & 0 deletions src/TTPageControl.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "Three20/TTPageControl.h"
#include "Three20/TTStyleSheet.h"
#include "Three20/TTStyle.h"

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

@implementation TTPageControl

@synthesize numberOfPages = _numberOfPages, currentPage = _currentPage, dotStyle = _dotStyle;

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

- (TTStyle*)normalDotStyle {
if (!_normalDotStyle) {
_normalDotStyle = [[[TTStyleSheet globalStyleSheet] styleWithSelector:_dotStyle
forState:UIControlStateNormal] retain];
}
return _normalDotStyle;
}

- (TTStyle*)currentDotStyle {
if (!_currentDotStyle) {
_currentDotStyle = [[[TTStyleSheet globalStyleSheet] styleWithSelector:_dotStyle
forState:UIControlStateSelected] retain];
}
return _currentDotStyle;
}

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

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_numberOfPages = 0;
_currentPage = 0;
_dotStyle = nil;
_normalDotStyle = nil;
_currentDotStyle = nil;

self.backgroundColor = [UIColor clearColor];
self.dotStyle = @"pageDot:";
}
return self;
}

- (void)dealloc {
TT_RELEASE_SAFELY(_dotStyle);
TT_RELEASE_SAFELY(_normalDotStyle);
TT_RELEASE_SAFELY(_currentDotStyle);
[super dealloc];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// UIView

- (void)drawRect:(CGRect)rect {
TTStyleContext* context = [[[TTStyleContext alloc] init] autorelease];
TTBoxStyle* boxStyle = [self.normalDotStyle firstStyleOfClass:[TTBoxStyle class]];

CGSize dotSize = [self.normalDotStyle addToSize:CGSizeZero context:context];
CGRect contentRect = CGRectMake(0, 0, dotSize.width, dotSize.height);

for (NSInteger i = 0; i < _numberOfPages; ++i) {
contentRect.origin.x += boxStyle.margin.left;

context.frame = contentRect;
context.contentFrame = contentRect;

if (i == _currentPage) {
[self.currentDotStyle draw:context];
} else {
[self.normalDotStyle draw:context];
}
contentRect.origin.x += dotSize.width + boxStyle.margin.right;
}
}

- (CGSize)sizeThatFits:(CGSize)size {
TTStyleContext* context = [[[TTStyleContext alloc] init] autorelease];
CGSize dotSize = [self.normalDotStyle addToSize:CGSizeZero context:context];

CGFloat margin = 0;
TTBoxStyle* boxStyle = [self.normalDotStyle firstStyleOfClass:[TTBoxStyle class]];
if (boxStyle) {
margin = boxStyle.margin.right + boxStyle.margin.left;
}

return CGSizeMake((dotSize.width * _numberOfPages) + (margin * (_numberOfPages-1)),
dotSize.height);
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// UIControl

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
if (self.touchInside) {
CGPoint point = [touch locationInView:self];
self.currentPage = round(point.x / self.width);
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
}

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

- (void)setNumberOfPages:(NSInteger)numberOfPages {
if (numberOfPages != _numberOfPages) {
_numberOfPages = numberOfPages;
[self setNeedsDisplay];
}
}

- (void)setCurrentPage:(NSInteger)currentPage {
if (currentPage != _currentPage) {
_currentPage = currentPage;
[self setNeedsDisplay];
}
}

- (void)setDotStyle:(NSString*)dotStyle {
if (![dotStyle isEqualToString:_dotStyle]) {
[_dotStyle release];
_dotStyle = [dotStyle copy];
TT_RELEASE_SAFELY(_normalDotStyle);
TT_RELEASE_SAFELY(_currentDotStyle);
}
}

@end
22 changes: 9 additions & 13 deletions src/TTPostController.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,16 @@ - (void)setOriginView:(UIView*)view {
}

- (void)post {
if (_textEditor.text.isEmptyOrWhitespace) {
[self cancel];
BOOL shouldDismiss = [self willPostText:_textEditor.text];
if ([_delegate respondsToSelector:@selector(postController:willPostText:)]) {
shouldDismiss = [_delegate postController:self willPostText:_textEditor.text];
}

if (shouldDismiss) {
[self dismissWithResult:nil animated:YES];
} else {
BOOL shouldDismiss = [self willPostText:_textEditor.text];
if ([_delegate respondsToSelector:@selector(postController:willPostText:)]) {
shouldDismiss = [_delegate postController:self willPostText:_textEditor.text];
}

if (shouldDismiss) {
[self dismissWithResult:nil animated:YES];
} else {
[self enableButtons:NO];
[self showActivity:[self titleForActivity]];
}
[self enableButtons:NO];
[self showActivity:[self titleForActivity]];
}
}

Expand Down
30 changes: 20 additions & 10 deletions src/TTStyle.m
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,30 @@ + (TTTextStyle*)styleWithFont:(UIFont*)font color:(UIColor*)color
///////////////////////////////////////////////////////////////////////////////////////////////////
// private

- (CGSize)sizeOfText:(NSString*)text withFont:(UIFont*)font size:(CGSize)size {
if (_numberOfLines == 1) {
return [text sizeWithFont:font];
} else {
CGSize maxSize = CGSizeMake(size.width, CGFLOAT_MAX);
CGSize textSize = [text sizeWithFont:font constrainedToSize:maxSize
lineBreakMode:_lineBreakMode];
if (_numberOfLines) {
CGFloat maxHeight = font.lineHeight * _numberOfLines;
if (textSize.height > maxHeight) {
textSize.height = maxHeight;
}
}
return textSize;
}
}

- (CGRect)rectForText:(NSString*)text forSize:(CGSize)size withFont:(UIFont*)font {
CGRect rect = CGRectZero;
if (_textAlignment == UITextAlignmentLeft
&& _verticalAlignment == UIControlContentVerticalAlignmentTop) {
rect.size = size;
} else {
CGSize textSize = [text sizeWithFont:font];
CGSize textSize = [self sizeOfText:text withFont:font size:size];

if (size.width < textSize.width) {
size.width = textSize.width;
Expand All @@ -539,14 +556,6 @@ - (CGRect)rectForText:(NSString*)text forSize:(CGSize)size withFont:(UIFont*)fon
return rect;
}

- (CGSize)sizeOfText:(NSString*)text withFont:(UIFont*)font size:(CGSize)size {
if (_numberOfLines == 1) {
return [text sizeWithFont:font];
} else {
return [text sizeWithFont:font constrainedToSize:size lineBreakMode:_lineBreakMode];
}
}

- (void)drawText:(NSString*)text context:(TTStyleContext*)context {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
Expand Down Expand Up @@ -574,7 +583,8 @@ - (void)drawText:(NSString*)text context:(TTStyleContext*)context {
baselineAdjustment:UIBaselineAdjustmentAlignCenters];
context.contentFrame = titleRect;
} else {
rect.size = [text drawInRect:rect withFont:font lineBreakMode:_lineBreakMode
CGRect titleRect = [self rectForText:text forSize:rect.size withFont:font];
rect.size = [text drawInRect:titleRect withFont:font lineBreakMode:_lineBreakMode
alignment:_textAlignment];
context.contentFrame = rect;
}
Expand Down
7 changes: 6 additions & 1 deletion src/TTTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ @implementation TTTableViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
// private

- (void)createInterstitialModel {
self.dataSource = [[[TTTableViewInterstialDataSource alloc] init] autorelease];
}

- (void)updateTableDelegate {
if (!_tableView.delegate) {
[_tableDelegate release];
Expand All @@ -44,7 +48,8 @@ - (void)addToOverlayView:(UIView*)view {
CGRect frame = [self rectForOverlayView];
_tableOverlayView = [[UIView alloc] initWithFrame:frame];
_tableOverlayView.autoresizesSubviews = YES;
_tableOverlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_tableOverlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleBottomMargin;
NSInteger tableIndex = [_tableView.superview.subviews indexOfObject:_tableView];
if (tableIndex != NSNotFound) {
[_tableView.superview addSubview:_tableOverlayView];
Expand Down
Loading

0 comments on commit c4048ee

Please sign in to comment.