Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge branch 'development' of github.com:facebook/three20 into develo…
Browse files Browse the repository at this point in the history
…pment
  • Loading branch information
jwang committed Jul 11, 2011
2 parents 643aa50 + 3cd5869 commit 43c6c66
Show file tree
Hide file tree
Showing 45 changed files with 3,662 additions and 806 deletions.
18 changes: 18 additions & 0 deletions samples/Style/TTCSSStyleSheets/Classes/SampleCSSStyleSheet.h
@@ -0,0 +1,18 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@interface SampleCSSStyleSheet : TTDefaultCSSStyleSheet {}
@end
36 changes: 36 additions & 0 deletions samples/Style/TTCSSStyleSheets/Classes/SampleCSSStyleSheet.m
@@ -0,0 +1,36 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "SampleCSSStyleSheet.h"

@implementation SampleCSSStyleSheet

- (TTStyle *)h3:(UIControlState)state {
return
[TTSolidFillStyle styleWithColor:TTCSSSTATE(@"h3", backgroundColor, state) next:
[TTTextStyle styleWithCssSelector:@"h3" forState:state next:
nil]];
}

- (TTStyle *)h4:(UIControlState)state {
return
[TTSolidFillStyle styleWithColor:TTCSSSTATE(@"h4text", backgroundColor, state) next:
[TTShadowStyle styleWithCssSelector:@"h4shadow" forState:state next:
[TTTextStyle styleWithCssSelector:@"h4text" forState:state next:
nil]]];
}

@end
Expand Up @@ -16,8 +16,6 @@

@interface StyleSheetViewController : TTViewController {
@private
TTCSSStyleSheet* _styleSheet;

BOOL _loadedSuccessfully;
}

Expand Down
68 changes: 45 additions & 23 deletions samples/Style/TTCSSStyleSheets/Classes/StyleSheetViewController.m
Expand Up @@ -16,6 +16,8 @@

#import "StyleSheetViewController.h"

#import "SampleCSSStyleSheet.h"


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -25,25 +27,18 @@ @implementation StyleSheetViewController

///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
_styleSheet = [[TTCSSStyleSheet alloc] init];

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
SampleCSSStyleSheet *_styleSheet = [[[SampleCSSStyleSheet alloc] init] autorelease];
_loadedSuccessfully = [_styleSheet
loadFromFilename:TTPathForBundleResource(@"stylesheet.css")];
addStyleSheetFromDisk:TTPathForBundleResource(@"stylesheet.css")];
[TTStyleSheet setGlobalStyleSheet:_styleSheet];
}

return self;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
TT_RELEASE_SAFELY(_styleSheet);

[super dealloc];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)loadView {
[super loadView];
Expand All @@ -55,23 +50,50 @@ - (void)loadView {
}

self.title = @"Three20 CSS extension";
self.view.backgroundColor = TTCSS(@"body", backgroundColor);

self.view.backgroundColor = [_styleSheet backgroundColorWithCssSelector: @"body"
forState: UIControlStateNormal];

// Using helper macro
UILabel* headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.text = @"Header text";
headerLabel.font = [_styleSheet fontWithCssSelector:@"h1" forState:UIControlStateNormal];
headerLabel.textColor = [_styleSheet colorWithCssSelector:@"h1" forState:UIControlStateNormal];
headerLabel.backgroundColor = [_styleSheet backgroundColorWithCssSelector: @"h1"
forState: UIControlStateNormal];
headerLabel.shadowColor = [_styleSheet textShadowColorWithCssSelector: @"h1"
forState: UIControlStateNormal];
headerLabel.shadowOffset = [_styleSheet textShadowOffsetWithCssSelector: @"h1"
forState: UIControlStateNormal];
headerLabel.font = TTCSS(@"h1", font);
headerLabel.textColor = TTCSS(@"h1", color);
headerLabel.backgroundColor = TTCSS(@"h1", backgroundColor);
headerLabel.shadowColor = TTCSS(@"h1", shadowColor);
headerLabel.shadowOffset = TTCSS(@"h1", shadowOffset);
[headerLabel sizeToFit];
[self.view addSubview:headerLabel];

// Using UILabel addition
UILabel* headerLabel2 = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel2.text = @"Header 2 text";
[headerLabel2 applyCssSelector:@"h2"];
[headerLabel2 sizeToFit];
CGFloat top = headerLabel.frame.size.height;
CGRect frame = headerLabel2.frame;
frame.origin.y = top;
headerLabel2.frame = frame;
[self.view addSubview:headerLabel2];

// Using TTTextStyle addition
TTButton* headerLabel3 = [TTButton buttonWithStyle:@"h3:" title:@"Header 3 text"];
[headerLabel3 sizeToFit];
top += headerLabel2.frame.size.height;
frame = headerLabel3.frame;
frame.origin.y = top;
headerLabel3.frame = frame;
[self.view addSubview:headerLabel3];

// Using TTTextStyle + TTShadowStyle addition
TTButton* headerLabel4 = [TTButton buttonWithStyle:@"h4:" title:@"Header 4 text"];
[headerLabel4 sizeToFit];
top += headerLabel2.frame.size.height;
frame = headerLabel4.frame;
frame.origin.y = top;
headerLabel4.frame = frame;
[self.view addSubview:headerLabel4];

TT_RELEASE_SAFELY(headerLabel);
TT_RELEASE_SAFELY(headerLabel2);
}


