Add FrameRenderer
This commit is contained in:
parent
33e1a65f59
commit
4f047d1e85
|
@ -11,6 +11,7 @@ using Xamarin.Forms.Internals;
|
||||||
[assembly: ExportRenderer (typeof (DatePicker), typeof (DatePickerRenderer))]
|
[assembly: ExportRenderer (typeof (DatePicker), typeof (DatePickerRenderer))]
|
||||||
[assembly: ExportRenderer (typeof (Editor), typeof (EditorRenderer))]
|
[assembly: ExportRenderer (typeof (Editor), typeof (EditorRenderer))]
|
||||||
[assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))]
|
[assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))]
|
||||||
|
[assembly: ExportRenderer (typeof (Frame), typeof (FrameRenderer))]
|
||||||
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
|
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
|
||||||
[assembly: ExportRenderer (typeof (ProgressBar), typeof (ProgressBarRenderer))]
|
[assembly: ExportRenderer (typeof (ProgressBar), typeof (ProgressBarRenderer))]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Ooui.Forms.Extensions;
|
||||||
|
|
||||||
|
namespace Ooui.Forms.Renderers
|
||||||
|
{
|
||||||
|
public class FrameRenderer : VisualElementRenderer<Frame>
|
||||||
|
{
|
||||||
|
protected override void OnElementChanged (ElementChangedEventArgs<Frame> e)
|
||||||
|
{
|
||||||
|
base.OnElementChanged (e);
|
||||||
|
|
||||||
|
if (e.NewElement != null)
|
||||||
|
SetupLayer ();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnElementPropertyChanged (sender, e);
|
||||||
|
|
||||||
|
if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName ||
|
||||||
|
e.PropertyName == Xamarin.Forms.Frame.OutlineColorProperty.PropertyName ||
|
||||||
|
e.PropertyName == Xamarin.Forms.Frame.HasShadowProperty.PropertyName ||
|
||||||
|
e.PropertyName == Xamarin.Forms.Frame.CornerRadiusProperty.PropertyName)
|
||||||
|
SetupLayer ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetupLayer ()
|
||||||
|
{
|
||||||
|
float cornerRadius = Element.CornerRadius;
|
||||||
|
|
||||||
|
if (cornerRadius == -1f)
|
||||||
|
cornerRadius = 5f; // default corner radius
|
||||||
|
|
||||||
|
var Layer = this.Style;
|
||||||
|
|
||||||
|
Layer.BorderRadius = cornerRadius;
|
||||||
|
|
||||||
|
if (Element.BackgroundColor == Xamarin.Forms.Color.Default)
|
||||||
|
Layer.BackgroundColor = "white";
|
||||||
|
else
|
||||||
|
Layer.BackgroundColor = Element.BackgroundColor.ToOouiColor ();
|
||||||
|
|
||||||
|
if (Element.HasShadow) {
|
||||||
|
//Layer.ShadowRadius = 5;
|
||||||
|
//Layer.ShadowColor = "black";
|
||||||
|
//Layer.ShadowOpacity = 0.8f;
|
||||||
|
//Layer.ShadowOffset = new SizeF ();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Layer.ShadowOpacity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Element.OutlineColor == Xamarin.Forms.Color.Default)
|
||||||
|
Layer.BorderColor = Colors.Clear;
|
||||||
|
else {
|
||||||
|
Layer.BorderColor = Element.OutlineColor.ToOouiColor ();
|
||||||
|
Layer.BorderWidth = 1;
|
||||||
|
Layer.BorderStyle = "solid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,38 +93,38 @@ namespace Ooui
|
||||||
|
|
||||||
public Value BorderTopWidth {
|
public Value BorderTopWidth {
|
||||||
get => this["border-top-width"];
|
get => this["border-top-width"];
|
||||||
set => this["border-top-width"] = value;
|
set => this["border-top-width"] = AddNumberUnits (value, "px");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value BorderRightWidth {
|
public Value BorderRightWidth {
|
||||||
get => this["border-right-width"];
|
get => this["border-right-width"];
|
||||||
set => this["border-right-width"] = value;
|
set => this["border-right-width"] = AddNumberUnits (value, "px");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value BorderBottomWidth {
|
public Value BorderBottomWidth {
|
||||||
get => this["border-bottom-width"];
|
get => this["border-bottom-width"];
|
||||||
set => this["border-bottom-width"] = value;
|
set => this["border-bottom-width"] = AddNumberUnits (value, "px");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value BorderLeftWidth {
|
public Value BorderLeftWidth {
|
||||||
get => this["border-left-width"];
|
get => this["border-left-width"];
|
||||||
set => this["border-left-width"] = value;
|
set => this["border-left-width"] = AddNumberUnits (value, "px");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value BorderRadius {
|
public Value BorderRadius {
|
||||||
get => this["border-radius"];
|
get => this["border-radius"];
|
||||||
set {
|
set {
|
||||||
this["border-radius"] = value;
|
this["border-radius"] = AddNumberUnits (value, "px");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value BorderWidth {
|
public Value BorderWidth {
|
||||||
get => this["border-top-width"];
|
get => this["border-top-width"];
|
||||||
set {
|
set {
|
||||||
this["border-top-width"] = value;
|
this["border-top-width"] = AddNumberUnits (value, "px");
|
||||||
this["border-right-width"] = value;
|
this["border-right-width"] = AddNumberUnits (value, "px");
|
||||||
this["border-bottom-width"] = value;
|
this["border-bottom-width"] = AddNumberUnits (value, "px");
|
||||||
this["border-left-width"] = value;
|
this["border-left-width"] = AddNumberUnits (value, "px");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,6 +403,8 @@ namespace Ooui
|
||||||
|
|
||||||
static string AddNumberUnits (object val, string units)
|
static string AddNumberUnits (object val, string units)
|
||||||
{
|
{
|
||||||
|
if (val == null)
|
||||||
|
return null;
|
||||||
if (val is string s)
|
if (val is string s)
|
||||||
return s;
|
return s;
|
||||||
if (val is IConvertible c)
|
if (val is IConvertible c)
|
||||||
|
|
Loading…
Reference in New Issue