geode/loader/include/Geode/ui/MDTextArea.hpp

76 lines
2.1 KiB
C++
Raw Normal View History

#pragma once
#include "ScrollLayer.hpp"
2022-10-30 14:59:20 -04:00
#include "TextRenderer.hpp"
#include <Geode/binding/FLAlertLayerProtocol.hpp>
struct MDParser;
2022-10-13 05:56:23 -04:00
class CCScrollLayerExt;
namespace geode {
/**
2022-10-30 14:59:20 -04:00
* TextArea for static markdown content. Supports the
* following features:
* - Links
* - Images (sprites & spritesheets)
* - Headings
* - Paragraphs
* - Code blocks
* - Code spans
* - TextArea color tags (<cr>, <cy>, etc.)
* - Strikethrough
* - Underline
* - Bold & italic
* - Horizontal rules
* - Lists
2022-10-30 14:59:20 -04:00
* Note that links also have some special protocols.
* Use `user:<id>` or `user:<name>` to link to a GD
* account; `level:<id>` to link to a GD level and
* `mod:<id>` to link to another Geode mod.
*/
class GEODE_DLL MDTextArea :
public cocos2d::CCLayer,
public cocos2d::CCLabelProtocol,
2022-10-30 14:59:20 -04:00
public FLAlertLayerProtocol {
protected:
std::string m_text;
cocos2d::CCSize m_size;
cocos2d::extension::CCScale9Sprite* m_bgSprite = nullptr;
cocos2d::CCMenu* m_content = nullptr;
CCScrollLayerExt* m_scrollLayer = nullptr;
TextRenderer* m_renderer = nullptr;
bool init(std::string const& str, cocos2d::CCSize const& size);
virtual ~MDTextArea();
void onLink(CCObject*);
void onGDProfile(CCObject*);
void FLAlert_Clicked(FLAlertLayer*, bool btn) override;
friend struct ::MDParser;
public:
/**
* Create a markdown text area. See class
* documentation for details on supported
* features & notes.
* @param str String to render
* @param size Size of the textarea
*/
static MDTextArea* create(std::string const& str, cocos2d::CCSize const& size);
/**
* Update the label's content; call
* sparingly as rendering may be slow
*/
void updateLabel();
2022-10-30 14:59:20 -04:00
void setString(char const* text) override;
char const* getString() override;
CCScrollLayerExt* getScrollLayer() const;
};
}