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

Component generator: brushes #56

Merged
merged 2 commits into from
Oct 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using AC = AlohaKit.Controls;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui.Graphics;
using System.Threading.Tasks;

Expand All @@ -19,13 +21,19 @@ public partial class Avatar : BlazorBindings.Maui.Elements.GraphicsView
{
static Avatar()
{
ElementHandlerRegistry.RegisterPropertyContentHandler<Avatar>(nameof(Background),
(renderer, parent, component) => new ContentPropertyHandler<AC.Avatar>((x, value) => x.Background = (MC.Brush)value));
ElementHandlerRegistry.RegisterPropertyContentHandler<Avatar>(nameof(Fill),
(renderer, parent, component) => new ContentPropertyHandler<AC.Avatar>((x, value) => x.Fill = (MC.Brush)value));
RegisterAdditionalHandlers();
}

[Parameter] public AC.AvatarSize? AvatarSize { get; set; }
[Parameter] public Color FillColor { get; set; }
[Parameter] public string Name { get; set; }
[Parameter] public AC.AvatarDrawable PersonaDrawable { get; set; }
[Parameter] public Color TextColor { get; set; }
[Parameter] public RenderFragment Fill { get; set; }

public new AC.Avatar NativeControl => (AC.Avatar)((Element)this).NativeControl;

Expand All @@ -42,6 +50,13 @@ protected override void HandleParameter(string name, object value)
NativeControl.AvatarSize = AvatarSize ?? (AC.AvatarSize)AC.Avatar.AvatarSizeProperty.DefaultValue;
}
break;
case nameof(FillColor):
if (!Equals(FillColor, value))
{
FillColor = (Color)value;
NativeControl.Fill = FillColor;
}
break;
case nameof(Name):
if (!Equals(Name, value))
{
Expand All @@ -63,13 +78,26 @@ protected override void HandleParameter(string name, object value)
NativeControl.TextColor = TextColor;
}
break;
case nameof(Background):
Background = (RenderFragment)value;
break;
case nameof(Fill):
Fill = (RenderFragment)value;
break;

default:
base.HandleParameter(name, value);
break;
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(Avatar), Background);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(Avatar), Fill);
}

static partial void RegisterAdditionalHandlers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using AC = AlohaKit.Controls;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui;
using Microsoft.Maui.Graphics;
using System;
Expand All @@ -21,6 +23,10 @@ public partial class Button : BlazorBindings.Maui.Elements.GraphicsView
{
static Button()
{
ElementHandlerRegistry.RegisterPropertyContentHandler<Button>(nameof(Background),
(renderer, parent, component) => new ContentPropertyHandler<AC.Button>((x, value) => x.Background = (MC.Brush)value));
ElementHandlerRegistry.RegisterPropertyContentHandler<Button>(nameof(Stroke),
(renderer, parent, component) => new ContentPropertyHandler<AC.Button>((x, value) => x.Stroke = (MC.Brush)value));
RegisterAdditionalHandlers();
}

Expand All @@ -29,10 +35,12 @@ static Button()
[Parameter] public bool? HasShadow { get; set; }
[Parameter] public TextAlignment? HorizontalTextAlignment { get; set; }
[Parameter] public Color ShadowColor { get; set; }
[Parameter] public Color StrokeColor { get; set; }
[Parameter] public double? StrokeThickness { get; set; }
[Parameter] public string Text { get; set; }
[Parameter] public Color TextColor { get; set; }
[Parameter] public TextAlignment? VerticalTextAlignment { get; set; }
[Parameter] public RenderFragment Stroke { get; set; }
[Parameter] public EventCallback OnPress { get; set; }
[Parameter] public EventCallback OnRelease { get; set; }
[Parameter] public EventCallback OnClick { get; set; }
Expand Down Expand Up @@ -80,6 +88,13 @@ protected override void HandleParameter(string name, object value)
NativeControl.ShadowColor = ShadowColor;
}
break;
case nameof(StrokeColor):
if (!Equals(StrokeColor, value))
{
StrokeColor = (Color)value;
NativeControl.Stroke = StrokeColor;
}
break;
case nameof(StrokeThickness):
if (!Equals(StrokeThickness, value))
{
Expand Down Expand Up @@ -108,6 +123,12 @@ protected override void HandleParameter(string name, object value)
NativeControl.VerticalTextAlignment = VerticalTextAlignment ?? (TextAlignment)AC.Button.VerticalTextAlignmentProperty.DefaultValue;
}
break;
case nameof(Background):
Background = (RenderFragment)value;
break;
case nameof(Stroke):
Stroke = (RenderFragment)value;
break;
case nameof(OnPress):
if (!Equals(OnPress, value))
{
Expand Down Expand Up @@ -145,6 +166,13 @@ protected override void HandleParameter(string name, object value)
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(Button), Background);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(Button), Stroke);
}

