Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightly #133

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
versions: [ 11.0.0, 11.0.1, 11.0.2 ]
versions: [ 11.0.0, 11.0.3, 11.0.4 ]

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions ColorTextBlock.Avalonia/CBold.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Bold decoration
/// </summary>
public class CBold : CSpan
{
public CBold() { }
Expand Down
15 changes: 14 additions & 1 deletion ColorTextBlock.Avalonia/CCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,35 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Monospace decoration
/// </summary>
public class CCode : CSpan
{
/// <summary>
/// Monospace font family used for code display.
/// </summary>
/// <see cref="MonospaceFontFamily"/>
public static readonly StyledProperty<FontFamily> MonospaceFontFamilyProperty =
AvaloniaProperty.Register<CCode, FontFamily>(
nameof(MonospaceFontFamily),
defaultValue: FontFamilyCollector.TryGetMonospace() ?? FontFamily.Default,
inherits: true);

public CCode() { }
public CCode() {
var obsvr = this.GetBindingObservable(MonospaceFontFamilyProperty);
Bind(FontFamilyProperty, obsvr);
}

public CCode(IEnumerable<CInline> inlines) : base(inlines)
{
var obsvr = this.GetBindingObservable(MonospaceFontFamilyProperty);
Bind(FontFamilyProperty, obsvr);
}

/// <summary>
/// Monospace font family used for code display.
/// </summary>
public FontFamily MonospaceFontFamily
{
get { return GetValue(MonospaceFontFamilyProperty); }
Expand Down
26 changes: 25 additions & 1 deletion ColorTextBlock.Avalonia/CHyperlink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,50 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Hyperlink decoration
/// </summary>
public class CHyperlink : CSpan
{
/// <summary>
/// Background brush during mouse hover
/// </summary>
/// <seealso cref="HoverBackground"/>
public static readonly StyledProperty<IBrush?> HoverBackgroundProperty =
AvaloniaProperty.Register<CHyperlink, IBrush?>(nameof(Foreground));

/// <summary>
/// Foreground brush during mouse hover
/// </summary>
/// <seealso cref="HoverForeground"/>
public static readonly StyledProperty<IBrush?> HoverForegroundProperty =
AvaloniaProperty.Register<CHyperlink, IBrush?>(nameof(Foreground));

/// <summary>
/// Background brush during mouse hover
/// </summary>
public IBrush? HoverBackground
{
get { return GetValue(HoverBackgroundProperty); }
set { SetValue(HoverBackgroundProperty, value); }
}

/// <summary>
/// Foreground brush during mouse hover
/// </summary>
public IBrush? HoverForeground
{
get { return GetValue(HoverForegroundProperty); }
set { SetValue(HoverForegroundProperty, value); }
}

/// <summary>
/// Link click action
/// </summary>
public Action<string>? Command { get; set; }
/// <summary>
/// Link click action parameter
/// </summary>
public string? CommandParameter { get; set; }

public CHyperlink() { }
Expand Down Expand Up @@ -65,7 +88,8 @@ protected override IEnumerable<CGeometry> MeasureOverride(
PseudoClasses.Add(":pointerover");
PseudoClasses.Add(":hover");

try {
try
{
ctrl.Cursor = new Cursor(StandardCursorType.Hand);
}
catch { /*I cannot assume Cursor.ctor doesn't throw an exception.*/ }
Expand Down
3 changes: 3 additions & 0 deletions ColorTextBlock.Avalonia/CImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Displays an image
/// </summary>
public class CImage : CInline
{
public static readonly StyledProperty<double?> LayoutWidthProperty =
Expand Down
94 changes: 92 additions & 2 deletions ColorTextBlock.Avalonia/CInline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,99 +8,183 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// The base class for representing a text element.
/// </summary>
// テキスト要素を表現するための基底のクラス
[TypeConverter(typeof(StringToRunConverter))]
public abstract class CInline : StyledElement
{
/// <summary>
/// The brush of background.
/// </summary>
/// <seealso cref="Background"/>
public static readonly StyledProperty<IBrush?> BackgroundProperty =
AvaloniaProperty.Register<CInline, IBrush?>(nameof(Background), inherits: true);

/// <summary>
/// The brush of the text element.
/// </summary>
/// <seealso cref="Foreground"/>
public static readonly StyledProperty<IBrush?> ForegroundProperty =
TextBlock.ForegroundProperty.AddOwner<CInline>();

/// <summary>
/// The font family of the text element
/// </summary>
/// <seealso cref="FontFamily"/>
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
TextBlock.FontFamilyProperty.AddOwner<CInline>();

/// <summary>
/// The font weight of the text element
/// </summary>
/// <seealso cref="FontWeight"/>
public static readonly StyledProperty<FontWeight> FontWeightProperty =
TextBlock.FontWeightProperty.AddOwner<CInline>();

/// <summary>
/// The font stretch of the text element
/// </summary>
/// <seealso cref="FontStretch"/>
public static readonly StyledProperty<FontStretch> FontStretchProperty =
TextBlock.FontStretchProperty.AddOwner<CInline>();

/// <summary>
/// The font size of the text element
/// </summary>
/// <seealso cref="FontSize"/>
public static readonly StyledProperty<double> FontSizeProperty =
TextBlock.FontSizeProperty.AddOwner<CInline>();

/// <summary>
/// The font style of the text element
/// </summary>
/// <seealso cref="FontStyle"/>
public static readonly StyledProperty<FontStyle> FontStyleProperty =
TextBlock.FontStyleProperty.AddOwner<CInline>();

/// <summary>
/// Use to indicate the vertical position of text within line.
/// For example, it is used to align text to the top or to the bottom.
/// </summary>
/// <seealso cref="TextVerticalAlignment"/>
// テキストを上揃えで描画するか下揃えで描画するか指定します。
public static readonly StyledProperty<TextVerticalAlignment> TextVerticalAlignmentProperty =
CTextBlock.TextVerticalAlignmentProperty.AddOwner<CInline>();

/// <summary>
/// Indicates whether the text element is underlined.
/// If this property value is true, the text element is underlined.
/// </summary>
/// <seealso cref="IsUnderline"/>
public static readonly StyledProperty<bool> IsUnderlineProperty =
AvaloniaProperty.Register<CInline, bool>(nameof(IsUnderline), inherits: true);

/// <summary>
/// Indicates whether the text element is strikethrough.
/// If the value of this property is true, the text element is strikethrough.
/// </summary>
/// <seealso cref="IsStrikethrough"/>
public static readonly StyledProperty<bool> IsStrikethroughProperty =
AvaloniaProperty.Register<CInline, bool>(nameof(IsStrikethrough), inherits: true);

/// <summary>
/// The brush of background.
/// </summary>
public IBrush? Background
{
get { return GetValue(BackgroundProperty); }
set { SetValue(BackgroundProperty, value); }
}

/// <summary>
/// The brush of the text element.
/// </summary>
public IBrush? Foreground
{
get { return GetValue(ForegroundProperty); }
set { SetValue(ForegroundProperty, value); }
}

/// <summary>
/// The font family of the text element
/// </summary>
public FontFamily FontFamily
{
get { return GetValue(FontFamilyProperty); }
set { SetValue(FontFamilyProperty, value); }
}

/// <summary>
/// The font size of the text element
/// </summary>
public double FontSize
{
get { return GetValue(FontSizeProperty); }
set { SetValue(FontSizeProperty, value); }
}

/// <summary>
/// The font stretch of the text element
/// </summary>
public FontStyle FontStyle
{
get { return GetValue(FontStyleProperty); }
set { SetValue(FontStyleProperty, value); }
}

/// <summary>
/// The font weight of the text element
/// </summary>
public FontWeight FontWeight
{
get { return GetValue(FontWeightProperty); }
set { SetValue(FontWeightProperty, value); }
}

public FontStretch FontStretch
/// <summary>
/// The font stretch of the text element
/// </summary>
public FontStretch FontStretch
{
get { return GetValue(FontStretchProperty); }
set { SetValue(FontStretchProperty, value); }
}

/// <summary>
/// Typeface of the text element
/// </summary>
public Typeface Typeface
{
get;
private set;
}


/// <summary>
/// Indicates whether the text element is underlined.
/// If this property value is true, the text element is underlined.
/// </summary>
public bool IsUnderline
{
get { return GetValue(IsUnderlineProperty); }
set { SetValue(IsUnderlineProperty, value); }
}

/// <summary>
/// Indicates whether the text element is strikethrough.
/// If the value of this property is true, the text element is strikethrough.
/// </summary>
public bool IsStrikethrough
{
get { return GetValue(IsStrikethroughProperty); }
set { SetValue(IsStrikethroughProperty, value); }
}

/// <summary>
/// Use to indicate the vertical position of text within line.
/// For example, it is used to align text to the top or to the bottom.
/// </summary>
public TextVerticalAlignment TextVerticalAlignment
{
get { return GetValue(TextVerticalAlignmentProperty); }
Expand Down Expand Up @@ -188,6 +272,12 @@ protected abstract IEnumerable<CGeometry> MeasureOverride(
double entireWidth,
double remainWidth);


/// <summary>
/// Returns the string that this instance displays.
/// </summary>
/// <returns></returns>
// この要素が表示する文字を返します。
public abstract string AsString();
}
}
7 changes: 7 additions & 0 deletions ColorTextBlock.Avalonia/CInlineUIContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Places a control as an inline element.
/// </summary>
public class CInlineUIContainer : CInline
{
/// <summary>
/// A displayed control
/// </summary>
public Control? Content { get; set; }
internal DummyGeometryForControl? Indicator { get; private set; }

Expand Down Expand Up @@ -41,6 +47,7 @@ protected override IEnumerable<CGeometry> MeasureOverride(double entireWidth, do
}
}

/// <inheritdoc/>
public override string AsString() => String.Empty;
}
}
3 changes: 3 additions & 0 deletions ColorTextBlock.Avalonia/CItalic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Italic decoration
/// </summary>
public class CItalic : CSpan
{
public CItalic() { }
Expand Down
3 changes: 3 additions & 0 deletions ColorTextBlock.Avalonia/CLineBreak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Expression of the linebreak.
/// </summary>
public class CLineBreak : CRun
{
public CLineBreak()
Expand Down
10 changes: 10 additions & 0 deletions ColorTextBlock.Avalonia/CRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@

namespace ColorTextBlock.Avalonia
{
/// <summary>
/// Expression of a text
/// </summary>
public class CRun : CInline
{
private static readonly Regex Sep = new("\r\n|\r|\n", RegexOptions.Compiled);

/// <summary>
/// THe content of the eleemnt
/// </summary>
/// <seealso cref="Content"/>
public static readonly StyledProperty<string> TextProperty =
AvaloniaProperty.Register<CRun, string>(nameof(Text));

/// <summary>
/// THe content of the eleemnt
/// </summary>
[Content]
public string Text
{
Expand Down
Loading
Loading