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); Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style);
} }
void UpdateImage () async void UpdateImage ()
{ {
//IImageSourceHandler handler; IImageSourceHandler handler;
//FileImageSource source = Element.Image; 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);
// 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); var Button = Control;
// } if (Button != null && uiimage != null)
//} {
//else { Button.Style.BackgroundImage = uiimage;
// Control.SetImage (null, UIControlState.Normal); Button.Style.BackgroundPosition = "center";
// ClearEdgeInsets (Control); }
//} }
//((IVisualElementController)Element).NativeSizeChanged (); else
{
Control.Style.BackgroundImage = null;
Control.Style.BackgroundPosition = null;
}
((IVisualElementController)Element).NativeSizeChanged ();
} }
void UpdateText () void UpdateText ()

View File

@ -32,7 +32,12 @@ namespace Ooui
public Value BackgroundImage { public Value BackgroundImage {
get => this["background-image"]; 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 { public Value BorderTopColor {
@ -425,6 +430,10 @@ namespace Ooui
} }
return o.ToString (); return o.ToString ();
} }
static string AddUrl(object val)
{
return String.Format("url('{0}')", val);
}
static string AddNumberUnits (object val, string units) static string AddNumberUnits (object val, string units)
{ {