Skip to content

Commit

Permalink
Merge pull request #2327 from LeeARichardson/multiline-unwrapped-labels
Browse files Browse the repository at this point in the history
Allow newlines in unwrapped Labels
  • Loading branch information
cwensley committed Oct 19, 2022
2 parents 8b9f246 + 59ce0c0 commit 2fe9f0c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/Eto.Gtk/Forms/Controls/LabelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,18 @@ void SetWrap(WrapMode mode)
case WrapMode.None:
Control.Wrap = false;
Control.LineWrap = false;
Control.SingleLineMode = true;
break;
case WrapMode.Word:
Control.Wrap = true;
Control.Layout.Wrap = Pango.WrapMode.WordChar;
Control.LineWrapMode = Pango.WrapMode.WordChar;
Control.LineWrap = true;
Control.SingleLineMode = false;
break;
case WrapMode.Character:
Control.Wrap = true;
Control.Layout.Wrap = Pango.WrapMode.Char;
Control.LineWrapMode = Pango.WrapMode.Char;
Control.LineWrap = true;
Control.SingleLineMode = false;
break;
default:
throw new NotSupportedException();
Expand Down
1 change: 0 additions & 1 deletion src/Eto.WinForms/Forms/Controls/LabelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ void SetStringFormat()
switch (Wrap)
{
case WrapMode.None:
textFormat |= swf.TextFormatFlags.SingleLine;
break;
case WrapMode.Word:
textFormat |= swf.TextFormatFlags.WordBreak;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ScalingSection()
tableLayout.SetColumnScale(2);
tableLayout.SetRowScale(0);
tableLayout.SetRowScale(2);
tableLayout.Add(new Label { Text = "2x2, should not scale and be centered", BackgroundColor = Colors.Red }, 1, 1);
tableLayout.Add(new Label { Text = "3x3, should not scale and be centered", BackgroundColor = Colors.Red }, 1, 1);
layout.Add(tableLayout, yscale: true);

Content = layout;
Expand Down
19 changes: 19 additions & 0 deletions test/Eto.Test/UnitTests/Forms/Controls/LabelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,24 @@ public void ChangingTextAfterCreationShouldUpdateSize()
return layout;
});
}

[Test, ManualTest]
public void WrapModeNoneShouldAllowNewLines()
{
ManualForm("Label should have two lines of text", form =>
{
var label = new Label
{
Text = Utility.LoremTextWithTwoParagraphs,
Wrap = WrapMode.None
};
var layout = new PixelLayout
{
Size = new Size(300, 200)
};
layout.Add(label, 0, 0);
return layout;
});
}
}
}

0 comments on commit 2fe9f0c

Please sign in to comment.