2023-10-01 17:59:44 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Geode/DefaultInclude.hpp>
|
|
|
|
#include <cocos2d.h>
|
|
|
|
|
|
|
|
namespace geode {
|
2023-10-10 13:19:12 -04:00
|
|
|
enum WrappingMode {
|
|
|
|
NO_WRAP,
|
|
|
|
WORD_WRAP,
|
|
|
|
CUTOFF_WRAP
|
|
|
|
};
|
|
|
|
|
2023-10-01 17:59:44 -04:00
|
|
|
/**
|
|
|
|
* A class which provides a textarea with proper alignment and some extra features like:
|
|
|
|
*
|
|
|
|
* - Max lines
|
|
|
|
* - Changing all aspects after creation
|
|
|
|
* - Custom text alignment
|
2023-10-10 13:19:12 -04:00
|
|
|
* - Configurable and automatic word wrapping
|
2023-10-01 17:59:44 -04:00
|
|
|
* - Line padding
|
|
|
|
*
|
|
|
|
* Contact me on Discord (\@smjs) if you have any questions, suggestions or bugs.
|
|
|
|
*/
|
|
|
|
class GEODE_DLL SimpleTextArea : public cocos2d::CCNode {
|
2024-01-28 13:27:11 -05:00
|
|
|
public:
|
2023-10-10 13:19:12 -04:00
|
|
|
static SimpleTextArea* create(const std::string& text, const std::string& font = "chatFont.fnt", const float scale = 1);
|
|
|
|
static SimpleTextArea* create(const std::string& text, const std::string& font, const float scale, const float width);
|
|
|
|
|
2023-10-01 17:59:44 -04:00
|
|
|
void setFont(const std::string& font);
|
|
|
|
std::string getFont();
|
2023-10-10 13:19:12 -04:00
|
|
|
void setColor(const cocos2d::ccColor4B& color);
|
|
|
|
cocos2d::ccColor4B getColor();
|
2023-10-01 17:59:44 -04:00
|
|
|
void setAlignment(const cocos2d::CCTextAlignment alignment);
|
|
|
|
cocos2d::CCTextAlignment getAlignment();
|
2023-10-10 13:19:12 -04:00
|
|
|
void setWrappingMode(const WrappingMode mode);
|
|
|
|
WrappingMode getWrappingMode();
|
2023-10-01 17:59:44 -04:00
|
|
|
void setText(const std::string& text);
|
|
|
|
std::string getText();
|
|
|
|
void setMaxLines(const size_t maxLines);
|
|
|
|
size_t getMaxLines();
|
|
|
|
void setWidth(const float width);
|
|
|
|
float getWidth();
|
2023-10-15 10:48:40 -04:00
|
|
|
void setScale(const float scale) override;
|
|
|
|
float getScale() override;
|
2023-10-01 17:59:44 -04:00
|
|
|
void setLinePadding(const float padding);
|
|
|
|
float getLinePadding();
|
|
|
|
std::vector<cocos2d::CCLabelBMFont*> getLines();
|
|
|
|
float getHeight();
|
|
|
|
float getLineHeight();
|
|
|
|
private:
|
|
|
|
static SimpleTextArea* create(const std::string& font, const std::string& text, const float scale, const float width, const bool artificialWidth);
|
|
|
|
|
2023-10-10 13:19:12 -04:00
|
|
|
bool m_shouldUpdate;
|
|
|
|
bool m_artificialWidth;
|
2024-01-28 13:55:28 -05:00
|
|
|
cocos2d::CCMenu* m_container;
|
|
|
|
std::string m_font;
|
|
|
|
std::string m_text;
|
|
|
|
std::vector<cocos2d::CCLabelBMFont*> m_lines;
|
|
|
|
cocos2d::ccColor4B m_color;
|
|
|
|
cocos2d::CCTextAlignment m_alignment;
|
|
|
|
WrappingMode m_wrappingMode;
|
|
|
|
size_t m_maxLines;
|
|
|
|
float m_scale;
|
|
|
|
float m_lineHeight;
|
|
|
|
float m_linePadding;
|
2023-10-10 13:19:12 -04:00
|
|
|
|
2023-10-01 17:59:44 -04:00
|
|
|
SimpleTextArea(const std::string& font, const std::string& text, const float scale, const float width, const bool artificialWidth);
|
|
|
|
cocos2d::CCLabelBMFont* createLabel(const std::string& text, const float top);
|
|
|
|
float calculateOffset(cocos2d::CCLabelBMFont* label);
|
2023-10-10 13:19:12 -04:00
|
|
|
void charIteration(const std::function<cocos2d::CCLabelBMFont*(cocos2d::CCLabelBMFont* line, const char c, const float top)>& overflowHandling);
|
|
|
|
void updateLinesNoWrap();
|
|
|
|
void updateLinesWordWrap();
|
|
|
|
void updateLinesCutoffWrap();
|
|
|
|
void updateContainer();
|
|
|
|
virtual void draw() override;
|
2023-10-01 17:59:44 -04:00
|
|
|
};
|
|
|
|
}
|