Merge pull request #204 from zumero/button-images

Button images in Ooui.Forms
This commit is contained in:
Frank A. Krueger 2019-01-05 12:07:06 -06:00 committed by GitHub
commit 5700c3bd59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 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,9 +32,14 @@ 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 {
get => this["border-top-color"]; get => this["border-top-color"];
set => this["border-top-color"] = value; set => this["border-top-color"] = value;
@ -425,7 +430,13 @@ namespace Ooui
} }
return o.ToString (); return o.ToString ();
} }
static string AddUrl(object val)
{
if (val == null)
return null;
return String.Format("url('{0}')", val);
}
static string AddNumberUnits (object val, string units) static string AddNumberUnits (object val, string units)
{ {
if (val == null) if (val == null)