Expand Down
Expand Up @@ -6,6 +6,6 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Three20/Three20.h"
#import "extThree20CSSStyle/extThree20CSSStyle.h"
#import "extThree20CSSStyle/extThree20CSSStyle+Additions.h"
#import "Atlas.h"
#endif
37 changes: 34 additions & 3 deletions samples/Style/TTCSSStyleSheets/Resources/stylesheet.css
Expand Up @@ -15,13 +15,44 @@
*/

body {
background-color: #111;
background-color: #114;
}

h1 {
font-weight: bold;
font-size: 50pt;
color: #666;
color: #FF6;
background-color: transparent;
text-shadow: 1px 1px 1px #999; /* blur amount (3rd value) doesn't do anything */
text-shadow: 2px 2px 0px #F99;
}

h2 {
font-size: 45pt;
color: white;
background-color: transparent;
text-shadow: 0px 1px 3px #9BF;
}

h3, h3:hover {
font-size: 35pt;
font-weight: bold;
color: white;
background-color: transparent;
text-shadow: 3px -3px 3px #99F;
}

h3:hover {
color: #99F;
text-shadow: 3px 3px 3px white;
}

h4text, h4text:hover {
color: white;
font-size: 35pt;
background-color: transparent;
}

h4text:hover { color: gray; }

h4shadow { text-shadow: 3px 3px 4px rgba(0, 255, 0, .5); }
h4shadow:hover { text-shadow: 0px 0px 4px green; }
Expand Up @@ -28,6 +28,7 @@
6E850FAE11B176F10071A4FD /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 6E850FAC11B176F10071A4FD /* Default.png */; };
6E850FAF11B176F10071A4FD /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 6E850FAD11B176F10071A4FD /* Icon.png */; };
6E850FB811B1795F0071A4FD /* Atlas.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E850FB711B1795F0071A4FD /* Atlas.m */; };
90C3A1C1132BF66B00AC06A2 /* SampleCSSStyleSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 90C3A1C0132BF66B00AC06A2 /* SampleCSSStyleSheet.m */; };
EB383B6510BBF62B0000B2D2 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EB383B6410BBF62B0000B2D2 /* QuartzCore.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -234,6 +235,8 @@
6E850FB711B1795F0071A4FD /* Atlas.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Atlas.m; sourceTree = "<group>"; };
6E8513D111B19B080071A4FD /* TTCSSStyleSheets_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TTCSSStyleSheets_Prefix.pch; path = Headers/TTCSSStyleSheets_Prefix.pch; sourceTree = "<group>"; };
6E8513D211B19B0E0071A4FD /* TTCSSStyleSheets-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "TTCSSStyleSheets-Info.plist"; sourceTree = "<group>"; };
90C3A1BF132BF66B00AC06A2 /* SampleCSSStyleSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleCSSStyleSheet.h; sourceTree = "<group>"; };
90C3A1C0132BF66B00AC06A2 /* SampleCSSStyleSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleCSSStyleSheet.m; sourceTree = "<group>"; };
EB383B6410BBF62B0000B2D2 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -268,6 +271,8 @@
1D3623250D0F684500981E51 /* AppDelegate.m */,
6E850FB611B1795F0071A4FD /* Atlas.h */,
6E850FB711B1795F0071A4FD /* Atlas.m */,
90C3A1BF132BF66B00AC06A2 /* SampleCSSStyleSheet.h */,
90C3A1C0132BF66B00AC06A2 /* SampleCSSStyleSheet.m */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -680,6 +685,7 @@
1D3623260D0F684500981E51 /* AppDelegate.m in Sources */,
6E850FB811B1795F0071A4FD /* Atlas.m in Sources */,
6E036BF811B38F3C0025E8EE /* StyleSheetViewController.m in Sources */,
90C3A1C1132BF66B00AC06A2 /* SampleCSSStyleSheet.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
45 changes: 45 additions & 0 deletions src/extThree20CSSStyle/Headers/TTCSSGlobalStyle.h
@@ -0,0 +1,45 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

///////////////////////////////////////////////////////////////////////////////////////////////////
// CSS Style helpers

#define TTCSSSTYLESHEET ([[TTDefaultCSSStyleSheet globalCSSStyleSheet] styleSheet])

#define TTCSS_color(_SELECTOR, _STATE) \
([TTCSSSTYLESHEET colorWithCssSelector:_SELECTOR forState:_STATE])

#define TTCSS_backgroundColor(_SELECTOR, _STATE) \
([TTCSSSTYLESHEET backgroundColorWithCssSelector:_SELECTOR forState:_STATE])

#define TTCSS_font(_SELECTOR, _STATE) \
([TTCSSSTYLESHEET fontWithCssSelector:_SELECTOR forState:_STATE])

#define TTCSS_shadowColor(_SELECTOR, _STATE) \
([TTCSSSTYLESHEET textShadowColorWithCssSelector:_SELECTOR forState:_STATE])

#define TTCSS_shadowOffset(_SELECTOR, _STATE) \
([TTCSSSTYLESHEET textShadowOffsetWithCssSelector:_SELECTOR forState:_STATE])

#define TTCSS_shadowRadius(_SELECTOR, _STATE) \
([TTCSSSTYLESHEET textShadowRadiusWithCssSelector:_SELECTOR forState:_STATE])

// _VARNAME must be one of: color, backgroundColor, font, shadowColor, shadowOffset, shadowRadius
#define TTCSSSTATE(_SELECTOR, _VARNAME, _STATE) \
TTCSS_##_VARNAME(_SELECTOR, _STATE)

#define TTCSS(_SELECTOR, _VARNAME) \
TTCSSSTATE(_SELECTOR, _VARNAME, UIControlStateNormal)
5 changes: 5 additions & 0 deletions src/extThree20CSSStyle/Headers/TTCSSStyleSheet.h
Expand Up @@ -75,6 +75,11 @@
*/
- (CGSize)textShadowOffsetWithCssSelector:(NSString*)selector forState:(UIControlState)state;

/**
* Get text shadow radius from a specific rule set.
*/
- (CGFloat)textShadowRadiusWithCssSelector:(NSString*)selector forState:(UIControlState)state;


/**
* Release all cached data.
Expand Down
28 changes: 28 additions & 0 deletions src/extThree20CSSStyle/Headers/TTShadowStyleAdditions.h
@@ -0,0 +1,28 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "Three20Style/TTShadowStyle.h"

@interface TTShadowStyle (TTCSSCategory)

+ (TTShadowStyle*)styleWithCssSelector:(NSString*)selector
forState:(UIControlState)state
next:(TTStyle*)next;

+ (TTShadowStyle*)styleWithCssSelector:(NSString*)selector
next:(TTStyle*)next;

@end
55 changes: 55 additions & 0 deletions src/extThree20CSSStyle/Headers/TTTextStyleAdditions.h
@@ -0,0 +1,55 @@
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import "Three20Style/TTTextStyle.h"

@interface TTTextStyle (TTCSSCategory)

+ (TTTextStyle*)styleWithCssSelector:(NSString*)selector
next:(TTStyle*)next;

+ (TTTextStyle*)styleWithCssSelector:(NSString*)selector
minimumFontSize:(CGFloat)minimumFontSize
next:(TTStyle*)next;

+ (TTTextStyle*)styleWithCssSelector:(NSString*)selector
minimumFontSize:(CGFloat)minimumFontSize
textAlignment:(UITextAlignment)textAlignment
verticalAlignment:(UIControlContentVerticalAlignment)verticalAlignment
lineBreakMode:(UILineBreakMode)lineBreakMode
numberOfLines:(NSInteger)numberOfLines
next:(TTStyle*)next;


+ (TTTextStyle*)styleWithCssSelector:(NSString*)selector
forState:(UIControlState)state
next:(TTStyle*)next;

+ (TTTextStyle*)styleWithCssSelector:(NSString*)selector
forState:(UIControlState)state
minimumFontSize:(CGFloat)minimumFontSize
next:(TTStyle*)next;

+ (TTTextStyle*)styleWithCssSelector:(NSString*)selector
forState:(UIControlState)state
minimumFontSize:(CGFloat)minimumFontSize
textAlignment:(UITextAlignment)textAlignment
verticalAlignment:(UIControlContentVerticalAlignment)verticalAlignment
lineBreakMode:(UILineBreakMode)lineBreakMode
numberOfLines:(NSInteger)numberOfLines
next:(TTStyle*)next;

@end

0 comments on commit 43c6c66

Please sign in to comment.