Browse Source

Added TextWrapping setting.

TextBox doesn't handle quite a few things yet, scrolling and lines for
example.
pull/10/head
Steven Kirk 11 years ago
parent
commit
71e46c3084
  1. 1
      Perspex.Controls/Perspex.Controls.csproj
  2. 19
      Perspex.Controls/TextBlock.cs
  3. 9
      Perspex.Controls/TextBox.cs
  4. 1
      Perspex.Controls/TextBoxView.cs
  5. 14
      Perspex.Controls/TextWrapping.cs
  6. 5
      Perspex.SceneGraph/Size.cs
  7. 9
      TestApplication/Program.cs

1
Perspex.Controls/Perspex.Controls.csproj

@ -73,6 +73,7 @@
<Compile Include="Panel.cs" />
<Compile Include="Primitives\Track.cs" />
<Compile Include="Primitives\Thumb.cs" />
<Compile Include="TextWrapping.cs" />
<Compile Include="Window.cs" />
<Compile Include="RowDefinition.cs" />
<Compile Include="RowDefinitions.cs" />

19
Perspex.Controls/TextBlock.cs

@ -30,6 +30,9 @@ namespace Perspex.Controls
public static readonly PerspexProperty<string> TextProperty =
PerspexProperty.Register<TextBlock, string>("Text");
public static readonly PerspexProperty<TextWrapping> TextWrappingProperty =
PerspexProperty.Register<TextBlock, TextWrapping>("TextWrapping");
private FormattedText formattedText;
public TextBlock()
@ -74,6 +77,12 @@ namespace Perspex.Controls
set { this.SetValue(FontStyleProperty, value); }
}
public TextWrapping TextWrapping
{
get { return this.GetValue(TextWrappingProperty); }
set { this.SetValue(TextWrappingProperty, value); }
}
protected FormattedText FormattedText
{
get
@ -108,7 +117,15 @@ namespace Perspex.Controls
{
if (!string.IsNullOrEmpty(this.Text))
{
this.FormattedText.Constraint = availableSize;
if (this.TextWrapping == TextWrapping.Wrap)
{
this.FormattedText.Constraint = new Size(availableSize.Width, double.PositiveInfinity);
}
else
{
this.FormattedText.Constraint = Size.Infinity;
}
return this.FormattedText.Measure();
}

9
Perspex.Controls/TextBox.cs

@ -32,6 +32,9 @@ namespace Perspex.Controls
public static readonly PerspexProperty<string> TextProperty =
TextBlock.TextProperty.AddOwner<TextBox>();
public static readonly PerspexProperty<TextWrapping> TextWrappingProperty =
TextBlock.TextWrappingProperty.AddOwner<TextBox>();
private TextBoxView textBoxView;
static TextBox()
@ -83,6 +86,12 @@ namespace Perspex.Controls
set { this.SetValue(TextProperty, value); }
}
public TextWrapping TextWrapping
{
get { return this.GetValue(TextWrappingProperty); }
set { this.SetValue(TextWrappingProperty, value); }
}
protected override void OnTemplateApplied()
{
Decorator textContainer = this.GetVisualDescendents()

1
Perspex.Controls/TextBoxView.cs

@ -26,6 +26,7 @@ namespace Perspex.Controls
this.caretTimer.Tick += this.CaretTimerTick;
this.parent = parent;
this[!TextProperty] = parent[!TextProperty];
this[!TextWrappingProperty] = parent[!TextWrappingProperty];
Observable.Merge(
this.parent.GetObservable(TextBox.SelectionStartProperty),

14
Perspex.Controls/TextWrapping.cs

@ -0,0 +1,14 @@
// -----------------------------------------------------------------------
// <copyright file="TextBox.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
public enum TextWrapping
{
NoWrap,
Wrap
}
}

5
Perspex.SceneGraph/Size.cs

@ -14,6 +14,11 @@ namespace Perspex
/// </summary>
public struct Size
{
/// <summary>
/// A size representing infinity.
/// </summary>
public static readonly Size Infinity = new Size(double.PositiveInfinity, double.PositiveInfinity);
/// <summary>
/// The width.
/// </summary>

9
TestApplication/Program.cs

@ -220,6 +220,7 @@ namespace TestApplication
new TextBlock
{
Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis dui quis libero suscipit tincidunt.",
TextWrapping = TextWrapping.Wrap,
},
new TextBlock
{
@ -228,7 +229,13 @@ namespace TestApplication
},
new TextBox
{
Text = "Some example text",
Text = "A non-wrapping text box. Lorem ipsum dolor sit amet.",
TextWrapping = TextWrapping.NoWrap,
},
new TextBox
{
Text = "A wrapping text box. Lorem ipsum dolor sit amet.",
TextWrapping = TextWrapping.Wrap,
},
}
},

Loading…
Cancel
Save