From 140f38bee0d0d7a0e5ae77280e0e07ebe992195c Mon Sep 17 00:00:00 2001 From: FigmentBoy <17240592+FigmentBoy@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:14:59 -0400 Subject: [PATCH] Make MDTextArea fit within provided size (and look better) --- loader/src/ui/nodes/MDTextArea.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/loader/src/ui/nodes/MDTextArea.cpp b/loader/src/ui/nodes/MDTextArea.cpp index c6afcda2..fb5e2046 100644 --- a/loader/src/ui/nodes/MDTextArea.cpp +++ b/loader/src/ui/nodes/MDTextArea.cpp @@ -109,8 +109,8 @@ bool MDTextArea::init(std::string const& str, CCSize const& size) { if (!CCLayer::init()) return false; m_text = str; - m_size = size; - this->setContentSize(size); + m_size = size - CCSize { 15.f, 0.f }; + this->setContentSize(m_size); m_renderer = TextRenderer::create(); CC_SAFE_RETAIN(m_renderer); @@ -118,8 +118,8 @@ bool MDTextArea::init(std::string const& str, CCSize const& size) { m_bgSprite->setScale(.5f); m_bgSprite->setColor({ 0, 0, 0 }); m_bgSprite->setOpacity(75); - m_bgSprite->setContentSize(size * 2 + CCSize { 25.f, 25.f }); - m_bgSprite->setPosition(size / 2); + m_bgSprite->setContentSize(size * 2); + m_bgSprite->setPosition(m_size / 2); this->addChild(m_bgSprite); m_scrollLayer = ScrollLayer::create({ 0, 0, m_size.width, m_size.height }, true); @@ -695,7 +695,16 @@ void MDTextArea::updateLabel() { m_renderer->end(); - m_scrollLayer->m_contentLayer->setContentSize(m_content->getContentSize()); + if (m_content->getContentSize().height > m_size.height) { + // Generate bottom padding + m_scrollLayer->m_contentLayer->setContentSize(m_content->getContentSize() + CCSize { 0.f, 12.5 }); + m_content->setPositionY(10.f); + } else { + m_scrollLayer->m_contentLayer->setContentSize(m_content->getContentSize()); + m_content->setPositionY(-2.5f); + } + + m_scrollLayer->moveToTop(); }