-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few enhancements to the base types (#115)
- Loading branch information
1 parent
707125d
commit e73ab52
Showing
15 changed files
with
151 additions
and
98 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
40 changes: 40 additions & 0 deletions
40
samples/Forms/SkiaSharpDemo/Views/OptionButtons/OptionButtonsResources.xaml
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,40 @@ | ||
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://xamarin.com/schemas/2014/forms/design" | ||
xmlns:views="clr-namespace:SkiaSharpDemo.Views" | ||
mc:Ignorable="d" | ||
x:Class="SkiaSharpDemo.Views.OptionButtonsResources"> | ||
|
||
<Style x:Key="OptionButtonStyle" TargetType="Button"> | ||
<Setter Property="CornerRadius" Value="3" /> | ||
<Setter Property="VisualStateManager.VisualStateGroups"> | ||
<VisualStateGroupList> | ||
<VisualStateGroup x:Name="CommonStates"> | ||
<VisualState x:Name="Normal" /> | ||
<VisualState x:Name="Pressed"> | ||
<VisualState.Setters> | ||
<Setter Property="Scale" Value="0.8" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
<VisualStateGroup x:Name="SelectedStates"> | ||
<VisualState x:Name="Unselected" /> | ||
<VisualState x:Name="Selected"> | ||
<VisualState.Setters> | ||
<Setter Property="BorderColor" Value="Black" /> | ||
<Setter Property="BorderWidth" Value="3" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateGroupList> | ||
</Setter> | ||
</Style> | ||
|
||
<Style x:Key="TextOptionButtonStyle" TargetType="Button" BasedOn="{StaticResource OptionButtonStyle}"> | ||
<Setter Property="BackgroundColor" Value="Accent" /> | ||
<Setter Property="TextColor" Value="White" /> | ||
<Setter Property="Padding" Value="24,12" /> | ||
</Style> | ||
|
||
</ResourceDictionary> |
12 changes: 12 additions & 0 deletions
12
samples/Forms/SkiaSharpDemo/Views/OptionButtons/OptionButtonsResources.xaml.cs
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,12 @@ | ||
using Xamarin.Forms; | ||
|
||
namespace SkiaSharpDemo.Views | ||
{ | ||
public partial class OptionButtonsResources : ResourceDictionary | ||
{ | ||
public OptionButtonsResources() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
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
9 changes: 0 additions & 9 deletions
9
source/SkiaSharp.Extended.UI.Forms/Controls/ExtendedTypeConverter.shared.cs
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
source/SkiaSharp.Extended.UI.Forms/Controls/StringTypeConverter.shared.cs
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,18 @@ | ||
namespace SkiaSharp.Extended.UI.Controls.Converters; | ||
|
||
public abstract class StringTypeConverter : TypeConverter | ||
{ | ||
internal StringTypeConverter() | ||
{ | ||
} | ||
|
||
public override object? ConvertFromInvariantString(string? value) => | ||
ConvertFromStringCore(value); | ||
|
||
public override string? ConvertToInvariantString(object? value) => | ||
ConvertToStringCore(value); | ||
|
||
protected abstract object? ConvertFromStringCore(string? value); | ||
|
||
protected virtual string? ConvertToStringCore(object? value) => throw new NotImplementedException(); | ||
} |
20 changes: 0 additions & 20 deletions
20
source/SkiaSharp.Extended.UI.Maui/Controls/ExtendedTypeConverter.cs
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
source/SkiaSharp.Extended.UI.Maui/Controls/StringTypeConverter.shared.cs
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,26 @@ | ||
using System.Globalization; | ||
|
||
namespace SkiaSharp.Extended.UI.Controls.Converters; | ||
|
||
public abstract class StringTypeConverter : TypeConverter | ||
{ | ||
internal StringTypeConverter() | ||
{ | ||
} | ||
|
||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) => | ||
sourceType == typeof(string); | ||
|
||
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType) => | ||
destinationType == typeof(string); | ||
|
||
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) => | ||
ConvertFromStringCore(value?.ToString()); | ||
|
||
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) => | ||
ConvertToStringCore(value); | ||
|
||
protected abstract object? ConvertFromStringCore(string? value); | ||
|
||
protected virtual string? ConvertToStringCore(object? value) => throw new NotImplementedException(); | ||
} |
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
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
30 changes: 30 additions & 0 deletions
30
source/SkiaSharp.Extended.UI/Utils/ResourceLoader.shared.cs
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,30 @@ | ||
namespace SkiaSharp.Extended.UI; | ||
|
||
internal static class ResourceLoader | ||
{ | ||
internal static void EnsureRegistered<T>(ref bool registered) | ||
where T : ResourceDictionary, new() | ||
{ | ||
if (registered) | ||
return; | ||
|
||
var merged = Application.Current?.Resources?.MergedDictionaries; | ||
if (merged != null) | ||
{ | ||
foreach (var dic in merged) | ||
{ | ||
if (dic.GetType() == typeof(T)) | ||
{ | ||
registered = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!registered) | ||
{ | ||
merged.Add(new T()); | ||
registered = true; | ||
} | ||
} | ||
} | ||
} |