diff --git a/framework/mvc/view/css/Bee_UIStyleParser.h b/framework/mvc/view/css/Bee_UIStyleParser.h index 759f172..cffb452 100644 --- a/framework/mvc/view/css/Bee_UIStyleParser.h +++ b/framework/mvc/view/css/Bee_UIStyleParser.h @@ -131,6 +131,9 @@ - (UITextBorderStyle)parseTextBorderStyleWithKeys:(NSArray *)keys; - (UITextBorderStyle)parseTextBorderStyleWithKeys:(NSArray *)keys defaultValue:(UITextBorderStyle)defaultValue; +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys; +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys defaultValue:(UIRectCorner)defaultValue; + @end #endif // #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) diff --git a/framework/mvc/view/css/Bee_UIStyleParser.m b/framework/mvc/view/css/Bee_UIStyleParser.m index 1651d21..28a374b 100644 --- a/framework/mvc/view/css/Bee_UIStyleParser.m +++ b/framework/mvc/view/css/Bee_UIStyleParser.m @@ -824,6 +824,48 @@ - (UITextBorderStyle)parseTextBorderStyleWithKeys:(NSArray *)keys defaultValue:( return UITextBorderStyleNone; } +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys +{ + return [self parseViewCornersStyleWithKeys:keys defaultValue:UIRectCornerAllCorners]; +} + +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys defaultValue:(UIRectCorner)defaultValue +{ + NSString * value = [self parseStringWithKeys:keys]; + if ( nil == value ) + { + return defaultValue; + } + + NSMutableArray *values = [NSMutableArray arrayWithArray:[value componentsSeparatedByString:@"-"]]; + UIRectCorner corners = [self parseCornerByString:[values safeObjectAtIndex:0]]; + [values removeObjectAtIndex:0]; + for (NSString * str in values) { + corners = corners | [self parseCornerByString:str]; + } + return corners; +} + +- (UIRectCorner)parseCornerByString:(NSString *)str +{ + UIRectCorner corners; + if ( [str matchAnyOf:@[@"BL", @"BottomLeft"]] ) { + corners = UIRectCornerBottomLeft; + }else if ( [str matchAnyOf:@[@"BR", @"BottomRight"]] ) + { + corners = UIRectCornerBottomRight; + }else if ( [str matchAnyOf:@[@"TR", @"TopRight"]] ) + { + corners = UIRectCornerTopRight; + }else if ( [str matchAnyOf:@[@"TL", @"TopLeft"]] ){ + corners = UIRectCornerTopLeft; + }else + { + corners = UIRectCornerAllCorners; + } + return corners; +} + @end #endif // #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) diff --git a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m index 5a44370..ad4a3b4 100644 --- a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m +++ b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m @@ -430,6 +430,7 @@ - (void)applyStyle if ( self.UIStyle ) { [self applyUIStyling:self.UIStyle.properties]; + [self applyUICorners:self.UIStyle.properties]; } } @@ -648,8 +649,11 @@ - (void)applyViewBorder:(NSMutableDictionary *)properties self.layer.borderColor = [properties parseColorWithKeys:@[@"border-color"] defaultValue:[UIColor clearColor]].CGColor; self.layer.borderWidth = [properties parseFloatWithKeys:@[@"border-width"] defaultValue:0.0f]; + if ([properties stringOfAny:@[@"corners"] removeAll:false] != nil) { + return; + } self.layer.cornerRadius = [properties parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; - + if ( self.layer.cornerRadius > 0.0f ) { self.layer.masksToBounds = YES; @@ -715,7 +719,6 @@ - (void)applyViewShadow:(NSMutableDictionary *)properties self.layer.shadowOffset = [properties parseSizeWithKeys:@[@"shadow-offset"] defaultValue:CGSizeZero]; self.layer.shadowOpacity = [properties parseFloatWithKeys:@[@"shadow-opacity"] defaultValue:1.0f]; self.layer.shadowRadius = [properties parseFloatWithKeys:@[@"shadow-radius"] defaultValue:1.0f]; -// self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath; } - (void)applyUIStyling:(NSDictionary *)properties @@ -733,6 +736,29 @@ - (void)applyUIStyling:(NSDictionary *)properties [super applyUIStyling:propertiesCopy]; } +- (void)applyUICorners:(NSDictionary *)properties +{ + NSMutableDictionary * propertiesCopy = [NSMutableDictionary dictionaryWithDictionary:properties]; + + if ([propertiesCopy stringOfAny:@[@"corners"] removeAll:false] == nil) { + return; + } + float cornerRadius = [propertiesCopy parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; + if ( cornerRadius > 0.0f ) + { + self.layer.cornerRadius = 0; + self.layer.mask = nil; + UIRectCorner corners = [propertiesCopy parseViewCornersStyleWithKeys:@[@"corners"]]; + UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds + byRoundingCorners:corners + cornerRadii:CGSizeMake(cornerRadius, 0.0)]; + CAShapeLayer *maskLayer = [CAShapeLayer layer]; + maskLayer.frame = self.bounds; + maskLayer.path = maskPath.CGPath; + self.layer.mask = maskLayer; + } +} + @end #endif // #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) diff --git a/framework/mvc/view/dom-capability/Bee_UICapability.h b/framework/mvc/view/dom-capability/Bee_UICapability.h index 0584271..c8482e4 100644 --- a/framework/mvc/view/dom-capability/Bee_UICapability.h +++ b/framework/mvc/view/dom-capability/Bee_UICapability.h @@ -113,6 +113,7 @@ - (BOOL)supportForUIStyling; - (void)applyUIStyling:(NSDictionary *)properties; +- (void)applyUICorners:(NSDictionary *)properties; // resource loading? diff --git a/framework/mvc/view/dom-capability/Bee_UICapability.m b/framework/mvc/view/dom-capability/Bee_UICapability.m index de5ee84..516aa8e 100644 --- a/framework/mvc/view/dom-capability/Bee_UICapability.m +++ b/framework/mvc/view/dom-capability/Bee_UICapability.m @@ -112,6 +112,11 @@ - (void)applyUIStyling:(NSDictionary *)properties // WARN( @"unrecognized styles for '%@':\n%@", [[self class] description], properties ); } +- (void)applyUICorners:(NSDictionary *)properties +{ + +} + + (BOOL)supportForUIResourceLoading { return NO; diff --git a/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m b/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m index 6a38373..22b51cd 100644 --- a/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m +++ b/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m @@ -831,6 +831,7 @@ - (void)layoutTree:(CGRect)bound // viewFrame.size.width, viewFrame.size.height ); view.frame = viewFrame; + [view applyUICorners:view.UIStyle.properties]; } } diff --git a/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml b/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml index 6b17112..0a4c1ee 100644 --- a/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml +++ b/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml @@ -301,7 +301,10 @@ Love coding, also skilled in HTML, CSS and JS. margin-top: 2px; margin-left: 10px; background-color: #999; - border-radius: 8px; + border-radius: 20px; + border-color:#000; + border-width:2px; + corners:BL-BR-TL; } .profile-right-wrapper { diff --git a/projects/scaffold/scaffold/SchemaGenerator.m b/projects/scaffold/scaffold/SchemaGenerator.m index 081f91d..dceb1ea 100644 --- a/projects/scaffold/scaffold/SchemaGenerator.m +++ b/projects/scaffold/scaffold/SchemaGenerator.m @@ -2282,7 +2282,7 @@ - (NSString *)mm } } } - code.LINE( @" self.HTTP_%@( requestURI ).PARAM(@\"json\", [self.req objectToDictionary] )%@;", [self.method uppercaseString], fileListParam ); + code.LINE( @" self.HTTP_%@( requestURI ).PARAM(@\"json\", [self.req objectToDictionary] )%@;", [self.method uppercaseString], fileListParam ); } } else @@ -3024,19 +3024,33 @@ - (NSString *)h code.LINE( [NSString stringWithFormat:@"AS_SINGLETON( %@ServerConfig )", prefix] ); code.LINE( nil ); - code.LINE( @"AS_INT( CONFIG_DEVELOPMENT )" ); - code.LINE( @"AS_INT( CONFIG_TEST )" ); - code.LINE( @"AS_INT( CONFIG_PRODUCTION )" ); - code.LINE( nil ); - - code.LINE( @"@property (nonatomic, assign) NSUInteger config;" ); - code.LINE( nil ); + NSMutableArray *urlNames = [[NSMutableArray alloc] init]; + + for (NSString *key in self.server) { + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + [urlNames addObject:key]; + for (NSString *key1 in value) { + code.LINE( [NSString stringWithFormat:@"AS_STRING( CONFIG_%@_%@ )", [key uppercaseString], [key1 uppercaseString]]); + } + }else + { + code.LINE( [NSString stringWithFormat:@"AS_STRING( CONFIG_%@ )", [key uppercaseString]]); + } + } + code.LINE( nil ); - code.LINE( @"@property (nonatomic, readonly) NSString * url;" ); - code.LINE( @"@property (nonatomic, readonly) NSString * testUrl;" ); - code.LINE( @"@property (nonatomic, readonly) NSString * productionUrl;" ); - code.LINE( @"@property (nonatomic, readonly) NSString * developmentUrl;" ); - code.LINE( nil ); + if (urlNames.count) { + for (int i = 0; i < urlNames.count; i ++) { + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, assign) NSString * Config%@;", [urlNames safeObjectAtIndex:i]] ); + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * Url%@;", [urlNames safeObjectAtIndex:i]] ); + code.LINE( nil ); + } + } + + code.LINE( @"@property (nonatomic, assign) NSString* config;" ); + code.LINE( @"@property (nonatomic, readonly) NSString * url;" ); + code.LINE( nil ); code.LINE( @"@end" ); code.LINE( nil ); @@ -3069,76 +3083,137 @@ - (NSString *)mm { code.LINE( [controller mm] ); } - - NSString * dev = [self.server objectForKey:@"development"]; - NSString * tst = [self.server objectForKey:@"test"]; - NSString * pro = [self.server objectForKey:@"production"]; - - code.LINE( @"#pragma mark - config" ); - code.LINE( nil ); - + + code.LINE( @"#pragma mark - config" ); + code.LINE( @"@interface ServerConfig()" ); + code.LINE( nil ); + + NSMutableArray *urlNames = [[NSMutableArray alloc] init]; + + for (NSString *key in self.server) { + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + [urlNames addObject:key]; + for (NSString *key1 in value) { + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * %@_%@_Url;", key, key1]); + } + }else + { + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * %@Url;", key]); + } + } + code.LINE( nil ); + code.LINE( @"@end" ); + code.LINE( nil ); + + code.LINE( @"#pragma mark - config" ); + code.LINE( nil ); code.LINE( [NSString stringWithFormat:@"@implementation %@ServerConfig", prefix] ); code.LINE( nil ); code.LINE( [NSString stringWithFormat:@"DEF_SINGLETON( %@ServerConfig )", prefix] ); code.LINE( nil ); - - code.LINE( @"DEF_INT( CONFIG_DEVELOPMENT, 0 )" ); - code.LINE( @"DEF_INT( CONFIG_TEST, 1 )" ); - code.LINE( @"DEF_INT( CONFIG_PRODUCTION, 2 )" ); - code.LINE( nil ); - - code.LINE( @"@synthesize config = _config;" ); - code.LINE( @"@dynamic url;" ); - code.LINE( @"@dynamic testUrl;" ); - code.LINE( @"@dynamic productionUrl;" ); - code.LINE( @"@dynamic developmentUrl;" ); + + for (NSString *key in self.server) { + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + for (NSString *key1 in value) { + code.LINE( [NSString stringWithFormat:@"DEF_STRING( CONFIG_%@_%@, @\"%@_%@\")", [key uppercaseString], [key1 uppercaseString], [key uppercaseString], [key1 uppercaseString]]); + } + }else + { + code.LINE( [NSString stringWithFormat:@"DEF_STRING( CONFIG_%@, @\"%@\" )", [key uppercaseString], [key uppercaseString]]); + } + } + code.LINE( nil ); - code.LINE( @"- (NSString *)url" ); - code.LINE( @"{" ); - code.LINE( @" NSString * host = nil;" ); - code.LINE( nil ); - code.LINE( @" if ( self.CONFIG_DEVELOPMENT == self.config )" ); - code.LINE( @" {" ); - code.LINE( @" host = self.developmentUrl;" ); - code.LINE( @" }" ); - code.LINE( @" else if ( self.CONFIG_TEST == self.config )" ); - code.LINE( @" {" ); - code.LINE( @" host = self.testUrl;" ); - code.LINE( @" }" ); - code.LINE( @" else" ); - code.LINE( @" {" ); - code.LINE( @" host = self.productionUrl;" ); - code.LINE( @" }" ); - code.LINE( nil ); - code.LINE( @" if ( NO == [host hasPrefix:@\"http://\"] && NO == [host hasPrefix:@\"https://\"] )" ); - code.LINE( @" {" ); - code.LINE( @" host = [@\"http://\" stringByAppendingString:host];" ); - code.LINE( @" }" ); - code.LINE( nil ); - code.LINE( @" return host;" ); - code.LINE( @"}" ); - code.LINE( nil ); - - code.LINE( @"- (NSString *)developmentUrl" ); - code.LINE( @"{" ); - code.LINE( [NSString stringWithFormat:@" return @\"%@\";", dev ? dev : @""] ); - code.LINE( @"}" ); - code.LINE( nil ); + if (urlNames.count) { + for (int i = 0; i < urlNames.count; i ++) { + code.LINE( [NSString stringWithFormat:@"@synthesize Config%@ = _Config%@;", [urlNames safeObjectAtIndex:i], [urlNames safeObjectAtIndex:i] ] ); + code.LINE( [NSString stringWithFormat:@"@synthesize Url%@ = _Url%@;", [urlNames safeObjectAtIndex:i], [urlNames safeObjectAtIndex:i] ] ); + code.LINE( nil ); + } + } + code.LINE( @"@synthesize config;" ); + code.LINE( @"@synthesize url;" ); + code.LINE( nil ); - code.LINE( @"- (NSString *)testUrl" ); - code.LINE( @"{" ); - code.LINE( [NSString stringWithFormat:@" return @\"%@\";", tst ? tst : @""] ); - code.LINE( @"}" ); code.LINE( nil ); - code.LINE( @"- (NSString *)productionUrl" ); - code.LINE( @"{" ); - code.LINE( [NSString stringWithFormat:@" return @\"%@\";", pro ? pro : @""] ); - code.LINE( @"}" ); + if (urlNames.count) { + for (int i = 0; i < urlNames.count; i ++) { + code.LINE( [NSString stringWithFormat:@"- (NSString *)Url%@", [urlNames safeObjectAtIndex:i]] ); + code.LINE( @"{" ); + code.LINE( @" NSString * host = nil;" ); + code.LINE( nil ); + id value = [self.server objectForKey:[urlNames safeObjectAtIndex:i]]; + for (NSString *key in value) { + code.LINE( [NSString stringWithFormat:@" if ( self.CONFIG_%@_%@ == self.Config%@ )", [[urlNames safeObjectAtIndex:i] uppercaseString], [key uppercaseString], [urlNames safeObjectAtIndex:i]] ); + code.LINE( @" {" ); + code.LINE( [NSString stringWithFormat:@" host = self.%@_%@_Url;", [urlNames safeObjectAtIndex:i], key] ); + code.LINE( @" }" ); + } + code.LINE( @" if ( NO == [host hasPrefix:@\"http://\"] && NO == [host hasPrefix:@\"https://\"] )" ); + code.LINE( @" {" ); + code.LINE( @" host = [@\"http://\" stringByAppendingString:host];" ); + code.LINE( @" }" ); + code.LINE( nil ); + code.LINE( @" return host;" ); + code.LINE( @"}" ); + } + } + code.LINE( nil ); + code.LINE( @"- (NSString *)url" ); + code.LINE( @"{" ); + code.LINE( @" NSString * host = nil;" ); + code.LINE( nil ); + for (NSString *key in self.server) { + if ([[self.server objectForKey:key] isKindOfClass:[NSDictionary class]]) { + continue; + } + code.LINE( [NSString stringWithFormat:@" if ( self.CONFIG_%@ == self.config )", [key uppercaseString]] ); + code.LINE( @" {" ); + code.LINE( [NSString stringWithFormat:@" host = self.%@Url;", key] ); + code.LINE( nil ); + code.LINE( @" if ( NO == [host hasPrefix:@\"http://\"] && NO == [host hasPrefix:@\"https://\"] )" ); + code.LINE( @" {" ); + code.LINE( @" host = [@\"http://\" stringByAppendingString:host];" ); + code.LINE( @" }" ); + code.LINE( nil ); + code.LINE( @" return host;" ); + code.LINE( @" }" ); + } + code.LINE( @" return nil;" ); + code.LINE( @"}" ); + code.LINE( nil ); - + + + + NSString *url = nil; + for (NSString *key in self.server) { + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + for (NSString *key1 in value) { + url = [value objectForKey:key1]; + code.LINE( [NSString stringWithFormat:@"- (NSString *)%@_%@_Url", key, key1] ); + code.LINE( @"{" ); + code.LINE( [NSString stringWithFormat:@" return @\"%@\";", url ? url : @""] ); + code.LINE( @"}" ); + code.LINE( nil ); + } + }else + { + url = [self.server objectForKey:key]; + code.LINE( [NSString stringWithFormat:@"- (NSString *)%@Url", key] ); + code.LINE( @"{" ); + code.LINE( [NSString stringWithFormat:@" return @\"%@\";", url ? url : @""] ); + code.LINE( @"}" ); + code.LINE( nil ); + } + } + code.LINE( @"@end" ); code.LINE( nil ); }