category management
This commit is contained in:
@ -8,6 +8,7 @@ namespace Billing.UI
|
||||
public BillingPage()
|
||||
{
|
||||
SetDynamicResource(BackgroundColorProperty, BaseTheme.WindowBackgroundColor);
|
||||
Shell.SetTabBarIsVisible(this, false);
|
||||
}
|
||||
}
|
||||
}
|
137
Billing.Shared/UI/ColorPicker.cs
Normal file
137
Billing.Shared/UI/ColorPicker.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using SkiaSharp;
|
||||
using SkiaSharp.Views.Forms;
|
||||
using System;
|
||||
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Billing.UI
|
||||
{
|
||||
public class ColorPicker : SKCanvasView
|
||||
{
|
||||
public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Color), typeof(ColorPicker));
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get => (Color)GetValue(ColorProperty);
|
||||
set => SetValue(ColorProperty, value);
|
||||
}
|
||||
|
||||
public event EventHandler<Color> ColorChanged;
|
||||
|
||||
private SKPoint? lastTouch;
|
||||
|
||||
public ColorPicker()
|
||||
{
|
||||
EnableTouchEvents = true;
|
||||
}
|
||||
|
||||
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
|
||||
{
|
||||
base.OnPaintSurface(e);
|
||||
var skInfo = e.Info;
|
||||
var skSurface = e.Surface;
|
||||
var skCanvas = skSurface.Canvas;
|
||||
|
||||
var width = skInfo.Width;
|
||||
var height = skInfo.Height;
|
||||
|
||||
skCanvas.Clear(SKColors.White);
|
||||
|
||||
using (var paint = new SKPaint())
|
||||
{
|
||||
paint.IsAntialias = true;
|
||||
var colors = new SKColor[]
|
||||
{
|
||||
new SKColor(255, 0, 0), // Red
|
||||
new SKColor(255, 255, 0), // Yellow
|
||||
new SKColor(0, 255, 0), // Green (Lime)
|
||||
new SKColor(0, 255, 255), // Aqua
|
||||
new SKColor(0, 0, 255), // Blue
|
||||
new SKColor(255, 0, 255), // Fuchsia
|
||||
new SKColor(255, 0, 0), // Red
|
||||
};
|
||||
|
||||
using var shader = SKShader.CreateLinearGradient(
|
||||
new SKPoint(0, 0),
|
||||
new SKPoint(width, 0),
|
||||
colors,
|
||||
null,
|
||||
SKShaderTileMode.Clamp);
|
||||
paint.Shader = shader;
|
||||
skCanvas.DrawPaint(paint);
|
||||
}
|
||||
|
||||
using (var paint = new SKPaint())
|
||||
{
|
||||
paint.IsAntialias = true;
|
||||
var colors = new SKColor[]
|
||||
{
|
||||
SKColors.Transparent,
|
||||
SKColors.Black
|
||||
};
|
||||
using var shader = SKShader.CreateLinearGradient(
|
||||
new SKPoint(0, 0),
|
||||
new SKPoint(0, height),
|
||||
colors,
|
||||
null,
|
||||
SKShaderTileMode.Clamp);
|
||||
paint.Shader = shader;
|
||||
skCanvas.DrawPaint(paint);
|
||||
}
|
||||
|
||||
if (lastTouch != null)
|
||||
{
|
||||
var touch = lastTouch.Value;
|
||||
SKColor touchColor;
|
||||
using (SKBitmap bitmap = new(skInfo))
|
||||
{
|
||||
IntPtr dstPixels = bitmap.GetPixels();
|
||||
skSurface.ReadPixels(
|
||||
skInfo,
|
||||
dstPixels,
|
||||
skInfo.RowBytes,
|
||||
(int)touch.X, (int)touch.Y);
|
||||
touchColor = bitmap.GetPixel(0, 0);
|
||||
}
|
||||
|
||||
using (SKPaint paintTouch = new())
|
||||
{
|
||||
paintTouch.Style = SKPaintStyle.Fill;
|
||||
paintTouch.Color = SKColors.White;
|
||||
paintTouch.IsAntialias = true;
|
||||
|
||||
skCanvas.DrawCircle(
|
||||
touch.X,
|
||||
touch.Y,
|
||||
18,
|
||||
paintTouch);
|
||||
|
||||
paintTouch.Color = touchColor;
|
||||
skCanvas.DrawCircle(
|
||||
touch.X,
|
||||
touch.Y,
|
||||
12,
|
||||
paintTouch);
|
||||
}
|
||||
|
||||
var color = touchColor.ToFormsColor();
|
||||
Color = color;
|
||||
ColorChanged?.Invoke(this, color);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnTouch(SKTouchEventArgs e)
|
||||
{
|
||||
base.OnTouch(e);
|
||||
lastTouch = e.Location;
|
||||
|
||||
var size = CanvasSize;
|
||||
if ((e.Location.X > 0 && e.Location.X < size.Width) &&
|
||||
(e.Location.Y > 0 && e.Location.Y < size.Height))
|
||||
{
|
||||
e.Handled = true;
|
||||
InvalidateSurface();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -217,4 +217,21 @@ namespace Billing.UI
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class SelectBackgroundColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool b && b)
|
||||
{
|
||||
return Application.Current.Resources[BaseTheme.PromptBackgroundColor];
|
||||
}
|
||||
return default(Color);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Billing.UI
|
||||
{
|
||||
public class ItemSelectPage<T> : ContentPage
|
||||
public class ItemSelectPage<T> : BillingPage
|
||||
{
|
||||
public event EventHandler<T> ItemTapped;
|
||||
|
||||
|
@ -190,6 +190,7 @@ namespace Billing.UI
|
||||
public class OptionImageCell : OptionSelectCell
|
||||
{
|
||||
public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create(nameof(ImageSource), typeof(ImageSource), typeof(OptionImageCell));
|
||||
public static readonly BindableProperty TintColorProperty = BindableProperty.Create(nameof(TintColor), typeof(Color?), typeof(OptionImageCell));
|
||||
|
||||
[TypeConverter(typeof(ImageSourceConverter))]
|
||||
public ImageSource ImageSource
|
||||
@ -197,6 +198,12 @@ namespace Billing.UI
|
||||
get => (ImageSource)GetValue(ImageSourceProperty);
|
||||
set => SetValue(ImageSourceProperty, value);
|
||||
}
|
||||
[TypeConverter(typeof(ColorTypeConverter))]
|
||||
public Color? TintColor
|
||||
{
|
||||
get => (Color?)GetValue(TintColorProperty);
|
||||
set => SetValue(TintColorProperty, value);
|
||||
}
|
||||
|
||||
protected override View Content => new StackLayout
|
||||
{
|
||||
@ -211,7 +218,8 @@ namespace Billing.UI
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
Margin = new Thickness(6, 0)
|
||||
}
|
||||
.Binding(Image.SourceProperty, nameof(ImageSource)),
|
||||
.Binding(Image.SourceProperty, nameof(ImageSource))
|
||||
.Binding(TintImage.PrimaryColorProperty, nameof(TintColor)),
|
||||
|
||||
new TintImage
|
||||
{
|
||||
|
Reference in New Issue
Block a user