Use standard colors for all controls

This commit is contained in:
Frank A. Krueger 2018-04-25 22:23:26 -07:00
parent 900a0095c8
commit 010982b08a
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
15 changed files with 51 additions and 72 deletions

View File

@ -76,7 +76,7 @@ namespace Ooui.Forms.Cells
private static void UpdateLabelColor(CellView cell, EntryCell entryCell) private static void UpdateLabelColor(CellView cell, EntryCell entryCell)
{ {
cell.TextLabel.Style.Color = entryCell.LabelColor.ToOouiColor(); cell.TextLabel.Style.Color = entryCell.LabelColor.ToOouiColor(OouiTheme.TextColor);
} }
private static void UpdatePlaceholder(CellView cell, EntryCell entryCell) private static void UpdatePlaceholder(CellView cell, EntryCell entryCell)

View File

@ -20,8 +20,8 @@ namespace Ooui.Forms.Cells
nativeTextCell.TextLabel.Text = textCell.Text ?? string.Empty; nativeTextCell.TextLabel.Text = textCell.Text ?? string.Empty;
nativeTextCell.DetailTextLabel.Text = textCell.Detail ?? string.Empty; nativeTextCell.DetailTextLabel.Text = textCell.Detail ?? string.Empty;
nativeTextCell.TextLabel.Style.Color = textCell.TextColor.ToOouiColor(); nativeTextCell.TextLabel.Style.Color = textCell.TextColor.ToOouiColor(OouiTheme.TextColor);
nativeTextCell.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor(); nativeTextCell.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor(OouiTheme.SecondaryTextColor);
WireUpForceUpdateSizeRequested(item, nativeTextCell); WireUpForceUpdateSizeRequested(item, nativeTextCell);
@ -40,9 +40,9 @@ namespace Ooui.Forms.Cells
else if (args.PropertyName == TextCell.DetailProperty.PropertyName) else if (args.PropertyName == TextCell.DetailProperty.PropertyName)
tvc.DetailTextLabel.Text = textCell.Detail ?? string.Empty; tvc.DetailTextLabel.Text = textCell.Detail ?? string.Empty;
else if (args.PropertyName == TextCell.TextColorProperty.PropertyName) else if (args.PropertyName == TextCell.TextColorProperty.PropertyName)
tvc.TextLabel.Style.Color = textCell.TextColor.ToOouiColor(); tvc.TextLabel.Style.Color = textCell.TextColor.ToOouiColor(OouiTheme.TextColor);
else if (args.PropertyName == TextCell.DetailColorProperty.PropertyName) else if (args.PropertyName == TextCell.DetailColorProperty.PropertyName)
tvc.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor(); tvc.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor(OouiTheme.SecondaryTextColor);
} }
} }
} }

View File

@ -4,31 +4,27 @@ namespace Ooui.Forms.Extensions
{ {
public static class ColorExtensions public static class ColorExtensions
{ {
public static Color ToOouiColor (this Xamarin.Forms.Color color) static Color ToOouiColor (ref Xamarin.Forms.Color color)
{ {
const byte defaultRed = 0; byte r = (byte)(color.R * 255.0 + 0.5);
const byte defaultGreen = 0; byte g = (byte)(color.G * 255.0 + 0.5);
const byte defaultBlue = 0; byte b = (byte)(color.B * 255.0 + 0.5);
const byte defaultAlpha = 255; byte a = (byte)(color.A * 255.0 + 0.5);
byte r = color.R < 0 ? defaultRed : (byte)(color.R * 255.0 + 0.5);
byte g = color.G < 0 ? defaultGreen : (byte)(color.G * 255.0 + 0.5);
byte b = color.B < 0 ? defaultBlue : (byte)(color.B * 255.0 + 0.5);
byte a = color.A < 0 ? defaultAlpha : (byte)(color.A * 255.0 + 0.5);
return new Color (r, g, b, a); return new Color (r, g, b, a);
} }
public static Color ToOouiColor (this Xamarin.Forms.Color color, Xamarin.Forms.Color defaultColor) public static Color ToOouiColor (this Xamarin.Forms.Color color, Xamarin.Forms.Color defaultColor)
{ {
if (color == Xamarin.Forms.Color.Default) if (color == Xamarin.Forms.Color.Default)
return defaultColor.ToOouiColor (); return ToOouiColor (ref defaultColor);
return color.ToOouiColor (); return ToOouiColor (ref color);
} }
public static Color ToOouiColor (this Xamarin.Forms.Color color, Ooui.Color defaultColor) public static Color ToOouiColor (this Xamarin.Forms.Color color, Ooui.Color defaultColor)
{ {
if (color == Xamarin.Forms.Color.Default) if (color == Xamarin.Forms.Color.Default)
return defaultColor; return defaultColor;
return color.ToOouiColor (); return ToOouiColor (ref color);
} }
} }
} }

14
Ooui.Forms/OouiTheme.cs Normal file
View File

