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);
|
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 ()
|
||||||
|
|
|
@ -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,12 @@ 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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue