// Update Content Lines structure void TextFieldWidget::UpdateContentLines() { m_ContentLines.clear(); m_MaxLineLength = 0; std::string::size_type Start = 0, End; do { End = m_Content.find_first_of('\n', Start); auto Length = ((std::string::npos != End) ? End : m_Content.length()) - Start; m_ContentLines.push_back(ContentLine(Start, Length)); auto LengthX = GetCaretPositionX(m_ContentLines.size() - 1, Length) / charWidth; if (m_MaxLineLength < LengthX) m_MaxLineLength = LengthX; Start = End + 1; } while (std::string::npos != End); // TEST: Resize the widget to accomodate text width ModifyDimensions().X() = std::max<sint32>(static_cast<sint32>(m_MaxLineLength * charWidth), 3 * charWidth); ModifyDimensions().Y() = std::max<sint32>(static_cast<sint32>(m_ContentLines.size()) * lineHeight, 1 * lineHeight); if (nullptr != m_OnChange) { m_OnChange(); } }
LabelWidget::LabelWidget(const Vector2n Position, const std::function<std::string()> & Content, Background Background) : Widget(Position, Vector2n::ZERO, { /*std::shared_ptr<Behavior>(new DraggablePositionBehavior(*this))*/ }), m_Content(Content), m_Background(Background) { // Calculate widget dimensions on init ModifyDimensions() = Concept::GetDimensions(m_Content()); }
void LabelWidget::Render() { // TODO: Refactor this out if (!m_Visible) return; Color BackgroundColor(1.0, 1.0, 1.0); Color BorderColor(0.6, 0.6, 0.6); auto Content = m_Content(); ModifyDimensions() = Concept::GetDimensions(Content); if (Background::Normal == m_Background) { DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor); } OpenGLStream OpenGLStream(GetPosition()); OpenGLStream << Content; }