static partial void RegisterAdditionalHandlers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
using AC = AlohaKit.Controls;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui.Graphics;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements.AlohaKit
Expand All @@ -18,12 +21,24 @@ public partial class CheckBox : BlazorBindings.Maui.Elements.GraphicsView
{
static CheckBox()
{
ElementHandlerRegistry.RegisterPropertyContentHandler<CheckBox>(nameof(CheckedBrush),
(renderer, parent, component) => new ContentPropertyHandler<AC.CheckBox>((x, value) => x.CheckedBrush = (MC.Brush)value));
ElementHandlerRegistry.RegisterPropertyContentHandler<CheckBox>(nameof(Stroke),
(renderer, parent, component) => new ContentPropertyHandler<AC.CheckBox>((x, value) => x.Stroke = (MC.Brush)value));
ElementHandlerRegistry.RegisterPropertyContentHandler<CheckBox>(nameof(UncheckedBrush),
(renderer, parent, component) => new ContentPropertyHandler<AC.CheckBox>((x, value) => x.UncheckedBrush = (MC.Brush)value));
RegisterAdditionalHandlers();
}

[Parameter] public AC.CheckBoxDrawable CheckBoxDrawable { get; set; }
[Parameter] public Color CheckedColor { get; set; }
[Parameter] public bool? IsChecked { get; set; }
[Parameter] public Color StrokeColor { get; set; }
[Parameter] public double? StrokeThickness { get; set; }
[Parameter] public Color UncheckedColor { get; set; }
[Parameter] public RenderFragment CheckedBrush { get; set; }
[Parameter] public RenderFragment Stroke { get; set; }
[Parameter] public RenderFragment UncheckedBrush { get; set; }
[Parameter] public EventCallback<bool> IsCheckedChanged { get; set; }

public new AC.CheckBox NativeControl => (AC.CheckBox)((Element)this).NativeControl;
Expand All @@ -41,20 +56,50 @@ protected override void HandleParameter(string name, object value)
NativeControl.CheckBoxDrawable = CheckBoxDrawable;
}
break;
case nameof(CheckedColor):
if (!Equals(CheckedColor, value))
{
CheckedColor = (Color)value;
NativeControl.CheckedBrush = CheckedColor;
}
break;
case nameof(IsChecked):
if (!Equals(IsChecked, value))
{
IsChecked = (bool?)value;
NativeControl.IsChecked = IsChecked ?? (bool)AC.CheckBox.IsCheckedProperty.DefaultValue;
}
break;
case nameof(StrokeColor):
if (!Equals(StrokeColor, value))
{
StrokeColor = (Color)value;
NativeControl.Stroke = StrokeColor;
}
break;
case nameof(StrokeThickness):
if (!Equals(StrokeThickness, value))
{
StrokeThickness = (double?)value;
NativeControl.StrokeThickness = StrokeThickness ?? (double)AC.CheckBox.StrokeThicknessProperty.DefaultValue;
}
break;
case nameof(UncheckedColor):
if (!Equals(UncheckedColor, value))
{
UncheckedColor = (Color)value;
NativeControl.UncheckedBrush = UncheckedColor;
}
break;
case nameof(CheckedBrush):
CheckedBrush = (RenderFragment)value;
break;
case nameof(Stroke):
Stroke = (RenderFragment)value;
break;
case nameof(UncheckedBrush):
UncheckedBrush = (RenderFragment)value;
break;
case nameof(IsCheckedChanged):
if (!Equals(IsCheckedChanged, value))
{
Expand All @@ -77,6 +122,14 @@ void NativeControlCheckedChanged(object sender, MC.CheckedChangedEventArgs e)
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(CheckBox), CheckedBrush);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(CheckBox), Stroke);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(CheckBox), UncheckedBrush);
}

