Skip to content

Commit

Permalink
Fix a MaterialTopAppBar issue and add new properties to MaterialSegme…
Browse files Browse the repository at this point in the history
…nted
  • Loading branch information
AgustinBonilla committed Nov 20, 2023
1 parent dc3aeef commit 98ca4aa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MaterialDesignControls.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.8.1">
<id>Plugin.MaterialDesignControls</id>
<version>3.0.4</version>
<version>3.0.5</version>
<title>MaterialDesignControls Plugin for Xamarin Forms</title>
<authors>Horus</authors>
<owners>AgustinBonillaHorus</owners>
Expand Down
10 changes: 10 additions & 0 deletions MaterialSegmentedControl.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ This propperty is to set the fontfamily of the segment text.
<br/>
<br/>

### Property SelectedFontSize:
This property is to set the fontsize of the selected segment text.
<br/>
<br/>

### Property SelectedFontFamily
This propperty is to set the fontfamily of the selected segment text.
<br/>
<br/>

### Property IsEnabled
This property is to set if the control is enabled or not. By default is True.
<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}" />
</StackLayout>
</ScrollView>
</Grid>
Expand Down
22 changes: 22 additions & 0 deletions src/MaterialDesignControls/ControlsMaterial3/MaterialSegmented.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
21 changes: 15 additions & 6 deletions src/MaterialDesignControls/ControlsMaterial3/MaterialTopAppBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 98ca4aa

Please sign in to comment.