Пример #1
0
        private void UpdateText()
        {
#if USE_FASTRENDERERS
            TextChanged -= OnTextChanged;

            var icon = Iconize.FindIconForKey(Label.Text);
            if (!(icon is null))
            {
                Text     = $"{icon.Character}";
                Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context);
            }

            TextChanged += OnTextChanged;
#else
            if (!(Control is null))
            {
                Control.TextChanged -= OnTextChanged;

                var icon = Iconize.FindIconForKey(Label.Text);
                if (!(icon is null))
                {
                    Control.Text     = $"{icon.Character}";
                    Control.Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context);
                }

                Control.TextChanged += OnTextChanged;
            }
#endif
        }
Пример #2
0
        /// <summary>
        /// Updates the image.
        /// </summary>
        private void UpdateImage()
        {
            var iconImage = Element as IconImage;

            var icon = Iconize.FindIconForKey(iconImage.Icon);

            if (icon is null)
            {
                Control.Layer.Contents = null;
                return;
            }

            if (Element.HeightRequest < 0)
            {
                Element.HeightRequest = iconImage.IconSize;
            }

            var iconSize = (iconImage.IconSize > 0 ? (nfloat)iconImage.IconSize : (nfloat)Element.HeightRequest);

            if (iconSize < 0)
            {
                throw new ArgumentException("The icon size is under zero !");
            }

            using (var image = icon.ToNSImageWithColor(iconSize, iconImage.IconColor.ToCGColor()))
            {
                Control.Layer.Contents = image.CGImage;
            }
        }
