Skip to content

Commit 820c6c1

Browse files
committed
better padding for TextFields on android
1 parent b1f36b0 commit 820c6c1

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

cocos2d-tests-android/Headless/tests/CCTextFieldTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ - (void) setupTextFieldBasicTest
3434
textField.preferredSize = CGSizeMake(0.5, 50);
3535
textField.positionType = CCPositionTypeNormalized;
3636
textField.position = ccp(0.5f, 0.8f);
37-
textField.padding = 6;
37+
textField.padding = 10;
3838
textField.anchorPoint = ccp(0.5f, 0.5f);
3939
textField.string = @"Hello!";
4040

cocos2d-ui/Platform/Android/CCPlatformTextFieldAndroid.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#import "CCDirector.h"
1515
#import "CCEditText.h"
1616

17-
17+
1818
@implementation CCPlatformTextFieldAndroid {
1919
CCEditText *_editText;
2020
}
@@ -50,29 +50,28 @@ - (void) onExitTransitionDidStart
5050
- (void) positionInControl:(CCControl *)control padding:(float)padding {
5151
CGPoint worldPos = [control convertToWorldSpace:CGPointZero];
5252
CGPoint viewPos = [[CCDirector sharedDirector] convertToUI:worldPos];
53-
viewPos.x += padding;
54-
// viewPos.y += padding;
53+
5554

5655
CGFloat scale = [[CCDirector sharedDirector] contentScaleFactor];
5756

5857
viewPos.x *= scale;
5958
viewPos.y *= scale;
6059

6160
CGSize size = control.contentSizeInPoints;
62-
size.width -= padding * 2;
63-
size.height -= padding * 2;
6461
size.width *= scale;
6562
size.height *= scale ;
66-
viewPos.y -= size.height + padding *scale;
67-
63+
viewPos.y -= size.height;
64+
6865

6966
CGRect frame = CGRectZero;
7067
frame.origin = viewPos;
7168
frame.size = size;
69+
int nativePadding = (int)padding*scale;
7270
dispatch_async(dispatch_get_main_queue(), ^{
7371
AndroidViewGroupLayoutParams *oldParams = [_editText layoutParams];
7472
AndroidRelativeLayoutLayoutParams *params = [[AndroidRelativeLayoutLayoutParams alloc] initWithWidth:frame.size.width height:frame.size.height];
7573
[params setMargins:frame.origin.x top:frame.origin.y right:0 bottom:0];
74+
[_editText setPadding:nativePadding top:nativePadding right:nativePadding bottom:nativePadding];
7675
[_editText setLayoutParams:params];
7776
[_editText setImeOptions:AndroidEditorInfoIME_FLAG_NO_EXTRACT_UI];
7877

@@ -82,7 +81,7 @@ - (void) positionInControl:(CCControl *)control padding:(float)padding {
8281
if ([[weakSelf delegate] respondsToSelector:@selector(platformTextFieldDidFinishEditing:)]) {
8382
[[weakSelf delegate] platformTextFieldDidFinishEditing:weakSelf];
8483
}
85-
84+
8685
}];
8786
});
8887
}
@@ -106,12 +105,12 @@ - (void)setFontSize:(float)fontSize {
106105
dispatch_async(dispatch_get_main_queue(), ^{
107106
// AndroidDisplayMetrics *metrics = [[AndroidDisplayMetrics alloc] init];
108107
// [[CCActivity currentActivity].windowManager.defaultDisplay getMetrics:metrics];
109-
108+
110109
[_editText setTextSizeDouble:fontSize];
111-
110+
112111
});
113-
114-
112+
113+
115114
}
116115

117116
- (void)setString:(NSString *)string {

0 commit comments

Comments
 (0)