コード例 #1
0
        public static void ApplyTheme(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            if (element == null)
            {
                return;
            }

            if (textField.ActiveTextInputController == null)
            {
                return;
            }

            textField.ContainerScheme.ColorScheme = (SemanticColorScheme)CreateColorScheme();
            ApplyContainerTheme(textField);

            var textColor         = MaterialColors.GetEntryTextColor(element.TextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(element.PlaceholderColor, element.TextColor);
            var underlineColors   = MaterialColors.GetUnderlineColor(element.PlaceholderColor);

            textField.TextInput.TextColor = textColor;
            textField.ActiveTextInputController.InlinePlaceholderColor         = placeHolderColors.InlineColor;
            textField.ActiveTextInputController.FloatingPlaceholderNormalColor = placeHolderColors.InlineColor;
            textField.ActiveTextInputController.FloatingPlaceholderActiveColor = placeHolderColors.FloatingColor;

            // BackgroundColor
            textField.ActiveTextInputController.BorderFillColor = MaterialColors.CreateEntryFilledInputBackgroundColor(element.BackgroundColor, element.TextColor);

            textField.ActiveTextInputController.ActiveColor = underlineColors.FocusedColor;
            textField.ActiveTextInputController.NormalColor = underlineColors.UnFocusedColor;
        }
コード例 #2
0
        public static void UpdateTextColor(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            var uIColor = MaterialColors.GetEntryTextColor(element.TextColor);

            textField.ContainerScheme.ColorScheme.OnSurfaceColor = uIColor;
            textField.ContainerScheme.ColorScheme.PrimaryColor   = uIColor;
        }
コード例 #3
0
 public static void ApplyTypographyScheme(IMaterialTextField textField, IFontElement fontElement)
 {
     textField.TextInput.Font             = fontElement?.ToUIFont();
     textField.TypographyScheme.Subtitle1 = textField.TextInput.Font;
     TextFieldTypographyThemer.ApplyTypographyScheme(textField.TypographyScheme, textField.TextInput);
     TextFieldTypographyThemer.ApplyTypographyScheme(textField.TypographyScheme, textField.ActiveTextInputController);
 }
コード例 #4
0
        public static void ApplyTypographyScheme(IMaterialTextField textField, IFontElement fontElement)
        {
            var containerScheme = textField.ContainerScheme;

            textField.TextInput.Font = fontElement?.ToUIFont();
            containerScheme.TypographyScheme.Subtitle1 = textField.TextInput.Font;
            ApplyContainerTheme(textField);
        }
コード例 #5
0
        static void ApplyContainerTheme(IMaterialTextField textField)
        {
            var containerScheme = textField.ContainerScheme;

            if (textField.ActiveTextInputController is MTextInputControllerFilled filled)
            {
                filled.ApplyTheme(containerScheme);
            }
        }
コード例 #6
0
 public static void Init(IMaterialEntryRenderer element, IMaterialTextField textField, IFontElement fontElement)
 {
     textField.TextInput.ClearButtonMode = UITextFieldViewMode.Never;
     textField.ActiveTextInputController = new MTextInputControllerFilled(textField.TextInput);
     textField.TextInput.TextInsetsMode  = TextInputTextInsetsMode.IfContent;
     textField.TypographyScheme          = CreateTypographyScheme();
     textField.ColorScheme = (SemanticColorScheme)CreateColorScheme();
     ApplyTypographyScheme(textField, fontElement);
     ApplyTheme(textField, element);
 }
コード例 #7
0
ファイル: MaterialTextManager.cs プロジェクト: Glepooek/maui
        public static void ApplyTheme(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            if (element == null)
            {
                return;
            }

            if (textField.ActiveTextInputController == null)
            {
                return;
            }

            textField.ContainerScheme.ColorScheme = (SemanticColorScheme)CreateColorScheme();
            ApplyContainerTheme(textField);

            var adjustedTextColor = AdjustTextColor(element);

            var textColor         = MaterialColors.GetEntryTextColor(adjustedTextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(element.PlaceholderColor, adjustedTextColor);
            var underlineColors   = MaterialColors.GetUnderlineColor(element.PlaceholderColor);

            textField.TextInput.TextColor = textColor;

            var inputController = textField.ActiveTextInputController;

            inputController.InlinePlaceholderColor         = placeHolderColors.InlineColor;
            inputController.FloatingPlaceholderNormalColor = placeHolderColors.InlineColor;
            inputController.FloatingPlaceholderActiveColor = placeHolderColors.FloatingColor;
            inputController.DisabledColor = placeHolderColors.InlineColor;

            var brush = element.Background;

            if (Brush.IsNullOrEmpty(brush))
            {
                // BackgroundColor
                textField.ActiveTextInputController.BorderFillColor = MaterialColors.CreateEntryFilledInputBackgroundColor(element.BackgroundColor, adjustedTextColor);
            }
            else
            {
                // Background
                if (textField is UITextField || textField is MultilineTextField)
                {
                    var backgroundImage = ((UIView)textField).GetBackgroundImage(brush);
                    textField.BackgroundSize = backgroundImage?.Size;
                    var color = backgroundImage != null?UIColor.FromPatternImage(backgroundImage) : UIColor.Clear;

                    textField.ActiveTextInputController.BorderFillColor = color;
                }
            }
            textField.ActiveTextInputController.ActiveColor = underlineColors.FocusedColor;
            textField.ActiveTextInputController.NormalColor = underlineColors.UnFocusedColor;
        }
コード例 #8
0
        public static void ApplyThemeIfNeeded(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            var bgBrush = element.Background;

            if (Brush.IsNullOrEmpty(bgBrush))
            {
                return;
            }

            UIImage backgroundImage = null;

            if (textField is UITextField || textField is MultilineTextField)
            {
                backgroundImage = ((UIView)textField).GetBackgroundImage(bgBrush);
            }

            if (textField.BackgroundSize != null && textField.BackgroundSize != backgroundImage?.Size)
            {
                ApplyTheme(textField, element);
            }
        }
コード例 #9
0
        public static void UpdatePlaceholder(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            var placeholderText = element.Placeholder ?? String.Empty;

            textField.ActiveTextInputController.PlaceholderText = placeholderText;
            ApplyTheme(textField, element);

            var previous = textField.ActiveTextInputController.FloatingPlaceholderScale;

            if (String.IsNullOrWhiteSpace(placeholderText))
            {
                textField.ActiveTextInputController.FloatingPlaceholderScale = 0;
            }
            else
            {
                textField.ActiveTextInputController.FloatingPlaceholderScale = (float)TextInputControllerBase.FloatingPlaceholderScaleDefault;
            }

            if (previous != textField.ActiveTextInputController.FloatingPlaceholderScale && element is IVisualElementRenderer controller)
            {
                controller.Element?.InvalidateMeasureInternal(InvalidationTrigger.VerticalOptionsChanged);
            }
        }