Use standard colors for all controls
This commit is contained in:
parent
900a0095c8
commit
010982b08a
|
@ -76,7 +76,7 @@ namespace Ooui.Forms.Cells
|
|||
|
||||
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)
|
||||
|
|
|
@ -20,8 +20,8 @@ namespace Ooui.Forms.Cells
|
|||
|
||||
nativeTextCell.TextLabel.Text = textCell.Text ?? string.Empty;
|
||||
nativeTextCell.DetailTextLabel.Text = textCell.Detail ?? string.Empty;
|
||||
nativeTextCell.TextLabel.Style.Color = textCell.TextColor.ToOouiColor();
|
||||
nativeTextCell.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor();
|
||||
nativeTextCell.TextLabel.Style.Color = textCell.TextColor.ToOouiColor(OouiTheme.TextColor);
|
||||
nativeTextCell.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor(OouiTheme.SecondaryTextColor);
|
||||
|
||||
WireUpForceUpdateSizeRequested(item, nativeTextCell);
|
||||
|
||||
|
@ -40,9 +40,9 @@ namespace Ooui.Forms.Cells
|
|||
else if (args.PropertyName == TextCell.DetailProperty.PropertyName)
|
||||
tvc.DetailTextLabel.Text = textCell.Detail ?? string.Empty;
|
||||
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)
|
||||
tvc.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor();
|
||||
tvc.DetailTextLabel.Style.Color = textCell.DetailColor.ToOouiColor(OouiTheme.SecondaryTextColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,31 +4,27 @@ namespace Ooui.Forms.Extensions
|
|||
{
|
||||
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;
|
||||
const byte defaultGreen = 0;
|
||||
const byte defaultBlue = 0;
|
||||
const byte defaultAlpha = 255;
|
||||
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);
|
||||
byte r = (byte)(color.R * 255.0 + 0.5);
|
||||
byte g = (byte)(color.G * 255.0 + 0.5);
|
||||
byte b = (byte)(color.B * 255.0 + 0.5);
|
||||
byte a = (byte)(color.A * 255.0 + 0.5);
|
||||
return new Color (r, g, b, a);
|
||||
}
|
||||
|
||||
public static Color ToOouiColor (this Xamarin.Forms.Color color, Xamarin.Forms.Color defaultColor)
|
||||
{
|
||||
if (color == Xamarin.Forms.Color.Default)
|
||||
return defaultColor.ToOouiColor ();
|
||||
return color.ToOouiColor ();
|
||||
return ToOouiColor (ref defaultColor);
|
||||
return ToOouiColor (ref color);
|
||||
}
|
||||
|
||||
public static Color ToOouiColor (this Xamarin.Forms.Color color, Ooui.Color defaultColor)
|
||||
{
|
||||
if (color == Xamarin.Forms.Color.Default)
|
||||
return defaultColor;
|
||||
return color.ToOouiColor ();
|
||||
return ToOouiColor (ref color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -29,11 +29,7 @@ namespace Ooui.Forms.Renderers
|
|||
if (Element == null)
|
||||
return;
|
||||
|
||||
var elementColor = Element.Color;
|
||||
if (!elementColor.IsDefault)
|
||||
_colorToRenderer = elementColor.ToOouiColor ();
|
||||
else
|
||||
_colorToRenderer = Colors.Clear;
|
||||
_colorToRenderer = Element.Color.ToOouiColor (Colors.Clear);
|
||||
|
||||
Style.BackgroundColor = _colorToRenderer;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace Ooui.Forms.Renderers
|
|||
var button = Element;
|
||||
|
||||
if (button.BorderColor != Xamarin.Forms.Color.Default)
|
||||
uiButton.Style.BorderColor = button.BorderColor.ToOouiColor ();
|
||||
uiButton.Style.BorderColor = button.BorderColor.ToOouiColor (OouiTheme.ButtonBorderColor);
|
||||
else
|
||||
uiButton.Style.BorderColor = null;
|
||||
|
||||
|
@ -149,12 +149,7 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
void UpdateTextColor ()
|
||||
{
|
||||
if (Element.TextColor == Xamarin.Forms.Color.Default) {
|
||||
Control.Style.Color = null;
|
||||
}
|
||||
else {
|
||||
Control.Style.Color = Element.TextColor.ToOouiColor ();
|
||||
}
|
||||
Control.Style.Color = Element.TextColor.ToOouiColor (OouiTheme.ButtonTextColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,12 +126,7 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
void UpdateTextColor ()
|
||||
{
|
||||
var textColor = Element.TextColor;
|
||||
|
||||
if (textColor.IsDefault)
|
||||
Control.Style.Color = "black";
|
||||
else
|
||||
Control.Style.Color = textColor.ToOouiColor ();
|
||||
Control.Style.Color = Element.TextColor.ToOouiColor (OouiTheme.TextColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace Ooui.Forms.Renderers
|
|||
{
|
||||
public class EntryRenderer : ViewRenderer<Entry, Ooui.TextInput>
|
||||
{
|
||||
Ooui.Color _defaultTextColor;
|
||||
bool _disposed;
|
||||
|
||||
static Size initialSize = Size.Zero;
|
||||
|
@ -72,8 +71,6 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
textField.ClassName = "form-control";
|
||||
|
||||
_defaultTextColor = Colors.Black;
|
||||
|
||||
textField.Input += OnEditingChanged;
|
||||
textField.Change += OnEditingEnded;
|
||||
}
|
||||
|
@ -151,12 +148,7 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
void UpdateColor ()
|
||||
{
|
||||
var textColor = Element.TextColor;
|
||||
|
||||
if (textColor.IsDefault || !Element.IsEnabled)
|
||||
Control.Style.Color = _defaultTextColor;
|
||||
else
|
||||
Control.Style.Color = textColor.ToOouiColor ();
|
||||
Control.Style.Color = Element.TextColor.ToOouiColor (OouiTheme.TextColor);
|
||||
}
|
||||
|
||||
void UpdateFont ()
|
||||
|
|
|
@ -37,10 +37,7 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
Layer.BorderRadius = cornerRadius;
|
||||
|
||||
if (Element.BackgroundColor == Xamarin.Forms.Color.Default)
|
||||
Layer.BackgroundColor = "white";
|
||||
else
|
||||
Layer.BackgroundColor = Element.BackgroundColor.ToOouiColor ();
|
||||
Layer.BackgroundColor = Element.BackgroundColor.ToOouiColor (OouiTheme.BackgroundColor);
|
||||
|
||||
if (Element.HasShadow) {
|
||||
//Layer.ShadowRadius = 5;
|
||||
|
@ -52,10 +49,13 @@ namespace Ooui.Forms.Renderers
|
|||
//Layer.ShadowOpacity = 0;
|
||||
}
|
||||
|
||||
if (Element.OutlineColor == Xamarin.Forms.Color.Default)
|
||||
if (Element.OutlineColor == Xamarin.Forms.Color.Default) {
|
||||
Layer.BorderColor = Colors.Clear;
|
||||
Layer.BorderWidth = 1;
|
||||
Layer.BorderStyle = "none";
|
||||
}
|
||||
else {
|
||||
Layer.BorderColor = Element.OutlineColor.ToOouiColor ();
|
||||
Layer.BorderColor = Element.OutlineColor.ToOouiColor (Colors.Clear);
|
||||
Layer.BorderWidth = 1;
|
||||
Layer.BorderStyle = "solid";
|
||||
}
|
||||
|
|
|
@ -97,10 +97,7 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
protected override void SetBackgroundColor (Xamarin.Forms.Color color)
|
||||
{
|
||||
if (color == Xamarin.Forms.Color.Default)
|
||||
Style.BackgroundColor = Colors.Clear;
|
||||
else
|
||||
Style.BackgroundColor = color.ToOouiColor();
|
||||
Style.BackgroundColor = color.ToOouiColor (Colors.Clear);
|
||||
}
|
||||
|
||||
void UpdateAlignment ()
|
||||
|
|
|
@ -100,10 +100,7 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
protected override void SetBackgroundColor (Xamarin.Forms.Color color)
|
||||
{
|
||||
if (color == Xamarin.Forms.Color.Default)
|
||||
Style.BackgroundColor = Colors.Clear;
|
||||
else
|
||||
Style.BackgroundColor = color.ToOouiColor ();
|
||||
Style.BackgroundColor = color.ToOouiColor (Colors.Clear);
|
||||
}
|
||||
|
||||
void UpdateHRef ()
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
private void UpdateBackgroundColor()
|
||||
{
|
||||
var backgroundColor = Element.BackgroundColor.ToOouiColor();
|
||||
var backgroundColor = Element.BackgroundColor.ToOouiColor(Colors.Clear);
|
||||
|
||||
_select.Style.BackgroundColor = backgroundColor;
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ namespace Ooui.Forms.Renderers
|
|||
|
||||
public class ViewRenderer<TElement, TNativeElement> : VisualElementRenderer<TElement> where TElement : View where TNativeElement : Ooui.Element
|
||||
{
|
||||
Color _defaultColor;
|
||||
|
||||
public TNativeElement Control { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -85,15 +83,11 @@ namespace Ooui.Forms.Renderers
|
|||
if (Control == null)
|
||||
return;
|
||||
|
||||
if (color == Xamarin.Forms.Color.Default)
|
||||
Control.Style.BackgroundColor = _defaultColor;
|
||||
else
|
||||
Control.Style.BackgroundColor = color.ToOouiColor ();
|
||||
Control.Style.BackgroundColor = color.ToOouiColor (OouiTheme.BackgroundColor);
|
||||
}
|
||||
|
||||
protected void SetNativeControl (Ooui.Element element)
|
||||
{
|
||||
_defaultColor = Color.FromStyleValue (element.Style.BackgroundColor);
|
||||
Control = (TNativeElement)element;
|
||||
|
||||
if (Element.BackgroundColor != Xamarin.Forms.Color.Default)
|
||||
|
|
|
@ -18,8 +18,6 @@ namespace Ooui.Forms
|
|||
{
|
||||
bool disposedValue = false; // To detect redundant calls
|
||||
|
||||
readonly Color _defaultColor = Colors.Clear;
|
||||
|
||||
readonly PropertyChangedEventHandler _propertyChangedHandler;
|
||||
|
||||
public TElement Element { get; private set; }
|
||||
|
@ -158,10 +156,7 @@ namespace Ooui.Forms
|
|||
|
||||
protected virtual void SetBackgroundColor (Xamarin.Forms.Color color)
|
||||
{
|
||||
if (color == Xamarin.Forms.Color.Default)
|
||||
Style.BackgroundColor = _defaultColor;
|
||||
else
|
||||
Style.BackgroundColor = color.ToOouiColor ();
|
||||
Style.BackgroundColor = color.ToOouiColor (Colors.Clear);
|
||||
}
|
||||
|
||||
protected virtual void UpdateNativeWidget ()
|
||||
|
|
|
@ -17,6 +17,14 @@ namespace Ooui
|
|||
A = a;
|
||||
}
|
||||
|
||||
public Color (byte r, byte g, byte b)
|
||||
{
|
||||
R = r;
|
||||
G = g;
|
||||
B = b;
|
||||
A = 0xFF;
|
||||
}
|
||||
|
||||
public double Red {
|
||||
get => R / 255.0;
|
||||
set => R = value >= 1.0 ? (byte)255 : ((value <= 0.0) ? (byte)0 : (byte)(value * 255.0 + 0.5));
|
||||
|
|
Loading…
Reference in New Issue