-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add text support for extensions. Thanks, @sn4k3
Merge pull request #39 from SKProCH/textExtensions
- Loading branch information
Showing
9 changed files
with
183 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using Avalonia.Controls; | ||
using Avalonia.Layout; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace Material.Icons.Avalonia | ||
{ | ||
public class MaterialIconTextExt : MaterialIconExt { | ||
public MaterialIconTextExt() { } | ||
public MaterialIconTextExt(MaterialIconKind kind) : base(kind) { } | ||
|
||
public MaterialIconTextExt(MaterialIconKind kind, double? size) : base(kind, size) { } | ||
|
||
[ConstructorArgument("spacing")] | ||
public double Spacing { get; set; } = 5; | ||
|
||
[ConstructorArgument("orientation")] | ||
public Orientation Orientation { get; set; } = Orientation.Horizontal; | ||
|
||
[ConstructorArgument("text")] | ||
public string? Text { get; set; } | ||
|
||
[ConstructorArgument("textfirst")] | ||
public bool TextFirst { get; set; } = false; | ||
|
||
[ConstructorArgument("isTextSelectable")] | ||
public bool IsTextSelectable { get; set; } = false; | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) { | ||
var icon = (Control)base.ProvideValue(serviceProvider); | ||
|
||
if (string.IsNullOrWhiteSpace(Text)) return icon; | ||
|
||
var textBlock = IsTextSelectable ? | ||
new SelectableTextBlock { | ||
Text = Text, | ||
HorizontalAlignment = HorizontalAlignment.Center, | ||
VerticalAlignment = VerticalAlignment.Center, | ||
} | ||
: new TextBlock { | ||
Text = Text, | ||
HorizontalAlignment = HorizontalAlignment.Center, | ||
VerticalAlignment = VerticalAlignment.Center, | ||
}; | ||
|
||
if (Size.HasValue) textBlock.FontSize = Size.Value; | ||
|
||
return new StackPanel { | ||
Orientation = Orientation, | ||
Spacing = Spacing, | ||
Children = { | ||
TextFirst ? textBlock : icon, | ||
TextFirst ? icon : textBlock | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Markup; | ||
|
||
namespace Material.Icons.WPF | ||
{ | ||
[MarkupExtensionReturnType(typeof(MaterialIcon))] | ||
public class MaterialIconTextExt : MaterialIconExt { | ||
public MaterialIconTextExt() { } | ||
public MaterialIconTextExt(MaterialIconKind kind) : base(kind) { } | ||
|
||
public MaterialIconTextExt(MaterialIconKind kind, double size) : base(kind, size) { } | ||
|
||
[ConstructorArgument("spacing")] | ||
public double Spacing { get; set; } = 5; | ||
|
||
[ConstructorArgument("orientation")] | ||
public Orientation Orientation { get; set; } = Orientation.Horizontal; | ||
|
||
[ConstructorArgument("text")] | ||
public string? Text { get; set; } | ||
|
||
[ConstructorArgument("textfirst")] | ||
public bool TextFirst { get; set; } = false; | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) { | ||
var icon = (Control)base.ProvideValue(serviceProvider); | ||
|
||
if (string.IsNullOrWhiteSpace(Text)) | ||
return icon; | ||
|
||
var textBlock = new TextBlock { | ||
Text = Text, | ||
HorizontalAlignment = HorizontalAlignment.Center, | ||
VerticalAlignment = VerticalAlignment.Center, | ||
}; | ||
|
||
if (Size.HasValue) | ||
textBlock.FontSize = Size.Value; | ||
|
||
if (Spacing > 0) { | ||
if (TextFirst) { | ||
textBlock.Margin = Orientation == Orientation.Horizontal | ||
? new Thickness(0, 0, Spacing, 0) | ||
: new Thickness(0, 0, 0, Spacing); | ||
} | ||
else { | ||
textBlock.Margin = Orientation == Orientation.Horizontal | ||
? new Thickness(Spacing, 0, 0, 0) | ||
: new Thickness(0, Spacing, 0, 0); | ||
} | ||
} | ||
|
||
return new StackPanel { | ||
Orientation = Orientation, | ||
Children = { | ||
TextFirst ? textBlock : icon, | ||
TextFirst ? icon : textBlock | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Material.Icons.WinUI3; | ||
|
||
public partial class MaterialIconTextExt : MaterialIconExt { | ||
public MaterialIconTextExt() { } | ||
public MaterialIconTextExt(MaterialIconKind kind) : base(kind) { } | ||
|
||
public MaterialIconTextExt(MaterialIconKind kind, double size) : base(kind, size) { } | ||
|
||
public double Spacing { get; set; } = 5; | ||
|
||
public Orientation Orientation { get; set; } = Orientation.Horizontal; | ||
|
||
public string? Text { get; set; } | ||
|
||
public bool TextFirst { get; set; } = false; | ||
|
||
protected override object ProvideValue(IXamlServiceProvider serviceProvider) { | ||
var icon = (Control)base.ProvideValue(serviceProvider); | ||
|
||
if (string.IsNullOrWhiteSpace(Text)) return icon; | ||
|
||
var textBlock = new TextBlock { | ||
Text = Text, | ||
HorizontalAlignment = HorizontalAlignment.Center, | ||
VerticalAlignment = VerticalAlignment.Center, | ||
}; | ||
|
||
if (Size.HasValue) textBlock.FontSize = Size.Value; | ||
|
||
return new StackPanel { | ||
Orientation = Orientation, | ||
Spacing = Spacing, | ||
Children = { | ||
TextFirst ? textBlock : icon, | ||
TextFirst ? icon : textBlock | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters