2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2012 James Chen
|
|
|
|
Copyright (c) 2013-2015 zilongshanren
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UIEditBoxIMPLICOMMON_H__
|
|
|
|
#define __UIEditBoxIMPLICOMMON_H__
|
|
|
|
|
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
#include "2d/CCLabel.h"
|
|
|
|
#include "ui/UIEditBox/UIEditBoxImpl-common.h"
|
|
|
|
#include "ui/UIEditBox/UIEditBoxImpl.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
class EditBox;
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_GUI_DLL EditBoxImplCommon : public EditBoxImpl
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
EditBoxImplCommon(EditBox* pEditText);
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~EditBoxImplCommon();
|
|
|
|
|
|
|
|
virtual bool initWithSize(const Size& size) override;
|
|
|
|
|
|
|
|
virtual void setFont(const char* pFontName, int fontSize) override;
|
|
|
|
virtual void setFontColor(const Color4B& color) override;
|
|
|
|
virtual void setPlaceholderFont(const char* pFontName, int fontSize) override;
|
|
|
|
virtual void setPlaceholderFontColor(const Color4B& color) override;
|
|
|
|
virtual void setInputMode(EditBox::InputMode inputMode) override;
|
|
|
|
virtual void setInputFlag(EditBox::InputFlag inputFlag) override;
|
|
|
|
virtual void setReturnType(EditBox::KeyboardReturnType returnType) override;
|
|
|
|
virtual void setText(const char* pText) override;
|
|
|
|
virtual void setPlaceHolder(const char* pText) override;
|
|
|
|
virtual void setVisible(bool visible) override;
|
|
|
|
|
|
|
|
virtual void setMaxLength(int maxLength) override;
|
|
|
|
virtual void setTextHorizontalAlignment(TextHAlignment alignment) override;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual int getMaxLength() override { return _maxLength; }
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual const char* getText() override { return _text.c_str(); }
|
|
|
|
virtual const char* getPlaceHolder() override { return _placeHolder.c_str(); }
|
|
|
|
|
|
|
|
virtual const char* getFontName() override { return _fontName.c_str(); }
|
|
|
|
virtual int getFontSize() override { return _fontSize; }
|
|
|
|
virtual const Color4B& getFontColor() override { return _colText; }
|
|
|
|
|
|
|
|
virtual const char* getPlaceholderFontName() override { return _placeholderFontName.c_str(); }
|
|
|
|
virtual int getPlaceholderFontSize() override { return _placeholderFontSize; }
|
|
|
|
virtual const Color4B& getPlaceholderFontColor() override { return _colPlaceHolder; }
|
|
|
|
|
|
|
|
virtual EditBox::InputMode getInputMode() override { return _editBoxInputMode; }
|
|
|
|
virtual EditBox::InputFlag getInputFlag() override { return _editBoxInputFlag; }
|
|
|
|
virtual EditBox::KeyboardReturnType getReturnType() override { return _keyboardReturnType; }
|
|
|
|
virtual TextHAlignment getTextHorizontalAlignment() override { return _alignment; }
|
|
|
|
|
|
|
|
virtual void refreshInactiveText();
|
|
|
|
|
|
|
|
virtual void setContentSize(const Size& size) override;
|
|
|
|
|
|
|
|
virtual void setAnchorPoint(const Vec2& anchorPoint) override {}
|
|
|
|
virtual void setPosition(const Vec2& pos) override {}
|
2021-04-22 22:01:47 +08:00
|
|
|
virtual void setGlobalZOrder(float globalZOrder) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void draw(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void openKeyboard() override;
|
|
|
|
virtual void closeKeyboard() override;
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
virtual void onEndEditing(std::string_view text);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
void editBoxEditingDidBegin();
|
2021-12-31 12:12:40 +08:00
|
|
|
void editBoxEditingChanged(std::string_view text);
|
|
|
|
void editBoxEditingDidEnd(std::string_view text,
|
2021-12-25 10:04:45 +08:00
|
|
|
EditBoxDelegate::EditBoxEndAction action = EditBoxDelegate::EditBoxEndAction::UNKNOWN);
|
|
|
|
|
|
|
|
virtual bool isEditing() override = 0;
|
|
|
|
virtual void createNativeControl(const Rect& frame) = 0;
|
|
|
|
virtual void setNativeFont(const char* pFontName, int fontSize) = 0;
|
|
|
|
virtual void setNativeFontColor(const Color4B& color) = 0;
|
|
|
|
virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) = 0;
|
|
|
|
virtual void setNativePlaceholderFontColor(const Color4B& color) = 0;
|
|
|
|
virtual void setNativeInputMode(EditBox::InputMode inputMode) = 0;
|
|
|
|
virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) = 0;
|
|
|
|
virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType) = 0;
|
2022-08-08 18:02:17 +08:00
|
|
|
virtual void setNativeTextHorizontalAlignment(ax::TextHAlignment alignment) = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void setNativeText(const char* pText) = 0;
|
|
|
|
virtual void setNativePlaceHolder(const char* pText) = 0;
|
|
|
|
virtual void setNativeVisible(bool visible) = 0;
|
|
|
|
virtual void updateNativeFrame(const Rect& rect) = 0;
|
|
|
|
virtual const char* getNativeDefaultFontName() = 0;
|
|
|
|
virtual void nativeOpenKeyboard() = 0;
|
|
|
|
virtual void nativeCloseKeyboard() = 0;
|
|
|
|
virtual void setNativeMaxLength(int maxLength){};
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
void initInactiveLabels(const Size& size);
|
|
|
|
void setInactiveText(const char* pText);
|
|
|
|
void refreshLabelAlignment();
|
|
|
|
void placeInactiveLabels(const Size& size);
|
|
|
|
virtual void doAnimationWhenKeyboardMove(float duration, float distance) override{};
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Label* _label;
|
|
|
|
Label* _labelPlaceHolder;
|
2021-12-25 10:04:45 +08:00
|
|
|
EditBox::InputMode _editBoxInputMode;
|
|
|
|
EditBox::InputFlag _editBoxInputFlag;
|
|
|
|
EditBox::KeyboardReturnType _keyboardReturnType;
|
2019-11-23 20:27:39 +08:00
|
|
|
TextHAlignment _alignment;
|
|
|
|
|
|
|
|
std::string _text;
|
|
|
|
std::string _placeHolder;
|
|
|
|
|
|
|
|
std::string _fontName;
|
|
|
|
std::string _placeholderFontName;
|
|
|
|
|
|
|
|
int _fontSize;
|
|
|
|
int _placeholderFontSize;
|
|
|
|
|
|
|
|
Color4B _colText;
|
|
|
|
Color4B _colPlaceHolder;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int _maxLength;
|
2019-11-23 20:27:39 +08:00
|
|
|
Size _contentSize;
|
|
|
|
bool _editingMode;
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif /* __UIEditBoxIMPLICOMMON_H__ */
|