Skip to content

Commit

Permalink
Fixed alignment issues caused by unallocated memory and bad anchor po…
Browse files Browse the repository at this point in the history
…ints (#282)
  • Loading branch information
SMJSGaming authored Oct 3, 2023
1 parent 7f277a7 commit 36c461a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions loader/src/ui/nodes/TextArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SimpleTextArea::SimpleTextArea(const std::string& font, const std::string& text,
m_maxLines = 0;
m_scale = scale;
m_linePadding = 0;
m_alignment = kCCTextAlignmentLeft;
m_artificialWidth = artificialWidth;
m_container = CCMenu::create();

Expand Down Expand Up @@ -129,7 +130,6 @@ CCLabelBMFont* SimpleTextArea::createLabel(const std::string& text, const float
CCLabelBMFont* label = CCLabelBMFont::create(text.c_str(), m_font.c_str());

label->setScale(m_scale);
label->setAnchorPoint({ 0, 0 });
label->setPosition({ 0, top });

return label;
Expand Down Expand Up @@ -203,26 +203,24 @@ void SimpleTextArea::updateContents() {
m_container->setContentSize(this->getContentSize());
m_container->removeAllChildren();

height -= m_lineHeight;

for (CCLabelBMFont* line : m_lines) {
const float y = height + line->getPositionY();

switch (m_alignment) {
case kCCTextAlignmentLeft: {
line->setAnchorPoint({ 0, 0 });
line->setAnchorPoint({ 0, 1 });
line->setPosition({ 0, y });
} break;
case kCCTextAlignmentCenter: {
line->setAnchorPoint({ 0.5f, 0 });
line->setAnchorPoint({ 0.5f, 1 });
line->setPosition({ width / 2, y });
} break;
case kCCTextAlignmentRight: {
line->setAnchorPoint({ 1, 0 });
line->setAnchorPoint({ 1, 1 });
line->setPosition({ width, y });
} break;
}

m_container->addChild(line);
}
}
}

0 comments on commit 36c461a

Please sign in to comment.