mirror of https://github.com/axmolengine/axmol.git
Merge pull request #15112 from zilongshanren/improve-editbox-mac
improve mac editbox
This commit is contained in:
commit
8f05f33a01
|
@ -48,7 +48,6 @@
|
|||
self.keyboardReturnType = cocos2d::ui::EditBox::KeyboardReturnType::DEFAULT;
|
||||
|
||||
[self createMultiLineTextField];
|
||||
[self.window.contentView addSubview:self.textInput];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -96,7 +95,8 @@
|
|||
[_textInput performSelector:@selector(setBackgroundColor:) withObject:[NSColor clearColor]];
|
||||
|
||||
if (![_textInput isKindOfClass:[NSTextView class]]) {
|
||||
[_textInput performSelector:@selector(setBordered:) withObject:[NSNumber numberWithBool:NO]];
|
||||
[_textInput performSelector:@selector(setBordered:)
|
||||
withObject:[NSNumber numberWithBool:NO]];
|
||||
}
|
||||
_textInput.hidden = NO;
|
||||
_textInput.wantsLayer = YES;
|
||||
|
@ -116,7 +116,6 @@
|
|||
frame.size.width = rect.size.width;
|
||||
|
||||
self.textInput.frame = frame;
|
||||
[self.window makeFirstResponder:self.window.contentView];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
@ -140,6 +139,11 @@
|
|||
}else {
|
||||
[self.window makeFirstResponder:self.textInput];
|
||||
}
|
||||
|
||||
auto editbox = getEditBoxImplMac()->getEditBox();
|
||||
auto oldPos = editbox->getPosition();
|
||||
editbox->setPosition(oldPos + cocos2d::Vec2(10,20));
|
||||
editbox->setPosition(oldPos);
|
||||
}
|
||||
|
||||
- (void)closeKeyboard
|
||||
|
@ -189,30 +193,18 @@
|
|||
return self.textInput.ccui_font.fontName ?: @"";
|
||||
}
|
||||
|
||||
- (void) hackingCodeForRefreshPosition
|
||||
{
|
||||
[self.window.contentView addSubview:self.textInput];
|
||||
if (![self.textInput isKindOfClass:[NSTextView class]]) {
|
||||
[self.textInput becomeFirstResponder];
|
||||
}else {
|
||||
[self.window makeFirstResponder:self.textInput];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setInputMode:(cocos2d::ui::EditBox::InputMode)inputMode
|
||||
{
|
||||
//multiline input
|
||||
if (inputMode == cocos2d::ui::EditBox::InputMode::ANY) {
|
||||
if (![self.textInput isKindOfClass:[NSTextView class]]) {
|
||||
[self createMultiLineTextField];
|
||||
[self hackingCodeForRefreshPosition];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (self.dataInputMode != cocos2d::ui::EditBox::InputFlag::PASSWORD) {
|
||||
if (![self.textInput isKindOfClass:[NSTextField class]]) {
|
||||
[self createSingleLineTextField];
|
||||
[self hackingCodeForRefreshPosition];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ bool UIEditBoxTest::init()
|
|||
_editName->setText("v👐👊💝");
|
||||
_editName->setReturnType(ui::EditBox::KeyboardReturnType::DONE);
|
||||
_editName->setDelegate(this);
|
||||
_editName->setVisible(true);
|
||||
addChild(_editName);
|
||||
|
||||
Button* button = Button::create("cocosui/animationbuttonnormal.png",
|
||||
|
@ -89,6 +90,7 @@ bool UIEditBoxTest::init()
|
|||
_editPassword->setInputMode(ui::EditBox::InputMode::SINGLE_LINE);
|
||||
_editPassword->setFontSize(editBoxSize.height/2);
|
||||
_editPassword->setDelegate(this);
|
||||
_editPassword->setVisible(true);
|
||||
addChild(_editPassword);
|
||||
|
||||
auto buttonPassword = (ui::Button*)button->clone();
|
||||
|
@ -111,6 +113,7 @@ bool UIEditBoxTest::init()
|
|||
_editEmail->setPlaceHolder("Email:");
|
||||
_editEmail->setInputMode(ui::EditBox::InputMode::EMAIL_ADDRESS);
|
||||
_editEmail->setDelegate(this);
|
||||
_editEmail->setVisible(true);
|
||||
_editEmailParent->addChild(_editEmail);
|
||||
//It is required to use setFontSize and setContentSize after adding it to the hierarchy, so that native EditBox get the right size
|
||||
_editEmail->setFontSize(30);
|
||||
|
|
Loading…
Reference in New Issue