From 98ca4aa5632348102ed070d141dad82ad3918a64 Mon Sep 17 00:00:00 2001 From: Agustin Bonilla Date: Mon, 20 Nov 2023 10:09:31 -0300 Subject: [PATCH] Fix a MaterialTopAppBar issue and add new properties to MaterialSegmented --- MaterialDesignControls.nuspec | 2 +- MaterialSegmentedControl.md | 10 +++++++++ .../Pages/MaterialSegmentedPage.xaml | 6 ++++- .../ControlsMaterial3/MaterialSegmented.cs | 22 +++++++++++++++++++ .../ControlsMaterial3/MaterialTopAppBar.cs | 21 +++++++++++++----- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/MaterialDesignControls.nuspec b/MaterialDesignControls.nuspec index 57daa40..c4641ab 100755 --- a/MaterialDesignControls.nuspec +++ b/MaterialDesignControls.nuspec @@ -2,7 +2,7 @@ Plugin.MaterialDesignControls - 3.0.4 + 3.0.5 MaterialDesignControls Plugin for Xamarin Forms Horus AgustinBonillaHorus diff --git a/MaterialSegmentedControl.md b/MaterialSegmentedControl.md index 53f58aa..039fc93 100644 --- a/MaterialSegmentedControl.md +++ b/MaterialSegmentedControl.md @@ -139,6 +139,16 @@ This propperty is to set the fontfamily of the segment text.

