Added space only wrapping to the simple text area (#851)

This commit is contained in:
SMJS 2024-06-05 20:16:23 +02:00 committed by GitHub
parent 712caa4c1e
commit e0d9056a88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -7,6 +7,7 @@ namespace geode {
enum WrappingMode {
NO_WRAP,
WORD_WRAP,
SPACE_WRAP,
CUTOFF_WRAP
};
@ -70,7 +71,7 @@ namespace geode {
float calculateOffset(cocos2d::CCLabelBMFont* label);
void charIteration(const std::function<cocos2d::CCLabelBMFont*(cocos2d::CCLabelBMFont* line, const char c, const float top)>& overflowHandling);
void updateLinesNoWrap();
void updateLinesWordWrap();
void updateLinesWordWrap(bool spaceWrap);
void updateLinesCutoffWrap();
void updateContainer();
};

View file

@ -209,9 +209,9 @@ void SimpleTextArea::updateLinesNoWrap() {
}
}
void SimpleTextArea::updateLinesWordWrap() {
this->charIteration([this](CCLabelBMFont* line, const char c, const float top) {
static const std::string delimiters(" `~!@#$%^&*()-_=+[{}];:'\",<.>/?\\|");
void SimpleTextArea::updateLinesWordWrap(bool spaceWrap) {
this->charIteration([this, spaceWrap](CCLabelBMFont* line, const char c, const float top) {
static const std::string delimiters(spaceWrap ? " " : " `~!@#$%^&*()-_=+[{}];:'\",<.>/?\\|");
if (delimiters.find(c) == std::string_view::npos) {
const std::string& text = line->getString();
@ -254,7 +254,10 @@ void SimpleTextArea::updateContainer() {
this->updateLinesNoWrap();
} break;
case WORD_WRAP: {
this->updateLinesWordWrap();
this->updateLinesWordWrap(false);
} break;
case SPACE_WRAP: {
this->updateLinesWordWrap(true);
} break;
case CUTOFF_WRAP: {
this->updateLinesCutoffWrap();