2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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 __UITEXTFIELD_H__
|
|
|
|
#define __UITEXTFIELD_H__
|
|
|
|
|
|
|
|
#include "ui/UIWidget.h"
|
2014-06-04 14:26:21 +08:00
|
|
|
#include "2d/CCTextFieldTTF.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* @brief A helper class which inherit from @see `TextFieldTTF` and implements the @see `TextFieldDelegate` protocol.
|
|
|
|
* It is mainly be used internally by @see `UITextField` class.
|
2015-03-30 21:38:32 +08:00
|
|
|
* @js NA
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL UICCTextField: public TextFieldTTF, public TextFieldDelegate
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2017-11-28 16:42:14 +08:00
|
|
|
/**
|
|
|
|
* @brief Create an empty UICCTextField.
|
|
|
|
*
|
|
|
|
* @return A UICCTextField instance.
|
|
|
|
*/
|
|
|
|
static UICCTextField* create();
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
UICCTextField();
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
~UICCTextField();
|
|
|
|
|
|
|
|
virtual void onEnter() override;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
2015-10-23 15:37:33 +08:00
|
|
|
* Create a UICCTextField instance with a placeholder, a fontName and a fontSize.
|
2015-03-25 18:17:58 +08:00
|
|
|
*@param placeholder Placeholder in string.
|
|
|
|
*@param fontName Font name in string.
|
|
|
|
*@param fontSize Font size in float.
|
|
|
|
*@return A UICCTextField instance.
|
|
|
|
*/
|
|
|
|
static UICCTextField* create(const std::string& placeholder,
|
|
|
|
const std::string& fontName,
|
|
|
|
float fontSize);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
//override functions
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual bool onTextFieldAttachWithIME(TextFieldTTF *pSender) override;
|
|
|
|
virtual bool onTextFieldDetachWithIME(TextFieldTTF * pSender) override;
|
2015-03-25 18:17:58 +08:00
|
|
|
virtual bool onTextFieldInsertText(TextFieldTTF * pSender,
|
|
|
|
const char * text,
|
|
|
|
size_t nLen) override;
|
|
|
|
virtual bool onTextFieldDeleteBackward(TextFieldTTF * pSender,
|
|
|
|
const char * delText,
|
|
|
|
size_t nLen) override;
|
2015-03-15 02:33:15 +08:00
|
|
|
void insertText(const char* text, size_t len) override;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Open up the IME.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void openIME();
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the IME.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void closeIME();
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Toggle enable max length limitation.
|
|
|
|
*@param enable True to enable max length, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setMaxLengthEnabled(bool enable);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query max length enable state.
|
|
|
|
*@return Whether max length is enabled or not.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool isMaxLengthEnabled()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
2015-10-23 15:37:33 +08:00
|
|
|
* Set maximize length.
|
|
|
|
*@param length The maximize length in integer.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setMaxLength(int length);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get maximize length.
|
|
|
|
*@return Maximize length.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
int getMaxLength()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
2015-10-23 15:37:33 +08:00
|
|
|
* Return the total inputed characters.
|
2015-03-25 18:17:58 +08:00
|
|
|
*@return Total inputed character count.
|
|
|
|
*/
|
2016-04-01 09:31:18 +08:00
|
|
|
std::size_t getCharCount()const;
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle password input mode.
|
|
|
|
*
|
|
|
|
* @param enable True if enable password input, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setPasswordEnabled(bool enable);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether password input mode is enabled or not.
|
|
|
|
*
|
|
|
|
* @return True if password input is enabled, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool isPasswordEnabled()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change password style text.
|
|
|
|
*
|
|
|
|
* @param styleText The styleText for password mask, the default value is "*".
|
|
|
|
*/
|
2014-05-12 14:59:00 +08:00
|
|
|
void setPasswordStyleText(const std::string& styleText);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the password text content.
|
|
|
|
*
|
|
|
|
* @param text The content of password.
|
|
|
|
*/
|
2014-05-12 14:59:00 +08:00
|
|
|
void setPasswordText(const std::string& text);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Toggle attach with IME.
|
|
|
|
*
|
|
|
|
* @param attach True if attach with IME, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setAttachWithIME(bool attach);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether the IME is attached or not.
|
|
|
|
*
|
|
|
|
* @return True if IME is attached, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool getAttachWithIME()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle detach with IME.
|
|
|
|
*
|
|
|
|
* @param detach True if detach with IME, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setDetachWithIME(bool detach);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether IME is detached or not.
|
|
|
|
*
|
|
|
|
* @return True if IME is detached, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool getDetachWithIME()const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Toggle enable text insert.
|
|
|
|
*
|
|
|
|
* @param insert True if enable insert text, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setInsertText(bool insert);
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Query whether insert text is enabled or not.
|
|
|
|
*
|
|
|
|
* @return True if insert text is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
bool getInsertText()const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle enable delete backward.
|
|
|
|
*
|
|
|
|
* @param deleteBackward True if enable delete backward, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setDeleteBackward(bool deleteBackward);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether delete backward is enabled or not.
|
|
|
|
*
|
|
|
|
* @return True if delete backward is enabled, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool getDeleteBackward()const;
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
bool _maxLengthEnabled;
|
|
|
|
int _maxLength;
|
|
|
|
bool _attachWithIME;
|
|
|
|
bool _detachWithIME;
|
|
|
|
bool _insertText;
|
|
|
|
bool _deleteBackward;
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* TextField event type.
|
|
|
|
* @deprecated Use @see `TextField::EventType` instead.
|
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef enum
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
TEXTFIELD_EVENT_ATTACH_WITH_IME,
|
|
|
|
TEXTFIELD_EVENT_DETACH_WITH_IME,
|
|
|
|
TEXTFIELD_EVENT_INSERT_TEXT,
|
|
|
|
TEXTFIELD_EVENT_DELETE_BACKWARD,
|
|
|
|
}TextFiledEventType;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* A callback which would be called when a TextField event happens.
|
|
|
|
* @deprecated Use @see `ccTextFieldCallback` instead.
|
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef void (Ref::*SEL_TextFieldEvent)(Ref*, TextFiledEventType);
|
2014-03-11 17:13:54 +08:00
|
|
|
#define textfieldeventselector(_SELECTOR) (SEL_TextFieldEvent)(&_SELECTOR)
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief A widget which allows users to input text.
|
|
|
|
* The rendering of the input text are based on @see `TextFieldTTF'.
|
|
|
|
* If you want to use system control behavior, please use @see `EditBox` instead.
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_GUI_DLL TextField : public Widget
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
DECLARE_CLASS_GUI_INFO
|
|
|
|
|
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* TextField event type.
|
|
|
|
*/
|
2014-05-12 11:29:22 +08:00
|
|
|
enum class EventType
|
|
|
|
{
|
|
|
|
ATTACH_WITH_IME,
|
|
|
|
DETACH_WITH_IME,
|
|
|
|
INSERT_TEXT,
|
|
|
|
DELETE_BACKWARD,
|
|
|
|
};
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* A callback which would be called when a TextField event happens.
|
|
|
|
*/
|
2014-05-12 11:29:22 +08:00
|
|
|
typedef std::function<void(Ref*, EventType)> ccTextFieldCallback;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default constructor.
|
|
|
|
*
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
TextField();
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default destructor.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual ~TextField();
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create an empty TextField.
|
|
|
|
*
|
|
|
|
* @return A TextField instance.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
static TextField* create();
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a TextField with a placeholder, a font name and a font size.
|
|
|
|
*
|
|
|
|
* @param placeholder The placeholder string.
|
|
|
|
* @param fontName The font name.
|
|
|
|
* @param fontSize The font size.
|
|
|
|
* @return A TextField instance.
|
|
|
|
*/
|
2014-04-02 18:35:08 +08:00
|
|
|
static TextField* create(const std::string& placeholder,
|
|
|
|
const std::string& fontName,
|
|
|
|
int fontSize);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the touch size
|
|
|
|
* The touch size is used for @see `hitTest`.
|
|
|
|
* @param size A delimitation zone.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setTouchSize(const Size &size);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get current touch size of TextField.
|
|
|
|
*
|
|
|
|
* @return The TextField's touch size.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
Size getTouchSize()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle enable touch area.
|
|
|
|
*
|
|
|
|
* @param enable True if enable touch area, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setTouchAreaEnabled(bool enable);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
2015-06-18 10:23:52 +08:00
|
|
|
virtual bool hitTest(const Vec2 &pt, const Camera* camera, Vec3 *p) const override;
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set placeholder of TextField.
|
|
|
|
*
|
|
|
|
* @param value The string value of placeholder.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setPlaceHolder(const std::string& value);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the placeholder of TextField.
|
|
|
|
*
|
|
|
|
* @return A placeholder string.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
const std::string& getPlaceHolder()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query the placeholder string color.
|
|
|
|
*
|
|
|
|
* @return The color of placeholder.
|
|
|
|
*/
|
2014-08-13 11:28:37 +08:00
|
|
|
const Color4B& getPlaceHolderColor()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change the placeholder color.
|
|
|
|
*
|
|
|
|
* @param color A color value in `Color3B`.
|
|
|
|
*/
|
2014-08-13 11:28:37 +08:00
|
|
|
void setPlaceHolderColor(const Color3B& color);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change the placeholder color.
|
|
|
|
*
|
|
|
|
* @param color A color value in `Color4B`.
|
|
|
|
*/
|
2014-08-13 11:28:37 +08:00
|
|
|
void setPlaceHolderColor(const Color4B& color);
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-05-26 03:05:49 +08:00
|
|
|
/**
|
|
|
|
* @brief Query the text string color.
|
|
|
|
*
|
|
|
|
* @return The color of the text.
|
|
|
|
*/
|
|
|
|
const Color4B& getTextColor()const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Change the text color.
|
|
|
|
*
|
|
|
|
* @param textColor The color value in `Color4B`.
|
|
|
|
*/
|
|
|
|
void setTextColor(const Color4B& textColor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change font size of TextField.
|
|
|
|
*
|
|
|
|
* @param size The integer font size.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setFontSize(int size);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query the font size.
|
|
|
|
*
|
|
|
|
* @return The integer font size.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
int getFontSize()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change the font name of TextField.
|
|
|
|
*
|
|
|
|
* @param name The font name string.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setFontName(const std::string& name);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query the TextField's font name.
|
|
|
|
*
|
|
|
|
* @return The font name string.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
const std::string& getFontName()const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Detach the IME.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void didNotSelectSelf();
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*Change content of TextField.
|
|
|
|
*@deprecated Use @see `setString(const std::string&)` instead.
|
|
|
|
*@param text A string content.
|
|
|
|
*/
|
2014-09-09 13:59:35 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void setText(const std::string& text){this->setString(text);}
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*Query the content of TextField.
|
|
|
|
*@deprecated Use @see `getString` instead.
|
|
|
|
*@return The string value of TextField.
|
|
|
|
*/
|
2014-09-09 13:59:35 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue()const{return this->getString();}
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*Change content of TextField.
|
|
|
|
*@param text A string content.
|
|
|
|
*/
|
2014-09-09 13:59:35 +08:00
|
|
|
void setString(const std::string& text);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*Query the content of TextField.
|
|
|
|
*@return The string value of TextField.
|
|
|
|
*/
|
2014-09-09 13:59:35 +08:00
|
|
|
const std::string& getString()const;
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual bool onTouchBegan(Touch *touch, Event *unusedEvent) override;
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle maximize length enable
|
|
|
|
*
|
|
|
|
* @param enable True if enable maximize length, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setMaxLengthEnabled(bool enable);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether max length is enabled or not.
|
|
|
|
*
|
|
|
|
* @return True if maximize length is enabled, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool isMaxLengthEnabled()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change maximize input length limitation.
|
|
|
|
*
|
|
|
|
* @param length A character count in integer.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setMaxLength(int length);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query maximize input length of TextField.
|
|
|
|
*
|
|
|
|
* @return The integer value of maximize input length.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
int getMaxLength()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query the input string length.
|
|
|
|
*
|
|
|
|
* @return A integer length value.
|
|
|
|
*/
|
2014-06-06 17:06:55 +08:00
|
|
|
int getStringLength() const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle enable password input mode.
|
|
|
|
*
|
|
|
|
* @param enable True if enable password input mode, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setPasswordEnabled(bool enable);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether password is enabled or not.
|
|
|
|
*
|
|
|
|
* @return True if password is enabled, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool isPasswordEnabled()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change password style text.
|
|
|
|
*
|
|
|
|
* @param styleText The styleText for password mask, the default value is "*".
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setPasswordStyleText(const char* styleText);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query the password style text.
|
|
|
|
*
|
|
|
|
* @return A password style text.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
const char* getPasswordStyleText()const;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void update(float dt) override;
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Query whether the IME is attached or not.
|
|
|
|
*
|
|
|
|
* @return True if IME is attached, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool getAttachWithIME()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle attach with IME.
|
|
|
|
*
|
|
|
|
* @param attach True if attach with IME, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setAttachWithIME(bool attach);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query whether IME is detached or not.
|
|
|
|
*
|
|
|
|
* @return True if IME is detached, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool getDetachWithIME()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle detach with IME.
|
|
|
|
*
|
|
|
|
* @param detach True if detach with IME, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setDetachWithIME(bool detach);
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Whether it is ready to get the inserted text or not.
|
|
|
|
*
|
|
|
|
* @return True if the insert text is ready, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool getInsertText()const;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Toggle enable insert text mode
|
|
|
|
*
|
|
|
|
* @param insertText True if enable insert text, false otherwise.
|
|
|
|
*/
|
|
|
|
void setInsertText(bool insertText);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Whether it is ready to delete backward in TextField.
|
|
|
|
*
|
|
|
|
* @return True is the delete backward is enabled, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:03:38 +08:00
|
|
|
bool getDeleteBackward()const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Toggle enable delete backward mode.
|
|
|
|
*
|
|
|
|
* @param deleteBackward True is delete backward is enabled, false otherwise.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setDeleteBackward(bool deleteBackward);
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Add a event listener to TextField, when some predefined event happens, the callback will be called.
|
|
|
|
*@deprecated Use @see `addEventListener` instead.
|
|
|
|
*@param target A pointer of `Ref*` type.
|
2016-06-29 10:04:11 +08:00
|
|
|
*@param selector A member function pointer with type of `SEL_TextFieldEvent`.
|
2015-03-25 18:17:58 +08:00
|
|
|
*/
|
2016-06-29 10:04:11 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void addEventListenerTextField(Ref* target, SEL_TextFieldEvent selector);
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Add a event listener to TextField, when some predefined event happens, the callback will be called.
|
|
|
|
*@param callback A callback function with type of `ccTextFieldCallback`.
|
|
|
|
*/
|
2014-05-14 16:14:28 +08:00
|
|
|
void addEventListener(const ccTextFieldCallback& callback);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the "class name" of widget.
|
|
|
|
*/
|
|
|
|
virtual std::string getDescription() const override;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
2015-11-04 16:09:58 +08:00
|
|
|
* @brief Get the renderer size in auto mode.
|
2015-03-25 18:17:58 +08:00
|
|
|
*
|
|
|
|
* @return A delimitation zone.
|
|
|
|
*/
|
2015-01-20 18:40:25 +08:00
|
|
|
virtual Size getAutoRenderSize();
|
2015-10-23 15:37:33 +08:00
|
|
|
//override functions.
|
2014-09-12 14:39:22 +08:00
|
|
|
virtual Size getVirtualRendererSize() const override;
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Node* getVirtualRenderer() override;
|
|
|
|
virtual void onEnter() override;
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @brief Attach the IME for inputing.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void attachWithIME();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change the text area size.
|
|
|
|
*
|
|
|
|
* @param size A delimitation zone.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setTextAreaSize(const Size &size);
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change horizontal text alignment.
|
|
|
|
*
|
|
|
|
* @param alignment A alignment arguments in @see `TextHAlignment`.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setTextHorizontalAlignment(TextHAlignment alignment);
|
2015-05-26 15:33:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Inquire the horizontal alignment
|
|
|
|
*
|
|
|
|
* @return The horizontal alignment
|
|
|
|
*/
|
2015-05-26 18:55:57 +08:00
|
|
|
TextHAlignment getTextHorizontalAlignment() const;
|
2015-03-25 18:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change the vertical text alignment.
|
|
|
|
*
|
|
|
|
* @param alignment A alignment arguments in @see `TextVAlignment`.
|
|
|
|
*/
|
2014-03-11 17:13:54 +08:00
|
|
|
void setTextVerticalAlignment(TextVAlignment alignment);
|
2015-05-26 15:33:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Inquire the horizontal alignment
|
|
|
|
*
|
|
|
|
* @return The horizontal alignment
|
|
|
|
*/
|
2015-05-26 18:55:57 +08:00
|
|
|
TextVAlignment getTextVerticalAlignment() const;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2016-03-14 23:09:04 +08:00
|
|
|
/**
|
|
|
|
* Set enable cursor use.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setCursorEnabled(bool enabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set char showing cursor.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setCursorChar(char cursor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set cursor position, if enabled
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setCursorPosition(std::size_t cursorPosition);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set cursor position to hit letter, if enabled
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
void setCursorFromPoint(const Vec2 &point, const Camera* camera);
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual bool init() override;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
protected:
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual void initRenderer() override;
|
|
|
|
void attachWithIMEEvent();
|
|
|
|
void detachWithIMEEvent();
|
|
|
|
void insertTextEvent();
|
|
|
|
void deleteBackwardEvent();
|
|
|
|
virtual void onSizeChanged() override;
|
2014-06-06 16:10:33 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
void textfieldRendererScaleChangedWithSize();
|
2014-05-27 11:03:38 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
2014-04-17 14:08:25 +08:00
|
|
|
virtual void adaptRenderers() override;
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
|
|
|
UICCTextField* _textFieldRenderer;
|
|
|
|
|
|
|
|
float _touchWidth;
|
|
|
|
float _touchHeight;
|
|
|
|
bool _useTouchArea;
|
|
|
|
|
|
|
|
Ref* _textFieldEventListener;
|
2014-05-12 11:29:22 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
2014-03-11 17:13:54 +08:00
|
|
|
SEL_TextFieldEvent _textFieldEventSelector;
|
2014-05-12 11:29:22 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|
|
|
|
ccTextFieldCallback _eventCallback;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2014-04-17 14:08:25 +08:00
|
|
|
bool _textFieldRendererAdaptDirty;
|
2014-06-28 23:37:29 +08:00
|
|
|
private:
|
|
|
|
enum class FontType
|
|
|
|
{
|
|
|
|
SYSTEM,
|
2017-12-29 11:24:02 +08:00
|
|
|
TTF,
|
|
|
|
BMFONT
|
2014-06-28 23:37:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string _fontName;
|
|
|
|
int _fontSize;
|
|
|
|
FontType _fontType;
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2014-03-11 17:13:54 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* defined(__TextField__) */
|