Implemented button images as background images.

This commit is contained in:
Troy Stanger 2018-11-07 10:33:51 -06:00
parent a75d44b573
commit 7d1cf22fb6
2 changed files with 39 additions and 25 deletions

View File

@ -110,32 +110,37 @@ namespace Ooui.Forms.Renderers
Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style);
}
void UpdateImage ()
async void UpdateImage ()
{
//IImageSourceHandler handler;
//FileImageSource source = Element.Image;
//if (source != null && (handler = Internals.Registrar.Registered.GetHandlerForObject<IImageSourceHandler> (source)) != null) {
// UIImage uiimage;
// try {
// uiimage = await handler.LoadImageAsync (source, scale: (float)UIScreen.MainScreen.Scale);
// }
// catch (OperationCanceledException) {
// uiimage = null;
// }
// Ooui.Button button = Control;
// if (button != null && uiimage != null) {
// button.SetImage (uiimage.ImageWithRenderingMode (UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
IImageSourceHandler handler;
FileImageSource source = Element.Image;
// button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
if (source != null &&
(handler = Xamarin.Forms.Internals.Registrar.Registered.GetHandler<IImageSourceHandler>(source.GetType())) != null)
{
string uiimage;
try
{
uiimage = await handler.LoadImageAsync(source, scale: 1.0f);
}
catch (OperationCanceledException)
{
uiimage = null;
}
// ComputeEdgeInsets (Control, Element.ContentLayout);
// }
//}
//else {
// Control.SetImage (null, UIControlState.Normal);
// ClearEdgeInsets (Control);
//}
//((IVisualElementController)Element).NativeSizeChanged ();
var Button = Control;
if (Button != null && uiimage != null)
{
Button.Style.BackgroundImage = uiimage;
Button.Style.BackgroundPosition = "center";
}
}
else
{
Control.Style.BackgroundImage = null;
Control.Style.BackgroundPosition = null;
}
((IVisualElementController)Element).NativeSizeChanged ();
}
void UpdateText ()

View File

@ -32,9 +32,14 @@ namespace Ooui
public Value BackgroundImage {
get => this["background-image"];
set => this["background-image"] = value;
set => this["background-image"] = AddUrl(value);
}
public Value BackgroundPosition {
get => this["background-position"];
set => this["background-position"] = value;
}
public Value BorderTopColor {
get => this["border-top-color"];
set => this["border-top-color"] = value;
@ -425,7 +430,11 @@ namespace Ooui
}
return o.ToString ();
}
static string AddUrl(object val)
{
return String.Format("url('{0}')", val);
}
static string AddNumberUnits (object val, string units)
{
if (val == null)