mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-27 01:45:35 -05:00
Fixed alignment issues caused by unallocated memory and bad anchor points
Simply put, alignment had no default assignment, causing undefined behavior, this also revealed some bad anchor points which could be optimized
This commit is contained in:
parent
7f277a77e1
commit
0e8865546c
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…
Reference in a new issue