diff options
author | Ptyl Dragon <ptyl@cloudon.com> | 2013-11-01 12:48:31 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2013-11-15 16:52:00 +0100 |
commit | 5c6aa9ae862d2483355613b8c2e3e33d61140068 (patch) | |
tree | edc4e764d86e1514dbe25fc7ad96206b4e5ba8da /ios | |
parent | Handle also FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA (diff) | |
download | core-5c6aa9ae862d2483355613b8c2e3e33d61140068.tar.gz core-5c6aa9ae862d2483355613b8c2e3e33d61140068.zip |
tiledrendering new stepper ui for tor
Change-Id: I3d4586c84adfa9f0416a043230c6227bda98d9dd
Diffstat (limited to 'ios')
3 files changed, 105 insertions, 19 deletions
diff --git a/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m b/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m index f286390caf34..22d98fa0a47e 100644 --- a/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m +++ b/ios/shared/ios_sharedlo/objective_c/view_controllers/MLOTestingTileParameter.m @@ -14,9 +14,14 @@ @property (nonatomic,strong) MLOTestingTileParameterExtractor extractor; @property UILabel * label; @property UITextField * data; +@property UITextField * step; @property NSInteger defaultValue; +@property UIStepper * dataStepper; +@property UIStepper * stepStepper; @end +static const CGFloat DEFAULT_STEP_VALUE = 1; + @implementation MLOTestingTileParameter -(MLOTestingTileParameter *)initWithParams:(MLOTestingTileParametersViewController *) params label:(NSString *)label extractor:(MLOTestingTileParameterExtractor) extractor defaultValue:(NSInteger) defaultValue{ @@ -26,13 +31,59 @@ self.params = params; self.extractor = extractor; self.defaultValue = defaultValue; - [self initLabel:label]; - [self initTextField]; + self.dataStepper = [self createStepper]; + self.stepStepper = [self createStepper]; + [self initDataTextField]; + [self initStepTextField]; } return self; } +-(UIStepper *) createStepper{ + UIStepper * stepper = [UIStepper new]; + stepper.maximumValue = MAXFLOAT; + stepper.minimumValue = -MAXFLOAT; + stepper.stepValue = DEFAULT_STEP_VALUE; + stepper.autorepeat = YES; + stepper.continuous = NO; + [stepper addObserver:self forKeyPath:@"value" + options: NSKeyValueObservingOptionNew + context:0]; + return stepper; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + + if (object == self.dataStepper) { + NSNumber * floatNumber = change[NSKeyValueChangeNewKey]; + CGFloat value = [self currentDataValue] + [floatNumber floatValue]; + + if(value == ((NSInteger) value)){ + self.data.text = [[NSNumber numberWithInteger:(NSInteger) value] stringValue]; + }else{ + self.data.text = [[NSNumber numberWithFloat:value] stringValue]; + } + [self.params renderTile]; + }else if (object == self.stepStepper){ + + NSNumber * floatNumber = change[NSKeyValueChangeNewKey]; + NSInteger value = [floatNumber integerValue]; + NSNumber * newValue = [NSNumber numberWithInteger:value]; + self.step.text = [newValue stringValue]; + self.dataStepper.stepValue = [newValue floatValue]; + } +} + + +-(void)initStepTextField{ + + self.step =[[UITextField alloc] initWithFrame:CGRECT_ZERO]; + self.data.textAlignment = NSTextAlignmentLeft; + self.step.text = [[NSNumber numberWithInteger:(NSInteger)DEFAULT_STEP_VALUE] stringValue]; +} + -(NSString *)description{ return [@"MLOTestingTileParameter: " stringByAppendingString:self.label.text]; } @@ -40,10 +91,10 @@ -(void) initLabel:(NSString *) label{ self.label =[[UILabel alloc] initWithFrame:CGRECT_ZERO]; self.label.text = label; - self.label.textAlignment = NSTextAlignmentRight; + self.label.textAlignment = NSTextAlignmentCenter; } --(void) initTextField{ +-(void) initDataTextField{ self.data = [[UITextField alloc] initWithFrame:CGRECT_ZERO]; [self.data setKeyboardType:UIKeyboardTypeNumberPad]; self.data.textAlignment = NSTextAlignmentLeft; @@ -58,31 +109,65 @@ -(void)setParamFrame:(CGRect) paramFrame{ NSLog(@"%@ setParamFrame",self); - self.label.frame=CGRectMake(paramFrame.origin.x, - paramFrame.origin.y, - paramFrame.size.width/2.0f, - paramFrame.size.height); - self.data.frame =CGRectMake(paramFrame.origin.x + paramFrame.size.width/2.0f, - paramFrame.origin.y, - paramFrame.size.width/2.0f, - paramFrame.size.height); + CGFloat x = paramFrame.origin.x; + CGFloat y = paramFrame.origin.y; + CGFloat w = paramFrame.size.width; + CGFloat h = paramFrame.size.height; + + CGFloat labelW = w/3.0f; + CGFloat otherW = w/6.0f; + + self.label.frame=CGRectMake(x, + y, + labelW, + h); + self.data.frame =CGRectMake(x + labelW, + y, + otherW, + h); + self.dataStepper.frame = CGRectMake(x + labelW + otherW, + y, + otherW, + h); + + self.step.frame = CGRectMake(x + labelW + 2*otherW, + y, + otherW, + h); + self.stepStepper.frame = CGRectMake(x + labelW + 3*otherW, + y, + otherW, + h); + } -(void)addToSuperview{ NSLog(@"%@ addToSuperview",self); [self.params.view addSubview:self.label]; [self.params.view addSubview:self.data]; + [self.params.view addSubview:self.dataStepper]; + [self.params.view addSubview:self.step]; + [self.params.view addSubview:self.stepStepper]; } --(void)extract{ - NSLog(@"%@ extract",self); +-(BOOL)isNumber:(NSString *) string{ + + return [[NSNumberFormatter new]numberFromString:string] == nil; +} - if([[NSNumberFormatter new]numberFromString:self.data.text] == nil){ +-(CGFloat) currentDataValue{ + if([self isNumber:self.data.text]){ NSLog(@"%@ got illegal value: %@, reseting to %d",self,self.data.text,self.defaultValue); [self resetValue]; } - self.extractor([self.data.text floatValue]); + return [self.data.text floatValue]; +} + +-(void)extract{ + NSLog(@"%@ extract",self); + + self.extractor([self currentDataValue]); } @end diff --git a/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.h b/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.h index 57060b7584f3..47c6a6e66954 100644 --- a/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.h +++ b/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.h @@ -11,4 +11,5 @@ @interface MLOTestingTileParametersViewController : MLOViewController<MLOTestingTileSubviewControllerProtocol> @property CGFloat contextWidth, contextHeight, tilePosX, tilePosY, tileWidth, tileHeight; +-(void)renderTile; @end diff --git a/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m b/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m index acd00c179929..4feee1ef6474 100644 --- a/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m +++ b/ios/shared/ios_sharedlo/objective_c/view_controllers/testing_tiles/MLOTestingTileParametersViewController.m @@ -41,10 +41,10 @@ static const CGFloat RENDER_BUTTON_HEIGHT = 50.0f; -(void)initParams{ self.params = @[[self createParam:@"contextWidth" extractor:^(CGFloat value){self.contextWidth = value;} value:600], [self createParam:@"contextHeight" extractor:^(CGFloat value){self.contextHeight = value;} value:600], - [self createParam:@"tilePosX" extractor:^(CGFloat value){self.tilePosX = value;} value:600], - [self createParam:@"tilePosY" extractor:^(CGFloat value){self.tilePosY = value;} value:600], + [self createParam:@"tilePosX" extractor:^(CGFloat value){self.tilePosX = value;} value:500], + [self createParam:@"tilePosY" extractor:^(CGFloat value){self.tilePosY = value;} value:620], [self createParam:@"tileWidth" extractor:^(CGFloat value){self.tileWidth = value;} value:1000], - [self createParam:@"tileHeight" extractor:^(CGFloat value){self.tileHeight = value;} value:1000] + [self createParam:@"tileHeight" extractor:^(CGFloat value){self.tileHeight = value;} value:1020] ]; } |