+### Property SelectedFontSize: +This property is to set the fontsize of the selected segment text. +
+
+ +### Property SelectedFontFamily +This propperty is to set the fontfamily of the selected segment text. +
+
+ ### Property IsEnabled This property is to set if the control is enabled or not. By default is True.
diff --git a/example/ExampleMaterialDesignControls/Pages/MaterialSegmentedPage.xaml b/example/ExampleMaterialDesignControls/Pages/MaterialSegmentedPage.xaml index f8e9dae..1fe2bcc 100644 --- a/example/ExampleMaterialDesignControls/Pages/MaterialSegmentedPage.xaml +++ b/example/ExampleMaterialDesignControls/Pages/MaterialSegmentedPage.xaml @@ -128,7 +128,11 @@ SelectedColor="{StaticResource GradientColor9}" SelectedTextColor="Black" UnselectedColor="#F5F5F5" - UnselectedTextColor="{StaticResource GradientColor9}" /> + UnselectedTextColor="{StaticResource GradientColor9}" + FontSize="13" + SelectedFontSize="18" + FontFamily="{StaticResource LightFont}" + SelectedFontFamily="{StaticResource BoldFont}" /> diff --git a/src/MaterialDesignControls/ControlsMaterial3/MaterialSegmented.cs b/src/MaterialDesignControls/ControlsMaterial3/MaterialSegmented.cs index 97efcba..3eab668 100644 --- a/src/MaterialDesignControls/ControlsMaterial3/MaterialSegmented.cs +++ b/src/MaterialDesignControls/ControlsMaterial3/MaterialSegmented.cs @@ -214,6 +214,24 @@ public string FontFamily set { SetValue(FontFamilyProperty, value); } } + public static readonly BindableProperty SelectedFontSizeProperty = + BindableProperty.Create(nameof(SelectedFontSize), typeof(double), typeof(MaterialSegmented), defaultValue: MaterialFontSize.LabelLarge); + + public double SelectedFontSize + { + get { return (double)GetValue(SelectedFontSizeProperty); } + set { SetValue(SelectedFontSizeProperty, value); } + } + + public static readonly BindableProperty SelectedFontFamilyProperty = + BindableProperty.Create(nameof(SelectedFontFamily), typeof(string), typeof(MaterialSegmented), defaultValue: MaterialFontFamily.Default); + + public string SelectedFontFamily + { + get { return (string)GetValue(SelectedFontFamilyProperty); } + set { SetValue(SelectedFontFamilyProperty, value); } + } + public static readonly BindableProperty DisabledBorderColorProperty = BindableProperty.Create(nameof(DisabledBorderColor), typeof(Color), typeof(MaterialSegmented), defaultValue: MaterialColor.Disable); @@ -504,6 +522,8 @@ private void SetItemContentAndColors(MaterialCard card, MaterialLabel label, Mat { card.BackgroundColor = IsEnabled ? SelectedColor : DisabledSelectedColor; label.TextColor = IsEnabled ? SelectedTextColor : DisabledSelectedTextColor; + label.FontSize = SelectedFontSize; + label.FontFamily = SelectedFontFamily; if (item.SelectedIconIsVisible) { @@ -531,6 +551,8 @@ private void SetItemContentAndColors(MaterialCard card, MaterialLabel label, Mat { card.BackgroundColor = IsEnabled ? UnselectedColor : DisabledUnselectedColor; label.TextColor = IsEnabled ? UnselectedTextColor : DisabledUnselectedTextColor; + label.FontSize = FontSize; + label.FontFamily = FontFamily; if (item.UnselectedIconIsVisible) { diff --git a/src/MaterialDesignControls/ControlsMaterial3/MaterialTopAppBar.cs b/src/MaterialDesignControls/ControlsMaterial3/MaterialTopAppBar.cs index 96e78f8..1d68483 100644 --- a/src/MaterialDesignControls/ControlsMaterial3/MaterialTopAppBar.cs +++ b/src/MaterialDesignControls/ControlsMaterial3/MaterialTopAppBar.cs @@ -37,9 +37,6 @@ public class MaterialTopAppBar : Grid private double _descriptionLateralMargin = 10; - private double _mediumDefaultFontSize = 28; - private double _largeDefaultFontSize = 32; - private int _smallRowHeight = 48; private int _mediumRowHeight = 106; private int _largeRowHeight = 106; @@ -636,7 +633,7 @@ private void SetScrollViewAnimation() int maxHeight = Type == MaterialTopAppBarType.Large ? _largeRowHeight : _mediumRowHeight; int minHeight = _smallRowHeight; - double maxFontSize = Type == MaterialTopAppBarType.Large ? _largeDefaultFontSize : _mediumDefaultFontSize; + double maxFontSize = Type == MaterialTopAppBarType.Large ? MaterialFontSize.HeadlineMedium : MaterialFontSize.HeadlineSmall; double minFontSize = HeadlineFontSize; int maxLabelLateralMargin = Type == MaterialTopAppBarType.Large ? _largeLabelLateralMargin : _mediumLabelLateralMargin; @@ -708,25 +705,37 @@ private void SetType() switch (Type) { case MaterialTopAppBarType.Small: + _leadingIconCustomImageButton.VerticalOptions = LayoutOptions.Center; + _cntLeadingActivityIndicator.VerticalOptions = LayoutOptions.Center; + _trailingIconCustomImageButton.VerticalOptions = LayoutOptions.Center; + _cntTrailingActivityIndicator.VerticalOptions = LayoutOptions.Center; _headlineLabel.HorizontalTextAlignment = TextAlignment.Start; _headlineLabel.Margin = new Thickness(_smallLabelLateralMargin, HeadlineMarginAdjustment.Top, _smallLabelLateralMargin, HeadlineMarginAdjustment.Bottom); _descriptionLabel.HorizontalTextAlignment = TextAlignment.Start; _descriptionLabel.Margin = new Thickness(_descriptionLateralMargin, DescriptionMarginAdjustment.Top, _descriptionLateralMargin, DescriptionMarginAdjustment.Bottom); break; case MaterialTopAppBarType.Medium: + _leadingIconCustomImageButton.VerticalOptions = LayoutOptions.Start; + _cntLeadingActivityIndicator.VerticalOptions = LayoutOptions.Start; + _trailingIconCustomImageButton.VerticalOptions = LayoutOptions.Start; + _cntTrailingActivityIndicator.VerticalOptions = LayoutOptions.Start; _headlineLabel.HorizontalTextAlignment = TextAlignment.Start; _headlineLabel.VerticalOptions = LayoutOptions.End; _headlineLabel.Margin = new Thickness(_mediumLabelLateralMargin, HeadlineMarginAdjustment.Top, _mediumLabelLateralMargin, HeadlineMarginAdjustment.Bottom); - _headlineLabel.FontSize = _mediumDefaultFontSize; + _headlineLabel.FontSize = MaterialFontSize.HeadlineSmall; RowDefinitions[0].Height = new GridLength(_mediumRowHeight); _descriptionLabel.HorizontalTextAlignment = TextAlignment.Start; _descriptionLabel.Margin = new Thickness(_descriptionLateralMargin, DescriptionMarginAdjustment.Top, _descriptionLateralMargin, DescriptionMarginAdjustment.Bottom); break; case MaterialTopAppBarType.Large: + _leadingIconCustomImageButton.VerticalOptions = LayoutOptions.Start; + _cntLeadingActivityIndicator.VerticalOptions = LayoutOptions.Start; + _trailingIconCustomImageButton.VerticalOptions = LayoutOptions.Start; + _cntTrailingActivityIndicator.VerticalOptions = LayoutOptions.Start; _headlineLabel.HorizontalTextAlignment = TextAlignment.Start; _headlineLabel.VerticalOptions = LayoutOptions.End; _headlineLabel.Margin = new Thickness(_largeLabelLateralMargin, HeadlineMarginAdjustment.Top, _largeLabelLateralMargin, HeadlineMarginAdjustment.Bottom); - _headlineLabel.FontSize = _largeDefaultFontSize; + _headlineLabel.FontSize = MaterialFontSize.HeadlineMedium; RowDefinitions[0].Height = new GridLength(_largeRowHeight); _descriptionLabel.HorizontalTextAlignment = TextAlignment.Start; _descriptionLabel.Margin = new Thickness(_descriptionLateralMargin, DescriptionMarginAdjustment.Top, _descriptionLateralMargin, DescriptionMarginAdjustment.Bottom);