mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-31 07:10:28 -04:00
Fixed alignment issues caused by unallocated memory and bad anchor points (#282)
This commit is contained in:
parent
7f277a77e1
commit
36c461ace4
1 changed files with 5 additions and 7 deletions
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue