Skip to content

Commit

Permalink
Textarea: Word wrapping should make horizontal overflow hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Jul 7, 2024
1 parent 5d37025 commit 4cb518e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Include/RmlUi/Core/Elements/ElementFormControlTextArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<WidgetTextInputMultiLine> widget;
};

Expand Down
20 changes: 10 additions & 10 deletions Source/Core/Elements/ElementFormControlTextArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ namespace Rml {
ElementFormControlTextArea::ElementFormControlTextArea(const String& tag) : ElementFormControl(tag)
{
widget = MakeUnique<WidgetTextInputMultiLine>(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() {}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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

0 comments on commit 4cb518e

Please sign in to comment.