axmol/extensions/fairygui/display/FUIRichText.h

79 lines
2.3 KiB
C
Raw Normal View History

2020-08-04 12:31:33 +08:00
#ifndef __FUIRICHTEXT_H__
#define __FUIRICHTEXT_H__
#include "cocos2d.h"
#include "FairyGUIMacros.h"
#include "TextFormat.h"
#include "utils/html/HtmlParser.h"
2020-08-04 12:31:33 +08:00
NS_FGUI_BEGIN
class HtmlObject;
2020-08-04 12:31:33 +08:00
2022-08-08 18:02:17 +08:00
class FUIRichText : public ax::Node
2020-08-04 12:31:33 +08:00
{
public:
FUIRichText();
virtual ~FUIRichText();
CREATE_FUNC(FUIRichText);
2022-08-08 18:02:17 +08:00
const ax::Size& getDimensions() const { return _dimensions; }
2020-08-04 12:31:33 +08:00
void setDimensions(float width, float height);
void setText(const std::string& value);
TextFormat* getTextFormat() { return &_textFormat; }
2020-08-04 12:31:33 +08:00
void applyTextFormat();
2022-08-08 18:02:17 +08:00
ax::Label::Overflow getOverflow()const { return _overflow; }
void setOverflow(ax::Label::Overflow overflow);
2020-08-04 12:31:33 +08:00
bool isAnchorTextUnderline();
2020-08-04 12:31:33 +08:00
void setAnchorTextUnderline(bool enable);
2022-08-08 18:02:17 +08:00
const ax::Color3B& getAnchorFontColor();
void setAnchorFontColor(const ax::Color3B& color);
2020-08-04 12:31:33 +08:00
void setObjectFactory(const std::function<HtmlObject*(HtmlElement*)>& value) { _objectFactory = value; }
HtmlParseOptions& parseOptions() { return _parseOptions; }
const std::vector<HtmlObject*>& getControls() const { return _controls; }
HtmlObject* getControl(const std::string& name) const;
2022-08-08 18:02:17 +08:00
const char* hitTestLink(const ax::Vec2& worldPoint);
virtual void visit(ax::Renderer *renderer, const ax::Mat4 &parentTransform, uint32_t parentFlags) override;
2020-08-04 12:31:33 +08:00
2022-08-08 18:02:17 +08:00
virtual const ax::Size& getContentSize() const override;
2020-08-04 12:31:33 +08:00
protected:
2020-08-04 12:31:33 +08:00
virtual bool init() override;
void formatText();
void formarRenderers();
void handleTextRenderer(HtmlElement* element, const std::string& text);
void handleRichRenderer(HtmlElement* element);
2020-08-04 12:31:33 +08:00
void addNewLine();
2022-08-08 18:02:17 +08:00
int findSplitPositionForWord(ax::Label* label, const std::string& text);
void doHorizontalAlignment(const std::vector<ax::Node*>& row, float rowWidth);
2020-08-04 12:31:33 +08:00
std::vector<HtmlElement*> _elements;
std::vector<HtmlObject*> _controls;
2022-08-08 18:02:17 +08:00
std::vector<std::vector<ax::Node*>> _renderers;
2020-08-04 12:31:33 +08:00
bool _formatTextDirty;
bool _textChanged;
2022-08-08 18:02:17 +08:00
ax::Size _dimensions;
2020-08-04 12:31:33 +08:00
float _leftSpaceWidth;
float _textRectWidth;
int _numLines;
2022-08-08 18:02:17 +08:00
ax::Label::Overflow _overflow;
TextFormat _textFormat;
2020-08-04 12:31:33 +08:00
std::string _text;
HtmlParseOptions _parseOptions;
std::function<HtmlObject*(HtmlElement*)> _objectFactory;
2020-08-04 12:31:33 +08:00
};
NS_FGUI_END
#endif