2020-08-04 12:31:33 +08:00
|
|
|
#ifndef __GTEXTFIELD_H__
|
|
|
|
#define __GTEXTFIELD_H__
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "FairyGUIMacros.h"
|
|
|
|
#include "GObject.h"
|
|
|
|
#include "display/FUILabel.h"
|
|
|
|
|
|
|
|
NS_FGUI_BEGIN
|
|
|
|
|
|
|
|
class GTextField : public GObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GTextField();
|
|
|
|
virtual ~GTextField();
|
|
|
|
|
|
|
|
virtual const std::string& getText() const override { return _text; }
|
|
|
|
void setText(const std::string& value) override;
|
|
|
|
|
|
|
|
bool isUBBEnabled() const { return _ubbEnabled; }
|
|
|
|
virtual void setUBBEnabled(bool value);
|
|
|
|
|
|
|
|
AutoSizeType getAutoSize() const { return _autoSize; }
|
|
|
|
virtual void setAutoSize(AutoSizeType value) {};
|
|
|
|
|
|
|
|
virtual bool isSingleLine() const { return false; }
|
|
|
|
virtual void setSingleLine(bool value) {};
|
|
|
|
|
|
|
|
virtual TextFormat* getTextFormat() const = 0;
|
|
|
|
virtual void applyTextFormat() = 0;
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
virtual const ax::Size& getTextSize() { return _displayObject->getContentSize(); }
|
2020-08-04 12:31:33 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Color3B getColor() const { return getTextFormat()->color; }
|
|
|
|
void setColor(const ax::Color3B& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
float getFontSize() const { return getTextFormat()->fontSize; }
|
|
|
|
void setFontSize(float value);
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Color3B getOutlineColor() const { return getTextFormat()->outlineColor; }
|
|
|
|
void setOutlineColor(const ax::Color3B& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::ValueMap* getTemplateVars() { return _templateVars; }
|
|
|
|
void setTemplateVars(ax::ValueMap* value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
GTextField* setVar(const std::string& name, const ax::Value& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
void flushVars();
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
virtual ax::Value getProp(ObjectPropID propId) override;
|
|
|
|
virtual void setProp(ObjectPropID propId, const ax::Value& value) override;
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void setTextFieldText() = 0;
|
|
|
|
virtual void updateSize();
|
|
|
|
|
|
|
|
virtual void setup_beforeAdd(ByteBuffer* buffer, int beginPos) override;
|
|
|
|
virtual void setup_afterAdd(ByteBuffer* buffer, int beginPos) override;
|
|
|
|
|
|
|
|
std::string parseTemplate(const char* text);
|
|
|
|
|
|
|
|
std::string _text;
|
|
|
|
bool _ubbEnabled;
|
|
|
|
AutoSizeType _autoSize;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::ValueMap* _templateVars;
|
2020-08-04 12:31:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class GBasicTextField : public GTextField
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GBasicTextField();
|
|
|
|
virtual ~GBasicTextField();
|
|
|
|
|
|
|
|
CREATE_FUNC(GBasicTextField);
|
|
|
|
|
|
|
|
virtual void setAutoSize(AutoSizeType value) override;
|
|
|
|
|
|
|
|
virtual bool isSingleLine() const override { return _label->isWrapEnabled(); }
|
|
|
|
virtual void setSingleLine(bool value) override;
|
|
|
|
|
|
|
|
virtual TextFormat* getTextFormat() const override { return _label->getTextFormat(); }
|
|
|
|
virtual void applyTextFormat() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void handleInit() override;
|
|
|
|
virtual void handleSizeChanged() override;
|
|
|
|
virtual void handleGrayedChanged() override;
|
|
|
|
|
|
|
|
virtual void setTextFieldText() override;
|
|
|
|
virtual void updateSize() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FUILabel* _label;
|
|
|
|
bool _updatingSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_FGUI_END
|
|
|
|
|
|
|
|
#endif
|