Browse Source

Merge pull request #7449 from emmauss/fluent-compact

Add DensityStyle property in Fluent Theme provider
release/0.10.13
Tako 4 years ago
committed by Dan Walmsley
parent
commit
870f62fb8f
  1. 48
      src/Avalonia.Themes.Fluent/FluentTheme.cs

48
src/Avalonia.Themes.Fluent/FluentTheme.cs

@ -15,6 +15,12 @@ namespace Avalonia.Themes.Fluent
Dark, Dark,
} }
public enum DensityStyle
{
Normal,
Compact
}
/// <summary> /// <summary>
/// Includes the fluent theme in an application. /// Includes the fluent theme in an application.
/// </summary> /// </summary>
@ -24,6 +30,7 @@ namespace Avalonia.Themes.Fluent
private Styles _fluentDark = new(); private Styles _fluentDark = new();
private Styles _fluentLight = new(); private Styles _fluentLight = new();
private Styles _sharedStyles = new(); private Styles _sharedStyles = new();
private Styles _densityStyles = new();
private bool _isLoading; private bool _isLoading;
private IStyle? _loaded; private IStyle? _loaded;
@ -47,9 +54,12 @@ namespace Avalonia.Themes.Fluent
InitStyles(_baseUri); InitStyles(_baseUri);
} }
public static readonly StyledProperty<FluentThemeMode> ModeProperty = public static readonly StyledProperty<FluentThemeMode> ModeProperty =
AvaloniaProperty.Register<FluentTheme, FluentThemeMode>(nameof(Mode)); AvaloniaProperty.Register<FluentTheme, FluentThemeMode>(nameof(Mode));
public static readonly StyledProperty<DensityStyle> DensityStyleProperty =
AvaloniaProperty.Register<FluentTheme, DensityStyle>(nameof(DensityStyle));
/// <summary> /// <summary>
/// Gets or sets the mode of the fluent theme (light, dark). /// Gets or sets the mode of the fluent theme (light, dark).
/// </summary> /// </summary>
@ -58,6 +68,16 @@ namespace Avalonia.Themes.Fluent
get => GetValue(ModeProperty); get => GetValue(ModeProperty);
set => SetValue(ModeProperty, value); set => SetValue(ModeProperty, value);
} }
/// <summary>
/// Gets or sets the density style of the fluent theme (normal, compact).
/// </summary>
public DensityStyle DensityStyle
{
get => GetValue(DensityStyleProperty);
set => SetValue(DensityStyleProperty, value);
}
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change) protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{ {
base.OnPropertyChanged(change); base.OnPropertyChanged(change);
@ -74,6 +94,18 @@ namespace Avalonia.Themes.Fluent
(Loaded as Styles)![2] = _fluentLight[1]; (Loaded as Styles)![2] = _fluentLight[1];
} }
} }
if (change.Property == DensityStyleProperty)
{
if (DensityStyle == DensityStyle.Compact)
{
(Loaded as Styles)!.Add(_densityStyles[0]);
}
else if (DensityStyle == DensityStyle.Normal)
{
(Loaded as Styles)!.Remove(_densityStyles[0]);
}
}
} }
public IResourceHost? Owner => (Loaded as IResourceProvider)?.Owner; public IResourceHost? Owner => (Loaded as IResourceProvider)?.Owner;
@ -97,6 +129,12 @@ namespace Avalonia.Themes.Fluent
{ {
_loaded = new Styles() { _sharedStyles, _fluentDark[0], _fluentDark[1] }; _loaded = new Styles() { _sharedStyles, _fluentDark[0], _fluentDark[1] };
} }
if (DensityStyle == DensityStyle.Compact)
{
(_loaded as Styles)!.Add(_densityStyles[0]);
}
_isLoading = false; _isLoading = false;
} }
@ -183,6 +221,14 @@ namespace Avalonia.Themes.Fluent
Source = new Uri("avares://Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml") Source = new Uri("avares://Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml")
} }
}; };
_densityStyles = new Styles
{
new StyleInclude(baseUri)
{
Source = new Uri("avares://Avalonia.Themes.Fluent/DensityStyles/Compact.xaml")
}
};
} }
} }
} }

Loading…
Cancel
Save