protected object ConvertValue(object value, object parameter)
        {
            AssetPlugin plugin = value as AssetPlugin;

            if (plugin == null)
            {
                plugin = (AssetPlugin)MvvmCross.Mvx.IoCProvider.Resolve <IAssetPlugin>();
            }

            if (parameter != null)
            {
                try{
                    string fontName = parameter.ToString();

                    //if a string is bound, could be a color name, add it
                    if (value is string && !string.IsNullOrEmpty((string)value))
                    {
                        fontName = $"{fontName}:{value}";
                    }

                    var font = plugin.GetFontByName(fontName);
                    return(font);
                }catch (Exception e) {
                    MvxPluginLog.Instance.Error(e, $"Failed to get font {e.Message}");
                }
            }

            return(null);
        }
        public void PlatformSizeIsModifiedByFontSizeFactor()
        {
            AssetPlugin plugin = new TestAssetPlugin();

            AssetPlugin.GetPlatformFontSize(10.0f).Should().Be(10.0f);

            AssetPlugin.FontSizeFactor = 2.0f;
            AssetPlugin.GetPlatformFontSize(10.0f).Should().Be(20.0f);
        }
Esempio n. 3
0
            public PluginTreeNode(AssetPlugin plugin)
                : base(plugin)
            {
                AlexandriaPlugin aplugin = plugin as AlexandriaPlugin;

                if (aplugin != null)
                {
                    CreateSubnode(this, aplugin.Engines);
                    CreateSubnode(this, aplugin.Games, null);
                }

                CreateSubnode(this, plugin.Formats);
            }
Esempio n. 4
0
        //TODO generic possible?
        public static UIFont GetCachedFont(IBaseFont font)
        {
            if (!_fontsCache.ContainsKey(font.Name))
            {
                if (font.Size == default(int))
                {
                    font.Size = 16;
                }
                _fontsCache[font.Name] = UIFont.FromName(font.FontPlatformName, AssetPlugin.GetPlatformFontSize(font.Size));
            }

            return(_fontsCache[font.Name]);
        }
Esempio n. 5
0
        protected override void SetValueImpl(object target, object toSet)
        {
            var  label = (TextView)target;
            Font font  = toSet as Font;

            if (font != null)
            {
                try
                {
                    Typeface droidFont = DroidAssetPlugin.GetCachedFont(font, label.Context);
                    label.SetTypeface(droidFont, new TypefaceStyle());

                    float fontSize;
                    if (font.Size != default(int))
                    {
                        fontSize = AssetPlugin.GetPlatformFontSize(font.Size);
                        label.SetTextSize(Android.Util.ComplexUnitType.Dip, fontSize);
                    }
                    else
                    {
                        fontSize = label.TextSize;
                    }

                    if (font.Color != System.Drawing.Color.Empty)
                    {
                        label.SetTextColor(font.Color.ToNativeColor());
                    }

                    var multiplierFactor = AssetPlugin.LineHeightFactor ?? 1;

                    var lineHeight = DroidAssetPlugin.GetPlatformLineHeight(font.Size, font.LineHeight * multiplierFactor);

                    var lineSpacingMultiplier = font.LineHeightMultiplier.HasValue ? font.LineHeightMultiplier.Value : 1;

                    label.SetLineSpacing(lineHeight, lineSpacingMultiplier);

                    if (font.Alignment != TextAlignment.None)
                    {
                        label.Gravity = font.ToNativeAlignment();
                    }
                }
                catch
                {
                    MvxBindingLog.Instance.Error("Failed to set font to Textview. Check if font exists, has a size and filename");
                }
            }
        }
Esempio n. 6
0
        protected override void SetValueImpl(object target, object toSet)
        {
            var  button = (Button)target;
            Font font   = toSet as Font;

            if (font != null)
            {
                try {
                    Typeface droidFont = DroidAssetPlugin.GetCachedFont(font, button.Context);
                    button.SetTypeface(droidFont, new TypefaceStyle());
                    if (font.Size != default(int))
                    {
                        button.SetTextSize(Android.Util.ComplexUnitType.Dip, AssetPlugin.GetPlatformFontSize(font.Size));
                    }
                    if (font.Color != System.Drawing.Color.Empty)
                    {
                        List <int[]> states = new List <int[]>();
                        List <int>   colors = new List <int>();

                        //if there's only a disabled color
                        if (font.DisabledColor != System.Drawing.Color.Empty)
                        {
                            if (font.SelectedColor == null)
                            {
                                states.Add(new int[] { Android.Resource.Attribute.StateEnabled });
                                states.Add(new int[] { -Android.Resource.Attribute.StateEnabled });
                            }

                            colors.Add(font.Color.ToArgb());
                            colors.Add(font.DisabledColor.ToArgb());
                        }

                        if (font.SelectedColor != System.Drawing.Color.Empty)
                        {
                            if (font.DisabledColor == null)
                            {
                                states.Add(new int[] { Android.Resource.Attribute.StateActivated });
                                states.Add(new int[] { -Android.Resource.Attribute.StateActivated });
                            }
                            colors.Add(font.SelectedColor.ToArgb());
                            colors.Add(font.Color.ToArgb());
                        }

                        //if both disabled color and activated color are available
                        if (font.DisabledColor != System.Drawing.Color.Empty && font.SelectedColor != System.Drawing.Color.Empty)
                        {
                            states.Add(new int[] { Android.Resource.Attribute.StateEnabled, -Android.Resource.Attribute.StateActivated });
                            states.Add(new int[] { -Android.Resource.Attribute.StateEnabled, -Android.Resource.Attribute.StateActivated });
                            states.Add(new int[] { Android.Resource.Attribute.StateEnabled, Android.Resource.Attribute.StateActivated });
                            states.Add(new int[] { -Android.Resource.Attribute.StateEnabled, Android.Resource.Attribute.StateActivated });
                        }

                        if (states.Count > 0)
                        {
                            button.SetTextColor(new ColorStateList(states.ToArray(), colors.ToArray()));
                        }
                        else
                        {
                            button.SetTextColor(font.Color.ToNativeColor());
                        }
                    }
                }
                catch
                {
                    MvxBindingLog.Instance.Error("Failed to set font to Button. Check if font exists, has a size and filename");
                }
            }
        }