Пример #3
0
        /// <summary>
        /// Updates the tabbed icons.
        /// </summary>
        private void UpdateTabbedIcons(Context context)
        {
            var tabLayout = FindViewById <TabLayout>(Iconize.TabLayoutId);

            if (tabLayout == null || tabLayout.TabCount == 0)
            {
                return;
            }

            for (var i = 0; i < tabLayout.TabCount; i++)
            {
                var tab = tabLayout.GetTabAt(i);

                if (_icons != null && i < _icons.Count)
                {
                    var iconKey = _icons[i];

                    var icon = Iconize.FindIconForKey(iconKey);
                    if (icon == null)
                    {
                        continue;
                    }

                    var drawable = new IconDrawable(context, icon).Color(Color.White.ToAndroid()).SizeDp(20);

                    tab.SetIcon(drawable);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Updates the text.
        /// </summary>
        private void UpdateText()
        {
#if USE_FASTRENDERERS
            TextChanged -= OnTextChanged;
#else
            Control.TextChanged -= OnTextChanged;
#endif

            var icon = Iconize.FindIconForKey(Button.Text);
            if (icon != null)
            {
#if USE_FASTRENDERERS
                Text     = $"{icon.Character}";
                Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context);
#else
                Control.Text     = $"{icon.Character}";
                Control.Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context);
#endif
            }

#if USE_FASTRENDERERS
            TextChanged += OnTextChanged;
#else
            Control.TextChanged += OnTextChanged;
#endif
        }
Пример #5
0
        private void UpdateImage()
        {
            var icon = Iconize.FindIconForKey(Image.Icon);

            if (icon == null)
            {
#if USE_FASTRENDERERS
                SetImageResource(Android.Resource.Color.Transparent);
#else
                Control.SetImageResource(Android.Resource.Color.Transparent);
#endif
                return;
            }

            var iconSize = (Image.IconSize == IconImage.AutoSize ? Math.Max(Image.WidthRequest, Image.HeightRequest) : Image.IconSize);

            var drawable = new IconDrawable(Context, icon).Color(Image.IconColor.ToAndroid())
                           .SizeDp((Int32)iconSize);
#if USE_FASTRENDERERS
            SetScaleType(Image.IconSize > 0 ? ScaleType.Center : ScaleType.FitCenter);
            SetImageDrawable(drawable);
#else
            Control.SetScaleType(Image.IconSize > 0 ? ScaleType.Center : ScaleType.FitCenter);
            Control.SetImageDrawable(drawable);
#endif
        }
Пример #6
0
        /// <summary>
        /// Updates the image.
        /// </summary>
        private void UpdateImage()
        {
            var icon = Iconize.FindIconForKey(Image.Icon);

            if (!(icon is null))
            {
                Control.Source = icon.ToImageSource(Image.IconColor);
            }
        }
Пример #7
0
        /// <summary>
        /// Updates the text.
        /// </summary>
        private void UpdateText()
        {
            var icon = Iconize.FindIconForKey(Element.Text);

            if (!(icon is null))
            {
                Control.Text       = $"{icon.Character}";
                Control.FontFamily = Iconize.FindModuleOf(icon).ToFontFamily();
            }
        }
Пример #8
0
        /// <summary>
        /// Updates the text.
        /// </summary>
        private void UpdateText()
        {
            var icon = Iconize.FindIconForKey(Element.Text);

            if (icon != null)
            {
                Control.Title = $"{icon.Character}";
                Control.Font  = Iconize.FindModuleOf(icon).ToNSFont((nfloat)Element.FontSize);
            }
        }
Пример #9
0
        /// <inheritdoc />
        protected override Task <Tuple <UIImage, UIImage> > GetIcon(Page page)
        {
            var icon = Iconize.FindIconForKey(page.Icon.File);

            if (!(icon is null))
            {
                return(Task.FromResult(Tuple.Create(icon.ToUIImage(25f), (UIImage)null)));
            }

            return(base.GetIcon(page));
        }
Пример #10
0
        /// <summary>
        /// Create an <see cref="IconDrawable" />.
        /// </summary>
        /// <param name="context">Your activity or application context.</param>
        /// <param name="iconKey">The icon key you want this drawable to display.</param>
        /// <exception cref="ArgumentException">If the key doesn't match any icon.</exception>
        public IconDrawable(Context context, String iconKey)
        {
            var icon = Iconize.FindIconForKey(iconKey);

            if (icon == null)
            {
                throw new ArgumentException($"No icon with the key: {iconKey}");
            }

            Init(context, icon);
        }
Пример #11
0
        /// <summary>
        /// Updates the image.
        /// </summary>
        private async Task UpdateImageAsync()
        {
            var icon = Iconize.FindIconForKey(Image.Icon);

            if (!(icon is null))
            {
                var iconSize = (Image.IconSize == IconImage.AutoSize ? Math.Max(Element.WidthRequest, Element.HeightRequest) : Image.IconSize);

                Control.Source = await icon.ToImageSourceAsync((Int32)iconSize, Image.IconColor);
            }
        }
Пример #12
0
        /// <inheritdoc />
        protected override Drawable GetIconDrawable(FileImageSource icon)
        {
            var iconize = Iconize.FindIconForKey(icon.File);

            if (!(iconize is null))
            {
                return(new IconDrawable(Context, icon).SizeDp(20));
            }

            return(base.GetIconDrawable(icon));
        }
Пример #13
0
        /// <inheritdoc />
        protected override void SetTabIcon(TabLayout.Tab tab, FileImageSource icon)
        {
            var iconize = Iconize.FindIconForKey(icon.File);

            if (!(iconize is null))
            {
                var drawable = new IconDrawable(Context, icon).SizeDp(20);
                DrawableCompat.SetTintList(drawable, GetItemIconTintColorState());
                tab.SetIcon(drawable);
                return;
            }

            base.SetTabIcon(tab, icon);
        }
Пример #14
0
        /// <summary>
        /// Updates the text.
        /// </summary>
        private void UpdateText()
        {
            var icon = Iconize.FindIconForKey(Element.Text);

            if (icon != null)
            {
                var font = Iconize.FindModuleOf(icon)?.ToUIFont((nfloat)Element.FontSize);
                if (font != null)
                {
                    Control.SetTitle($"{icon.Character}", UIControlState.Normal);
                    Control.Font = font;
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Updates the text.
        /// </summary>
        private void UpdateText()
        {
            var icon = Iconize.FindIconForKey(Element.Text);

            if (!(icon is null))
            {
                var font = Iconize.FindModuleOf(icon)?.ToUIFont((nfloat)Element.FontSize);
                if (!(font is null))
                {
                    Control.Text = $"{icon.Character}";
                    Control.Font = font;
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Updates the text.
        /// </summary>
        private void UpdateText()
        {
            TextChanged -= OnTextChanged;

            var icon = Iconize.FindIconForKey(Label.Text);

            if (icon != null)
            {
                Text     = $"{icon.Character}";
                Typeface = Iconize.FindModuleOf(icon).ToTypeface(Context);
            }

            TextChanged += OnTextChanged;
        }
Пример #17
0
        /// <summary>
        /// Views the will appear.
        /// </summary>
        public override void ViewWillAppear()
        {
            base.ViewWillAppear();

            for (int i = 0; i < TabView.Items.Length; i++)
            {
                var icon = Iconize.FindIconForKey(_icons?[i]);
                if (icon == null)
                {
                    continue;
                }

                using (var image = icon.ToNSImage(18))
                {
                    TabView.Items[i].Image = image;
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Called prior to the <see cref="P:UIKit.UIViewController.View" /> being added to the view hierarchy.
        /// </summary>
        /// <param name="animated">If the appearance will be animated.</param>
        /// <remarks>
        /// <para>This method is called prior to the <see cref="T:UIKit.UIView" /> that is this <see cref="T:UIKit.UIViewController" />’s <see cref="P:UIKit.UIViewController.View" /> property being added to the display <see cref="T:UIKit.UIView" /> hierarchy. </para>
        /// <para>Application developers who override this method must call <c>base.ViewWillAppear()</c> in their overridden method.</para>
        /// </remarks>
        public override void ViewWillAppear(Boolean animated)
        {
            base.ViewWillAppear(animated);

            foreach (var tab in TabBar.Items)
            {
                var icon = Iconize.FindIconForKey(_icons?[(Int32)tab.Tag]);
                if (icon == null)
                {
                    continue;
                }

                using (var image = icon.ToUIImage(25f))
                {
                    tab.Image         = image;
                    tab.SelectedImage = image;
                }
            }
        }
Пример #19
0
 /// <summary>
 /// Updates the button icon.
 /// </summary>
 /// <param name="button">The button.</param>
 private static void UpdateButtonIcon(AppBarButton button)
 {
     if (button?.DataContext is IconToolbarItem item)
     {
         var icon = Iconize.FindIconForKey(item.Icon);
         if (icon != null)
         {
             button.ClearValue(AppBarButton.IconProperty);
             button.Icon = new FontIcon
             {
                 FontFamily = Iconize.FindModuleOf(icon).ToFontFamily(),
                 Glyph      = $"{icon.Character}"
             };
             if (item.IconColor != default(Color))
             {
                 button.Icon.Foreground = new SolidColorBrush(item.IconColor.ToUIColor());
             }
             button.Visibility = item.IsVisible ? Visibility.Visible : Visibility.Collapsed;
         }
     }
 }
Пример #20
0
        /// <summary>
        /// Updates the image.
        /// </summary>
        /// <param name="shouldUpdateImage">if set to <c>true</c> [should update image].</param>
        private void UpdateImage(Boolean shouldUpdateImage)
        {
            if (shouldUpdateImage)
            {
                Control.ContentMode = (Image.IconSize == IconImage.AutoSize ? UIViewContentMode.ScaleAspectFit : UIViewContentMode.Center);

                var icon = Iconize.FindIconForKey(Image.Icon);
                if (icon == null)
                {
                    Control.Image = null;
                    return;
                }

                var iconSize = (Image.IconSize == IconImage.AutoSize ? Math.Max(Element.WidthRequest, Element.HeightRequest) : Image.IconSize);

                using (var image = icon.ToUIImage((nfloat)iconSize))
                {
                    Control.Image = image;
                }
            }

            Control.TintColor = Image.IconColor.ToUIColor();
        }
Пример #21
0
        /// <summary>
        /// Updates the toolbar items.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="controller">The controller.</param>
        public static void UpdateToolbarItems(this Page page, UINavigationController controller)
        {
            try
            {
                if (page == null || controller == null)
                {
                    return;
                }

                if (controller.IsBeingDismissed)
                {
                    return;
                }

                var navController = controller.VisibleViewController;
                if (navController == null)
                {
                    return;
                }

                if (navController.NavigationItem?.RightBarButtonItems != null)
                {
                    for (var i = 0; i < navController.NavigationItem.RightBarButtonItems.Length; ++i)
                    {
                        navController.NavigationItem.RightBarButtonItems[i].Dispose();
                    }
                }

                if (navController.ToolbarItems != null)
                {
                    for (var i = 0; i < navController.ToolbarItems.Length; ++i)
                    {
                        navController.ToolbarItems[i].Dispose();
                    }
                }

                var toolbarItems = page.GetToolbarItems();
                if (toolbarItems == null)
                {
                    return;
                }

                List <UIBarButtonItem> primaries   = null;
                List <UIBarButtonItem> secondaries = null;

                foreach (var toolbarItem in toolbarItems)
                {
                    var barButtonItem = toolbarItem.ToUIBarButtonItem(toolbarItem.Order == ToolbarItemOrder.Secondary);
                    if (toolbarItem is IconToolbarItem iconItem)
                    {
                        if (!iconItem.IsVisible)
                        {
                            continue;
                        }

                        var icon = Iconize.FindIconForKey(iconItem.Icon);
                        if (icon != null)
                        {
                            using (var image = icon.ToUIImage(22f))
                            {
                                barButtonItem.Image = image;
                                if (iconItem.IconColor != Color.Default)
                                {
                                    barButtonItem.TintColor = iconItem.IconColor.ToUIColor();
                                }
                            }
                        }
                    }

                    if (toolbarItem.Order == ToolbarItemOrder.Secondary)
                    {
                        (secondaries = secondaries ?? new List <UIBarButtonItem>()).Add(barButtonItem);
                    }
                    else
                    {
                        (primaries = primaries ?? new List <UIBarButtonItem>()).Add(barButtonItem);
                    }
                }

                primaries?.Reverse();

                navController.NavigationItem.SetRightBarButtonItems(primaries == null ? new UIBarButtonItem[0] : primaries.ToArray(), false);
                navController.ToolbarItems = (secondaries == null ? new UIBarButtonItem[0] : secondaries.ToArray());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #22
0
 /// <summary>
 /// Create an <see cref="IconDrawable" />.
 /// </summary>
 /// <param name="context">Your activity or application context.</param>
 /// <param name="iconKey">The icon key you want this drawable to display.</param>
 /// <exception cref="ArgumentException">If the key doesn't match any icon.</exception>
 public IconDrawable(Context context, String iconKey)
     : this(context, Iconize.FindIconForKey(iconKey))
 {
     // Intentionally left blank
 }