@ -0,0 +1,14 @@
using System;
namespace Ooui.Forms
{
public static class OouiTheme
{
public static readonly Color BackgroundColor = new Color (0xFF, 0xFF, 0xFF, 0xFF);
public static readonly Color TextColor = new Color (0x0, 0x0, 0x0, 0xFF);
public static readonly Color SecondaryTextColor = new Color (119, 119, 119, 0xFF);
public static readonly Color ButtonBackgroundColor = new Color (51, 122, 183, 0xFF);
public static readonly Color ButtonBorderColor = new Color (46, 109, 164, 0xFF);
public static readonly Color ButtonTextColor = new Color (0xFF, 0xFF, 0xFF, 0xFF);
}
}

View File

@ -29,11 +29,7 @@ namespace Ooui.Forms.Renderers
if (Element == null) if (Element == null)
return; return;
var elementColor = Element.Color; _colorToRenderer = Element.Color.ToOouiColor (Colors.Clear);
if (!elementColor.IsDefault)
_colorToRenderer = elementColor.ToOouiColor ();
else
_colorToRenderer = Colors.Clear;
Style.BackgroundColor = _colorToRenderer; Style.BackgroundColor = _colorToRenderer;
} }

View File

@ -84,7 +84,7 @@ namespace Ooui.Forms.Renderers
var button = Element; var button = Element;
if (button.BorderColor != Xamarin.Forms.Color.Default) if (button.BorderColor != Xamarin.Forms.Color.Default)
uiButton.Style.BorderColor = button.BorderColor.ToOouiColor (); uiButton.Style.BorderColor = button.BorderColor.ToOouiColor (OouiTheme.ButtonBorderColor);
else else
uiButton.Style.BorderColor = null; uiButton.Style.BorderColor = null;
@ -149,12 +149,7 @@ namespace Ooui.Forms.Renderers
void UpdateTextColor () void UpdateTextColor ()
{ {
if (Element.TextColor == Xamarin.Forms.Color.Default) { Control.Style.Color = Element.TextColor.ToOouiColor (OouiTheme.ButtonTextColor);
Control.Style.Color = null;
}
else {
Control.Style.Color = Element.TextColor.ToOouiColor ();
}
} }
} }
} }

View File

@ -126,12 +126,7 @@ namespace Ooui.Forms.Renderers
void UpdateTextColor () void UpdateTextColor ()
{ {
var textColor = Element.TextColor; Control.Style.Color = Element.TextColor.ToOouiColor (OouiTheme.TextColor);
if (textColor.IsDefault)
Control.Style.Color = "black";
else
Control.Style.Color = textColor.ToOouiColor ();
} }
} }
} }

View File

