mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-30 11:17:08 -05:00
084fea220e
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions
78 lines
3 KiB
C++
78 lines
3 KiB
C++
#pragma once
|
|
|
|
#include <Geode/DefaultInclude.hpp>
|
|
#include <cocos2d.h>
|
|
|
|
namespace geode {
|
|
enum WrappingMode {
|
|
NO_WRAP,
|
|
WORD_WRAP,
|
|
SPACE_WRAP,
|
|
CUTOFF_WRAP
|
|
};
|
|
|
|
/**
|
|
* A class which provides a textarea with proper alignment and some extra features like:
|
|
*
|
|
* - Max lines
|
|
* - Changing all aspects after creation
|
|
* - Custom text alignment
|
|
* - Configurable and automatic word wrapping
|
|
* - Line padding
|
|
*
|
|
* Contact me on Discord (\@smjs) if you have any questions, suggestions or bugs.
|
|
*/
|
|
class GEODE_DLL SimpleTextArea : public cocos2d::CCNode {
|
|
public:
|
|
static SimpleTextArea* create(const std::string& text, const std::string& font = "chatFont.fnt", float scale = 1.0f);
|
|
static SimpleTextArea* create(const std::string& text, const std::string& font, float scale, float width);
|
|
|
|
void setFont(const std::string& font);
|
|
std::string getFont();
|
|
void setColor(const cocos2d::ccColor4B& color);
|
|
cocos2d::ccColor4B getColor();
|
|
void setAlignment(cocos2d::CCTextAlignment alignment);
|
|
cocos2d::CCTextAlignment getAlignment();
|
|
void setWrappingMode(WrappingMode mode);
|
|
WrappingMode getWrappingMode();
|
|
void setText(const std::string& text);
|
|
std::string getText();
|
|
void setMaxLines(size_t maxLines);
|
|
size_t getMaxLines();
|
|
void setWidth(float width);
|
|
float getWidth();
|
|
void setScale(float scale) override;
|
|
float getScale() override;
|
|
void setLinePadding(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, float scale, float width, const bool artificialWidth);
|
|
|
|
bool init(const std::string& font, const std::string& text, float scale, float width, const bool artificialWidth);
|
|
|
|
bool m_shouldUpdate = false;
|
|
bool m_artificialWidth = false;
|
|
cocos2d::CCMenu* m_container = nullptr;
|
|
std::string m_font;
|
|
std::string m_text;
|
|
std::vector<cocos2d::CCLabelBMFont*> m_lines;
|
|
cocos2d::ccColor4B m_color = { 0xFF, 0xFF, 0xFF, 0xFF };
|
|
cocos2d::CCTextAlignment m_alignment = cocos2d::kCCTextAlignmentLeft;
|
|
WrappingMode m_wrappingMode = WORD_WRAP;
|
|
size_t m_maxLines = 0;
|
|
float m_scale = 1.f;
|
|
float m_lineHeight = 0.f;
|
|
float m_linePadding = 0.f;
|
|
|
|
cocos2d::CCLabelBMFont* createLabel(const std::string& text, float top);
|
|
float calculateOffset(cocos2d::CCLabelBMFont* label);
|
|
void charIteration(const std::function<cocos2d::CCLabelBMFont*(cocos2d::CCLabelBMFont* line, char c, float top)>& overflowHandling);
|
|
void updateLinesNoWrap();
|
|
void updateLinesWordWrap(bool spaceWrap);
|
|
void updateLinesCutoffWrap();
|
|
void updateContainer();
|
|
};
|
|
}
|