DatePicker completed
This commit is contained in:
@@ -23,6 +23,7 @@ public partial class DatePickerHandler : ViewHandler<IDatePicker, SkiaDatePicker
|
|||||||
[nameof(IDatePicker.Format)] = MapFormat,
|
[nameof(IDatePicker.Format)] = MapFormat,
|
||||||
[nameof(IDatePicker.TextColor)] = MapTextColor,
|
[nameof(IDatePicker.TextColor)] = MapTextColor,
|
||||||
[nameof(IDatePicker.CharacterSpacing)] = MapCharacterSpacing,
|
[nameof(IDatePicker.CharacterSpacing)] = MapCharacterSpacing,
|
||||||
|
[nameof(ITextStyle.Font)] = MapFont,
|
||||||
[nameof(IView.Background)] = MapBackground,
|
[nameof(IView.Background)] = MapBackground,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,7 +111,27 @@ public partial class DatePickerHandler : ViewHandler<IDatePicker, SkiaDatePicker
|
|||||||
|
|
||||||
public static void MapCharacterSpacing(DatePickerHandler handler, IDatePicker datePicker)
|
public static void MapCharacterSpacing(DatePickerHandler handler, IDatePicker datePicker)
|
||||||
{
|
{
|
||||||
// Character spacing would require custom text rendering
|
if (handler.PlatformView is null) return;
|
||||||
|
handler.PlatformView.CharacterSpacing = datePicker.CharacterSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MapFont(DatePickerHandler handler, IDatePicker datePicker)
|
||||||
|
{
|
||||||
|
if (handler.PlatformView is null) return;
|
||||||
|
|
||||||
|
var font = datePicker.Font;
|
||||||
|
if (font.Size > 0)
|
||||||
|
handler.PlatformView.FontSize = font.Size;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(font.Family))
|
||||||
|
handler.PlatformView.FontFamily = font.Family;
|
||||||
|
|
||||||
|
// Map FontAttributes from the Font weight/slant
|
||||||
|
var attrs = FontAttributes.None;
|
||||||
|
if (font.Weight >= FontWeight.Bold)
|
||||||
|
attrs |= FontAttributes.Bold;
|
||||||
|
// Note: Font.Slant for italic would require checking FontSlant
|
||||||
|
handler.PlatformView.FontAttributes = attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MapBackground(DatePickerHandler handler, IDatePicker datePicker)
|
public static void MapBackground(DatePickerHandler handler, IDatePicker datePicker)
|
||||||
|
|||||||
@@ -61,10 +61,22 @@ public class SkiaDatePicker : SkiaView
|
|||||||
BindableProperty.Create(nameof(DisabledDayColor), typeof(Color), typeof(SkiaDatePicker), Color.FromRgb(189, 189, 189), BindingMode.TwoWay,
|
BindableProperty.Create(nameof(DisabledDayColor), typeof(Color), typeof(SkiaDatePicker), Color.FromRgb(189, 189, 189), BindingMode.TwoWay,
|
||||||
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).Invalidate());
|
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).Invalidate());
|
||||||
|
|
||||||
|
public static readonly BindableProperty FontFamilyProperty =
|
||||||
|
BindableProperty.Create(nameof(FontFamily), typeof(string), typeof(SkiaDatePicker), string.Empty, BindingMode.TwoWay,
|
||||||
|
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).Invalidate());
|
||||||
|
|
||||||
public static readonly BindableProperty FontSizeProperty =
|
public static readonly BindableProperty FontSizeProperty =
|
||||||
BindableProperty.Create(nameof(FontSize), typeof(double), typeof(SkiaDatePicker), 14.0, BindingMode.TwoWay,
|
BindableProperty.Create(nameof(FontSize), typeof(double), typeof(SkiaDatePicker), 14.0, BindingMode.TwoWay,
|
||||||
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).InvalidateMeasure());
|
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).InvalidateMeasure());
|
||||||
|
|
||||||
|
public static readonly BindableProperty FontAttributesProperty =
|
||||||
|
BindableProperty.Create(nameof(FontAttributes), typeof(FontAttributes), typeof(SkiaDatePicker), FontAttributes.None, BindingMode.TwoWay,
|
||||||
|
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).Invalidate());
|
||||||
|
|
||||||
|
public static readonly BindableProperty CharacterSpacingProperty =
|
||||||
|
BindableProperty.Create(nameof(CharacterSpacing), typeof(double), typeof(SkiaDatePicker), 0.0, BindingMode.TwoWay,
|
||||||
|
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).Invalidate());
|
||||||
|
|
||||||
public static readonly BindableProperty CornerRadiusProperty =
|
public static readonly BindableProperty CornerRadiusProperty =
|
||||||
BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(SkiaDatePicker), 4.0, BindingMode.TwoWay,
|
BindableProperty.Create(nameof(CornerRadius), typeof(double), typeof(SkiaDatePicker), 4.0, BindingMode.TwoWay,
|
||||||
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).Invalidate());
|
propertyChanged: (b, o, n) => ((SkiaDatePicker)b).Invalidate());
|
||||||
@@ -150,12 +162,30 @@ public class SkiaDatePicker : SkiaView
|
|||||||
set => SetValue(DisabledDayColorProperty, value);
|
set => SetValue(DisabledDayColorProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string FontFamily
|
||||||
|
{
|
||||||
|
get => (string)GetValue(FontFamilyProperty);
|
||||||
|
set => SetValue(FontFamilyProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public double FontSize
|
public double FontSize
|
||||||
{
|
{
|
||||||
get => (double)GetValue(FontSizeProperty);
|
get => (double)GetValue(FontSizeProperty);
|
||||||
set => SetValue(FontSizeProperty, value);
|
set => SetValue(FontSizeProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FontAttributes FontAttributes
|
||||||
|
{
|
||||||
|
get => (FontAttributes)GetValue(FontAttributesProperty);
|
||||||
|
set => SetValue(FontAttributesProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double CharacterSpacing
|
||||||
|
{
|
||||||
|
get => (double)GetValue(CharacterSpacingProperty);
|
||||||
|
set => SetValue(CharacterSpacingProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public double CornerRadius
|
public double CornerRadius
|
||||||
{
|
{
|
||||||
get => (double)GetValue(CornerRadiusProperty);
|
get => (double)GetValue(CornerRadiusProperty);
|
||||||
@@ -305,7 +335,33 @@ public class SkiaDatePicker : SkiaView
|
|||||||
canvas.DrawRoundRect(new SKRoundRect(bounds, cornerRadius), borderPaint);
|
canvas.DrawRoundRect(new SKRoundRect(bounds, cornerRadius), borderPaint);
|
||||||
|
|
||||||
SKColor textColor = ToSKColor(TextColor);
|
SKColor textColor = ToSKColor(TextColor);
|
||||||
using var font = new SKFont(SKTypeface.Default, fontSize, 1f, 0f);
|
|
||||||
|
// Get typeface based on FontFamily and FontAttributes
|
||||||
|
SKTypeface typeface = SKTypeface.Default;
|
||||||
|
if (!string.IsNullOrEmpty(FontFamily))
|
||||||
|
{
|
||||||
|
var style = FontAttributes switch
|
||||||
|
{
|
||||||
|
FontAttributes.Bold => SKFontStyle.Bold,
|
||||||
|
FontAttributes.Italic => SKFontStyle.Italic,
|
||||||
|
FontAttributes.Bold | FontAttributes.Italic => SKFontStyle.BoldItalic,
|
||||||
|
_ => SKFontStyle.Normal
|
||||||
|
};
|
||||||
|
typeface = SKTypeface.FromFamilyName(FontFamily, style) ?? SKTypeface.Default;
|
||||||
|
}
|
||||||
|
else if (FontAttributes != FontAttributes.None)
|
||||||
|
{
|
||||||
|
var style = FontAttributes switch
|
||||||
|
{
|
||||||
|
FontAttributes.Bold => SKFontStyle.Bold,
|
||||||
|
FontAttributes.Italic => SKFontStyle.Italic,
|
||||||
|
FontAttributes.Bold | FontAttributes.Italic => SKFontStyle.BoldItalic,
|
||||||
|
_ => SKFontStyle.Normal
|
||||||
|
};
|
||||||
|
typeface = SKTypeface.FromFamilyName(null, style) ?? SKTypeface.Default;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var font = new SKFont(typeface, fontSize, 1f, 0f);
|
||||||
using var textPaint = new SKPaint(font)
|
using var textPaint = new SKPaint(font)
|
||||||
{
|
{
|
||||||
Color = IsEnabled ? textColor : textColor.WithAlpha(128),
|
Color = IsEnabled ? textColor : textColor.WithAlpha(128),
|
||||||
|
|||||||
Reference in New Issue
Block a user