@ -8,7 +8,6 @@ namespace Ooui.Forms.Renderers
{ {
public class EntryRenderer : ViewRenderer<Entry, Ooui.TextInput> public class EntryRenderer : ViewRenderer<Entry, Ooui.TextInput>
{ {
Ooui.Color _defaultTextColor;
bool _disposed; bool _disposed;
static Size initialSize = Size.Zero; static Size initialSize = Size.Zero;
@ -72,8 +71,6 @@ namespace Ooui.Forms.Renderers
textField.ClassName = "form-control"; textField.ClassName = "form-control";
_defaultTextColor = Colors.Black;
textField.Input += OnEditingChanged; textField.Input += OnEditingChanged;
textField.Change += OnEditingEnded; textField.Change += OnEditingEnded;
} }
@ -151,12 +148,7 @@ namespace Ooui.Forms.Renderers
void UpdateColor () void UpdateColor ()
{ {
var textColor = Element.TextColor; Control.Style.Color = Element.TextColor.ToOouiColor (OouiTheme.TextColor);
if (textColor.IsDefault || !Element.IsEnabled)
Control.Style.Color = _defaultTextColor;
else
Control.Style.Color = textColor.ToOouiColor ();
} }
void UpdateFont () void UpdateFont ()

View File

@ -37,10 +37,7 @@ namespace Ooui.Forms.Renderers
Layer.BorderRadius = cornerRadius; Layer.BorderRadius = cornerRadius;
if (Element.BackgroundColor == Xamarin.Forms.Color.Default) Layer.BackgroundColor = Element.BackgroundColor.ToOouiColor (OouiTheme.BackgroundColor);
Layer.BackgroundColor = "white";
else
Layer.BackgroundColor = Element.BackgroundColor.ToOouiColor ();
if (Element.HasShadow) { if (Element.HasShadow) {
//Layer.ShadowRadius = 5; //Layer.ShadowRadius = 5;
@ -52,10 +49,13 @@ namespace Ooui.Forms.Renderers
//Layer.ShadowOpacity = 0; //Layer.ShadowOpacity = 0;
} }
if (Element.OutlineColor == Xamarin.Forms.Color.Default) if (Element.OutlineColor == Xamarin.Forms.Color.Default) {
Layer.BorderColor = Colors.Clear; Layer.BorderColor = Colors.Clear;
Layer.BorderWidth = 1;
Layer.BorderStyle = "none";
}
else { else {
Layer.BorderColor = Element.OutlineColor.ToOouiColor (); Layer.BorderColor = Element.OutlineColor.ToOouiColor (Colors.Clear);
Layer.BorderWidth = 1; Layer.BorderWidth = 1;
Layer.BorderStyle = "solid"; Layer.BorderStyle = "solid";
} }

View File

@ -97,10 +97,7 @@ namespace Ooui.Forms.Renderers
protected override void SetBackgroundColor (Xamarin.Forms.Color color) protected override void SetBackgroundColor (Xamarin.Forms.Color color)
{ {
if (color == Xamarin.Forms.Color.Default) Style.BackgroundColor = color.ToOouiColor (Colors.Clear);
Style.BackgroundColor = Colors.Clear;
else
Style.BackgroundColor = color.ToOouiColor();
} }
void UpdateAlignment () void UpdateAlignment ()

View File

@ -100,10 +100,7 @@ namespace Ooui.Forms.Renderers
protected override void SetBackgroundColor (Xamarin.Forms.Color color) protected override void SetBackgroundColor (Xamarin.Forms.Color color)
{ {
if (color == Xamarin.Forms.Color.Default) Style.BackgroundColor = color.ToOouiColor (Colors.Clear);
Style.BackgroundColor = Colors.Clear;
else
Style.BackgroundColor = color.ToOouiColor ();
} }
void UpdateHRef () void UpdateHRef ()

View File

@ -64,7 +64,7 @@ namespace Ooui.Forms.Renderers
private void UpdateBackgroundColor() private void UpdateBackgroundColor()
{ {
var backgroundColor = Element.BackgroundColor.ToOouiColor(); var backgroundColor = Element.BackgroundColor.ToOouiColor(Colors.Clear);
_select.Style.BackgroundColor = backgroundColor; _select.Style.BackgroundColor = backgroundColor;
} }

View File

@ -11,8 +11,6 @@ namespace Ooui.Forms.Renderers
public class ViewRenderer<TElement, TNativeElement> : VisualElementRenderer<TElement> where TElement : View where TNativeElement : Ooui.Element public class ViewRenderer<TElement, TNativeElement> : VisualElementRenderer<TElement> where TElement : View where TNativeElement : Ooui.Element
{ {
Color _defaultColor;
public TNativeElement Control { get; private set; } public TNativeElement Control { get; private set; }
/// <summary> /// <summary>
@ -85,15 +83,11 @@ namespace Ooui.Forms.Renderers
if (Control == null) if (Control == null)
return; return;
if (color == Xamarin.Forms.Color.Default) Control.Style.BackgroundColor = color.ToOouiColor (OouiTheme.BackgroundColor);
Control.Style.BackgroundColor = _defaultColor;
else
Control.Style.BackgroundColor = color.ToOouiColor ();
} }
protected void SetNativeControl (Ooui.Element element) protected void SetNativeControl (Ooui.Element element)
{ {
_defaultColor = Color.FromStyleValue (element.Style.BackgroundColor);
Control = (TNativeElement)element; Control = (TNativeElement)element;
if (Element.BackgroundColor != Xamarin.Forms.Color.Default) if (Element.BackgroundColor != Xamarin.Forms.Color.Default)

View File

@ -18,8 +18,6 @@ namespace Ooui.Forms
{ {
bool disposedValue = false; // To detect redundant calls bool disposedValue = false; // To detect redundant calls
readonly Color _defaultColor = Colors.Clear;
readonly PropertyChangedEventHandler _propertyChangedHandler; readonly PropertyChangedEventHandler _propertyChangedHandler;
public TElement Element { get; private set; } public TElement Element { get; private set; }
@ -158,10 +156,7 @@ namespace Ooui.Forms
protected virtual void SetBackgroundColor (Xamarin.Forms.Color color) protected virtual void SetBackgroundColor (Xamarin.Forms.Color color)
{ {
if (color == Xamarin.Forms.Color.Default) Style.BackgroundColor = color.ToOouiColor (Colors.Clear);
Style.BackgroundColor = _defaultColor;
else
Style.BackgroundColor = color.ToOouiColor ();
} }
protected virtual void UpdateNativeWidget () protected virtual void UpdateNativeWidget ()

View File

@ -17,6 +17,14 @@ namespace Ooui
A = a; A = a;
} }
public Color (byte r, byte g, byte b)
{
R = r;
G = g;
B = b;
A = 0xFF;
}
public double Red { public double Red {
get => R / 255.0; get => R / 255.0;
set => R = value >= 1.0 ? (byte)255 : ((value <= 0.0) ? (byte)0 : (byte)(value * 255.0 + 0.5)); set => R = value >= 1.0 ? (byte)255 : ((value <= 0.0) ? (byte)0 : (byte)(value * 255.0 + 0.5));