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-07-11 17:50:21 +08:00
|
|
|
virtual const axis::Size& getTextSize() { return _displayObject->getContentSize(); }
|
2020-08-04 12:31:33 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Color3B getColor() const { return getTextFormat()->color; }
|
|
|
|
void setColor(const axis::Color3B& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
|
|
|
float getFontSize() const { return getTextFormat()->fontSize; }
|
|
|
|
void setFontSize(float value);
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Color3B getOutlineColor() const { return getTextFormat()->outlineColor; }
|
|
|
|
void setOutlineColor(const axis::Color3B& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ValueMap* getTemplateVars() { return _templateVars; }
|
|
|
|
void setTemplateVars(axis::ValueMap* value);
|
2020-08-04 12:31:33 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
GTextField* setVar(const std::string& name, const axis::Value& value);
|
2020-08-04 12:31:33 +08:00
|
|
|
void flushVars();
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
virtual axis::Value getProp(ObjectPropID propId) override;
|
|
|
|
virtual void setProp(ObjectPropID propId, const axis::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-07-11 17:50:21 +08:00
|
|
|
axis::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
|