diff --git a/Include/RmlUi/Core/Elements/ElementFormControlTextArea.h b/Include/RmlUi/Core/Elements/ElementFormControlTextArea.h index b9a555db7..c95be509e 100644 --- a/Include/RmlUi/Core/Elements/ElementFormControlTextArea.h +++ b/Include/RmlUi/Core/Elements/ElementFormControlTextArea.h @@ -132,6 +132,9 @@ class RMLUICORE_API ElementFormControlTextArea : public ElementFormControl { void GetInnerRML(String& content) const override; private: + /// Sets the necessary properties to display the widget in current word wrap state. + void SetWordWrapProperties(); + UniquePtr widget; }; diff --git a/Source/Core/Elements/ElementFormControlTextArea.cpp b/Source/Core/Elements/ElementFormControlTextArea.cpp index f0503b84f..a42c21b70 100644 --- a/Source/Core/Elements/ElementFormControlTextArea.cpp +++ b/Source/Core/Elements/ElementFormControlTextArea.cpp @@ -39,10 +39,7 @@ namespace Rml { ElementFormControlTextArea::ElementFormControlTextArea(const String& tag) : ElementFormControl(tag) { widget = MakeUnique(this); - - SetProperty(PropertyId::OverflowX, Property(Style::Overflow::Auto)); - SetProperty(PropertyId::OverflowY, Property(Style::Overflow::Auto)); - SetProperty(PropertyId::WhiteSpace, Property(Style::WhiteSpace::Prewrap)); + SetWordWrapProperties(); } ElementFormControlTextArea::~ElementFormControlTextArea() {} @@ -157,12 +154,7 @@ void ElementFormControlTextArea::OnAttributeChange(const ElementAttributes& chan ElementFormControl::OnAttributeChange(changed_attributes); if (changed_attributes.find("wrap") != changed_attributes.end()) - { - if (GetWordWrap()) - SetProperty(PropertyId::WhiteSpace, Property(Style::WhiteSpace::Prewrap)); - else - SetProperty(PropertyId::WhiteSpace, Property(Style::WhiteSpace::Pre)); - } + SetWordWrapProperties(); if (changed_attributes.find("rows") != changed_attributes.end() || changed_attributes.find("cols") != changed_attributes.end()) DirtyLayout(); @@ -199,4 +191,12 @@ void ElementFormControlTextArea::GetInnerRML(String& content) const content = GetValue(); } +void ElementFormControlTextArea::SetWordWrapProperties() +{ + const bool word_wrap = GetWordWrap(); + SetProperty(PropertyId::OverflowX, Property(word_wrap ? Style::Overflow::Hidden : Style::Overflow::Auto)); + SetProperty(PropertyId::OverflowY, Property(Style::Overflow::Auto)); + SetProperty(PropertyId::WhiteSpace, Property(word_wrap ? Style::WhiteSpace::Prewrap : Style::WhiteSpace::Pre)); +} + } // namespace Rml