Prechádzať zdrojové kódy

Textarea: Word wrapping should make horizontal overflow hidden

Michael Ragazzon 1 rok pred
rodič
commit
4cb518eccd

+ 3 - 0
Include/RmlUi/Core/Elements/ElementFormControlTextArea.h

@@ -132,6 +132,9 @@ protected:
 	void GetInnerRML(String& content) const override;
 	void GetInnerRML(String& content) const override;
 
 
 private:
 private:
+	/// Sets the necessary properties to display the widget in current word wrap state.
+	void SetWordWrapProperties();
+
 	UniquePtr<WidgetTextInputMultiLine> widget;
 	UniquePtr<WidgetTextInputMultiLine> widget;
 };
 };
 
 

+ 10 - 10
Source/Core/Elements/ElementFormControlTextArea.cpp

@@ -39,10 +39,7 @@ namespace Rml {
 ElementFormControlTextArea::ElementFormControlTextArea(const String& tag) : ElementFormControl(tag)
 ElementFormControlTextArea::ElementFormControlTextArea(const String& tag) : ElementFormControl(tag)
 {
 {
 	widget = MakeUnique<WidgetTextInputMultiLine>(this);
 	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() {}
 ElementFormControlTextArea::~ElementFormControlTextArea() {}
@@ -157,12 +154,7 @@ void ElementFormControlTextArea::OnAttributeChange(const ElementAttributes& chan
 	ElementFormControl::OnAttributeChange(changed_attributes);
 	ElementFormControl::OnAttributeChange(changed_attributes);
 
 
 	if (changed_attributes.find("wrap") != changed_attributes.end())
 	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())
 	if (changed_attributes.find("rows") != changed_attributes.end() || changed_attributes.find("cols") != changed_attributes.end())
 		DirtyLayout();
 		DirtyLayout();
@@ -199,4 +191,12 @@ void ElementFormControlTextArea::GetInnerRML(String& content) const
 	content = GetValue();
 	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
 } // namespace Rml