static partial void RegisterAdditionalHandlers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
using AC = AlohaKit.Controls;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui.Graphics;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements.AlohaKit
Expand All @@ -18,11 +21,15 @@ public partial class HorizontalProgressBar : BlazorBindings.Maui.Elements.Graphi
{
static HorizontalProgressBar()
{
ElementHandlerRegistry.RegisterPropertyContentHandler<HorizontalProgressBar>(nameof(ProgressBrush),
(renderer, parent, component) => new ContentPropertyHandler<AC.HorizontalProgressBar>((x, value) => x.ProgressBrush = (MC.Brush)value));
RegisterAdditionalHandlers();
}

[Parameter] public double? Progress { get; set; }
[Parameter] public AC.HorizontalProgressBarDrawable ProgressBarDrawable { get; set; }
[Parameter] public Color ProgressColor { get; set; }
[Parameter] public RenderFragment ProgressBrush { get; set; }

public new AC.HorizontalProgressBar NativeControl => (AC.HorizontalProgressBar)((Element)this).NativeControl;

Expand All @@ -46,13 +53,29 @@ protected override void HandleParameter(string name, object value)
NativeControl.ProgressBarDrawable = ProgressBarDrawable;
}
break;
case nameof(ProgressColor):
if (!Equals(ProgressColor, value))
{
ProgressColor = (Color)value;
NativeControl.ProgressBrush = ProgressColor;
}
break;
case nameof(ProgressBrush):
ProgressBrush = (RenderFragment)value;
break;

default:
base.HandleParameter(name, value);
break;
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(HorizontalProgressBar), ProgressBrush);
}

static partial void RegisterAdditionalHandlers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using AC = AlohaKit.Controls;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui.Graphics;
using System.Threading.Tasks;

Expand All @@ -19,6 +21,8 @@ public partial class NumericUpDown : BlazorBindings.Maui.Elements.GraphicsView
{
static NumericUpDown()
{
ElementHandlerRegistry.RegisterPropertyContentHandler<NumericUpDown>(nameof(Background),
(renderer, parent, component) => new ContentPropertyHandler<AC.NumericUpDown>((x, value) => x.Background = (MC.Brush)value));
RegisterAdditionalHandlers();
}

Expand Down Expand Up @@ -96,6 +100,9 @@ protected override void HandleParameter(string name, object value)
NativeControl.Value = Value ?? (double)AC.NumericUpDown.ValueProperty.DefaultValue;
}
break;
case nameof(Background):
Background = (RenderFragment)value;
break;
case nameof(ValueChanged):
if (!Equals(ValueChanged, value))
{
Expand All @@ -118,6 +125,12 @@ void NativeControlValueChanged(object sender, MC.ValueChangedEventArgs e)
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(NumericUpDown), Background);
}

static partial void RegisterAdditionalHandlers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using AC = AlohaKit.Controls;
using BlazorBindings.Core;
using BlazorBindings.Maui.Elements;
using BlazorBindings.Maui.Elements.Handlers;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui.Graphics;
using System;
using System.Threading.Tasks;
Expand All @@ -20,6 +22,8 @@ public partial class PulseIcon : BlazorBindings.Maui.Elements.GraphicsView
{
static PulseIcon()
{
ElementHandlerRegistry.RegisterPropertyContentHandler<PulseIcon>(nameof(Background),
(renderer, parent, component) => new ContentPropertyHandler<AC.PulseIcon>((x, value) => x.Background = (MC.Brush)value));
RegisterAdditionalHandlers();
}

Expand Down Expand Up @@ -65,6 +69,9 @@ protected override void HandleParameter(string name, object value)
NativeControl.Source = Source;
}
break;
case nameof(Background):
Background = (RenderFragment)value;
break;
case nameof(OnClick):
if (!Equals(OnClick, value))
{
Expand All @@ -82,6 +89,12 @@ protected override void HandleParameter(string name, object value)
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddContentProperty(builder, sequence++, typeof(PulseIcon), Background);
}

static partial void RegisterAdditionalHandlers();
}
}
Loading