-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce66cfa
commit eb69c1d
Showing
8 changed files
with
254 additions
and
5 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/Orc.Theming.Example/ViewModels/Tools/FontSizeViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Orc.Theming.Example.ViewModels | ||
{ | ||
using Catel.MVVM; | ||
|
||
public class FontSizeViewModel : ViewModelBase | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<catel:UserControl x:Class="Orc.Theming.Example.Views.FontSizeView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:catel="http://schemas.catelproject.com" | ||
xmlns:ribbon="clr-namespace:Orc.Theming.Example" | ||
xmlns:orctheming="http://schemas.wildgums.com/orc/theming" | ||
xmlns:orccontrols="http://schemas.wildgums.com/orc/controls"> | ||
|
||
<orccontrols:StackGrid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Label Content="Default font size" | ||
Grid.ColumnSpan="2" | ||
HorizontalAlignment="Center" /> | ||
|
||
<GroupBox Header="No subscriptions"> | ||
<StackPanel Orientation="Horizontal"> | ||
<GroupBox Header="Scaling"> | ||
<StackPanel Orientation="Vertical" | ||
HorizontalAlignment="Left"> | ||
<Label Content="This is 0.6" | ||
FontSize="{orctheming:FontSize Scale=0.6}" /> | ||
<Label Content="This is 0.8" | ||
FontSize="{orctheming:FontSize Scale=0.8}" /> | ||
<Label Content="This is 1.0" | ||
FontSize="{orctheming:FontSize Scale=1.0}" /> | ||
<Label Content="This is 1.2" | ||
FontSize="{orctheming:FontSize Scale=1.2}" /> | ||
<Label Content="This is 1.4" | ||
FontSize="{orctheming:FontSize Scale=1.4}" /> | ||
</StackPanel> | ||
</GroupBox> | ||
|
||
<GroupBox Header="Delta"> | ||
<StackPanel Orientation="Vertical" | ||
HorizontalAlignment="Left"> | ||
<Label Content="This is -4" | ||
FontSize="{orctheming:FontSize Delta=-4}" /> | ||
<Label Content="This is -2" | ||
FontSize="{orctheming:FontSize Delta=-2}" /> | ||
<Label Content="This is 0" | ||
FontSize="{orctheming:FontSize Delta=0}" /> | ||
<Label Content="This is +2" | ||
FontSize="{orctheming:FontSize Delta=2}" /> | ||
<Label Content="This is +4" | ||
FontSize="{orctheming:FontSize Delta=4}" /> | ||
</StackPanel> | ||
</GroupBox> | ||
</StackPanel> | ||
</GroupBox> | ||
|
||
<GroupBox Header="Subscriptions"> | ||
<StackPanel Orientation="Horizontal"> | ||
<GroupBox Header="Scaling"> | ||
<StackPanel Orientation="Vertical" | ||
HorizontalAlignment="Left"> | ||
<Label Content="This is 0.6" | ||
FontSize="{orctheming:FontSize Scale=0.6, SubscribeToEvents=True}" /> | ||
<Label Content="This is 0.8" | ||
FontSize="{orctheming:FontSize Scale=0.8, SubscribeToEvents=True}" /> | ||
<Label Content="This is 1.0" | ||
FontSize="{orctheming:FontSize Scale=1.0, SubscribeToEvents=True}" /> | ||
<Label Content="This is 1.2" | ||
FontSize="{orctheming:FontSize Scale=1.2, SubscribeToEvents=True}" /> | ||
<Label Content="This is 1.4" | ||
FontSize="{orctheming:FontSize Scale=1.4, SubscribeToEvents=True}" /> | ||
</StackPanel> | ||
</GroupBox> | ||
|
||
<GroupBox Header="Delta"> | ||
<StackPanel Orientation="Vertical" | ||
HorizontalAlignment="Left"> | ||
<Label Content="This is -4" | ||
FontSize="{orctheming:FontSize Delta=-4, SubscribeToEvents=True}" /> | ||
<Label Content="This is -2" | ||
FontSize="{orctheming:FontSize Delta=-2, SubscribeToEvents=True}" /> | ||
<Label Content="This is 0" | ||
FontSize="{orctheming:FontSize Delta=0, SubscribeToEvents=True}" /> | ||
<Label Content="This is +2" | ||
FontSize="{orctheming:FontSize Delta=2, SubscribeToEvents=True}" /> | ||
<Label Content="This is +4" | ||
FontSize="{orctheming:FontSize Delta=4, SubscribeToEvents=True}" /> | ||
</StackPanel> | ||
</GroupBox> | ||
</StackPanel> | ||
</GroupBox> | ||
|
||
</orccontrols:StackGrid> | ||
|
||
</catel:UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Orc.Theming.Example.Views; | ||
|
||
public partial class FontSizeView | ||
{ | ||
public FontSizeView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
namespace Orc.Theming; | ||
|
||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Markup; | ||
using Catel.IoC; | ||
using Catel.Logging; | ||
using Catel.Windows; | ||
using Catel.Windows.Markup; | ||
|
||
/// <summary> | ||
/// Markup extension that can set a relative font size. | ||
/// </summary> | ||
public class FontSize : UpdatableMarkupExtension | ||
{ | ||
private static readonly ILog Log = LogManager.GetCurrentClassLogger(); | ||
|
||
private IFontSizeService? _fontSizeService; | ||
|
||
static FontSize() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FontSize" /> class. | ||
/// </summary> | ||
public FontSize() | ||
{ | ||
Scale = 1.0d; | ||
SubscribeToEvents = false; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the font size scaling. | ||
/// </summary> | ||
/// <value>The font size scaling.</value> | ||
[ConstructorArgument("scale")] | ||
public double? Scale { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the font size delta. | ||
/// </summary> | ||
/// <value>The font size delta.</value> | ||
[ConstructorArgument("delta")] | ||
public double? Delta { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets whether this markup extension should subscribe to events to be responsive. | ||
/// <para /> | ||
/// The default value is <c>false</c> for performance reasons. | ||
/// </summary> | ||
/// <value>The font size delta.</value> | ||
[ConstructorArgument("subscribeToEvents")] | ||
public bool SubscribeToEvents { get; set; } | ||
|
||
protected override object? ProvideDynamicValue(IServiceProvider? serviceProvider) | ||
{ | ||
var defaultFontSize = 12d; | ||
|
||
if (TargetObject is DependencyObject dependencyObject) | ||
{ | ||
var parentControl = dependencyObject.GetLogicalParent()?.FindLogicalAncestorByType<Control>(); | ||
if (parentControl is not null) | ||
{ | ||
defaultFontSize = (double)parentControl.GetValue(Control.FontSizeProperty); | ||
} | ||
} | ||
|
||
var finalFontSize = defaultFontSize; | ||
|
||
if (Delta is not null) | ||
{ | ||
finalFontSize += Delta.Value; | ||
} | ||
|
||
if (Scale is not null) | ||
{ | ||
finalFontSize *= Scale.Value; | ||
} | ||
|
||
return finalFontSize; | ||
} | ||
|
||
protected override void OnTargetObjectLoaded() | ||
{ | ||
base.OnTargetObjectLoaded(); | ||
|
||
if (SubscribeToEvents) | ||
{ | ||
var fontSizeService = _fontSizeService; | ||
if (fontSizeService is null) | ||
{ | ||
_fontSizeService = fontSizeService = ServiceLocator.Default.ResolveType<IFontSizeService>(); | ||
} | ||
|
||
if (fontSizeService is not null) | ||
{ | ||
fontSizeService.FontSizeChanged += OnFontSizeServiceFontSizeChanged; | ||
} | ||
} | ||
} | ||
|
||
protected override void OnTargetObjectUnloaded() | ||
{ | ||
var fontSizeService = _fontSizeService; | ||
if (fontSizeService is not null) | ||
{ | ||
fontSizeService.FontSizeChanged -= OnFontSizeServiceFontSizeChanged; | ||
} | ||
|
||
base.OnTargetObjectUnloaded(); | ||
} | ||
|
||
private void OnFontSizeServiceFontSizeChanged(object? sender, EventArgs e) | ||
{ | ||
UpdateValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,4 @@ private void OnSelectedFontSizeChanged() | |
{ | ||
_fontSizeService.SetFontSize(SelectedFontSize); | ||
} | ||
} | ||
} |