Merge pull request #204 from zumero/button-images
Button images in Ooui.Forms
This commit is contained in:
commit
5700c3bd59
|
@ -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 ()
|
||||
|
|
|
@ -32,7 +32,12 @@ 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 {
|
||||
|
@ -425,6 +430,12 @@ namespace Ooui
|
|||
}
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue