Skip to content

Commit

Permalink
[Settings][Chore] Add CheckBoxWithDescriptionControl (#13866)
Browse files Browse the repository at this point in the history
* Added new control

* Update Microsoft.PowerToys.Settings.UI.csproj

* Added styling

* Add enableableTextBlock

* Update EnableableTextBlock.xaml

* Updated styles

* Updates styles

* Updated margins

* Name change and typo fix

* Update App.xaml

* Control name change

* Update expect.txt

* More name changes

* Even more name changes

Co-authored-by: Laute <Niels.Laute@philips.com>
  • Loading branch information
niels9001 and Laute committed Oct 19, 2021
1 parent 6269aa6 commit 4f335b9
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 128 deletions.
5 changes: 5 additions & 0 deletions src/settings-ui/Microsoft.PowerToys.Settings.UI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
x:Class="Microsoft.PowerToys.Settings.UI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:xaml="using:Microsoft.Toolkit.Win32.UI.XamlHost">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" ControlsResourcesVersion="Version2" />
<ResourceDictionary Source="/Controls/KeyVisual/KeyVisual.xaml" />
<ResourceDictionary Source="/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml" />
<ResourceDictionary Source="/Styles/TextBlock.xaml" />
<ResourceDictionary Source="/Styles/Button.xaml"/>
<ResourceDictionary Source="/Themes/Colors.xaml"/>
Expand All @@ -23,6 +25,9 @@
<Setter Property="Padding" Value="0,0,0,0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>

<Style TargetType="controls:CheckBoxWithDescriptionControl" BasedOn="{StaticResource DefaultCheckBoxStyle}" />

</ResourceDictionary>
</Application.Resources>
</xaml:XamlApplication>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using Windows.UI.Accessibility;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace Microsoft.PowerToys.Settings.UI.Controls
{
public class CheckBoxWithDescriptionControl : CheckBox
{
private CheckBoxWithDescriptionControl _checkBoxSubTextControl;

public CheckBoxWithDescriptionControl()
{
_checkBoxSubTextControl = (CheckBoxWithDescriptionControl)this;
this.Loaded += CheckBoxSubTextControl_Loaded;
}

protected override void OnApplyTemplate()
{
Update();
base.OnApplyTemplate();
}

private void Update()
{
if (!string.IsNullOrEmpty(Header))
{
AutomationProperties.SetName(this, Header);
}
}

private void CheckBoxSubTextControl_Loaded(object sender, RoutedEventArgs e)
{
StackPanel panel = new StackPanel() { Orientation = Orientation.Vertical };
panel.Children.Add(new TextBlock() { Margin = new Thickness(0, 10, 0, 0), Text = Header });
panel.Children.Add(new IsEnabledTextBlock() { FontSize = (double)App.Current.Resources["SecondaryTextFontSize"], Foreground = (SolidColorBrush)App.Current.Resources["TextFillColorSecondaryBrush"], Text = Description });
_checkBoxSubTextControl.Content = panel;
}

public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
"Header",
typeof(string),
typeof(CheckBoxWithDescriptionControl),
new PropertyMetadata(default(string)));

public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
"Description",
typeof(object),
typeof(CheckBoxWithDescriptionControl),
new PropertyMetadata(default(string)));

[Localizable(true)]
public string Header
{
get => (string)GetValue(HeaderProperty);
set => SetValue(HeaderProperty, value);
}

[Localizable(true)]
public string Description
{
get => (string)GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Microsoft.PowerToys.Settings.UI.Controls
{
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
public class IsEnabledTextBlock : Control
{
public IsEnabledTextBlock()
{
this.DefaultStyleKey = typeof(IsEnabledTextBlock);
}

protected override void OnApplyTemplate()
{
IsEnabledChanged -= IsEnabledTextBlock_IsEnabledChanged;
SetEnabledState();
IsEnabledChanged += IsEnabledTextBlock_IsEnabledChanged;
base.OnApplyTemplate();
}

public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text",
typeof(string),
typeof(IsEnabledTextBlock),
null);

[Localizable(true)]
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

private void IsEnabledTextBlock_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
SetEnabledState();
}

private void SetEnabledState()
{
VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Controls">

<Style TargetType="local:IsEnabledTextBlock">
<Setter Property="Foreground" Value="{ThemeResource DefaultTextForegroundThemeBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:IsEnabledTextBlock">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="Label.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBlock x:Name="Label"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
FontFamily="{TemplateBinding FontFamily}"
Foreground="{TemplateBinding Foreground}"
TextWrapping="WrapWholeWords"
Text="{TemplateBinding Text}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
</Compile>
<Compile Include="Behaviors\NavigationViewHeaderBehavior.cs" />
<Compile Include="Behaviors\NavigationViewHeaderMode.cs" />
<Compile Include="Controls\CheckBoxWithDescriptionControl.cs" />
<Compile Include="Controls\IsEnabledTextBlock\IsEnabledTextBlock.cs" />
<Compile Include="Controls\SettingsGroup\SettingsGroupAutomationPeer.cs" />
<Compile Include="Controls\ShortcutControl\ShortcutControl.xaml.cs">
<DependentUpon>ShortcutControl.xaml</DependentUpon>
Expand All @@ -116,9 +118,6 @@
<DependentUpon>OOBEPageControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\SettingsPageControl\PageLink.cs" />
<Compile Include="Controls\TextBlockControl.xaml.cs">
<DependentUpon>TextBlockControl.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\AwakeModeToIntConverter.cs" />
<Compile Include="Converters\ImageResizerFitToStringConverter.cs" />
<Compile Include="Converters\ImageResizerUnitToStringConverter.cs" />
Expand Down Expand Up @@ -303,9 +302,13 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<PRIResource Include="Strings\*\Resources.resw" />
<PRIResource Include="Strings\en-us\Resources.resw" />
</ItemGroup>
<ItemGroup>
<Page Include="Controls\IsEnabledTextBlock\IsEnabledTextBlock.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\ShortcutControl\ShortcutControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -338,10 +341,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\TextBlockControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="OOBE\Views\OobeAwake.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,11 @@
<data name="PowerLauncher_IgnoreHotkeysInFullScreen.Content" xml:space="preserve">
<value>Ignore shortcuts in fullscreen mode</value>
</data>
<data name="PowerLauncher_UseCentralizedKeyboardHook.Content" xml:space="preserve">
<value>Use centralized keyboard hook (try it if there are issues with the shortcut)</value>
<data name="PowerLauncher_UseCentralizedKeyboardHook.Header" xml:space="preserve">
<value>Use centralized keyboard hook</value>
</data>
<data name="PowerLauncher_UseCentralizedKeyboardHook.Description" xml:space="preserve">
<value>Try this if there are issues with the shortcut</value>
</data>
<data name="PowerLauncher_ClearInputOnLaunch.Content" xml:space="preserve">
<value>Clear the previous query on launch</value>
Expand Down Expand Up @@ -913,7 +916,7 @@
Made with 💗 by Microsoft and the PowerToys community.</value>
<comment>Windows refers to the OS</comment>
</data>
<data name="FancyZones_SpanZonesAcrossMonitorsCheckBoxControl.Text" xml:space="preserve">
<data name="FancyZones_SpanZonesAcrossMonitors.Header" xml:space="preserve">
<value>Allow zones to span across monitors</value>
</data>
<data name="ImageResizer_Formatting_ActualHeight.Text" xml:space="preserve">
Expand Down Expand Up @@ -1627,7 +1630,7 @@ From there, simply click on a Markdown file, PDF file or SVG icon in the File Ex
<data name="InvalidShortcutWarningLabel.Text" xml:space="preserve">
<value>Only shortcuts that start with **Windows key**, **Ctrl**, **Alt** or **Shift** are valid.</value>
</data>
<data name="FancyZones_SpanZonesAcrossMonitorsPrerequisites.Text" xml:space="preserve">
<data name="FancyZones_SpanZonesAcrossMonitors.Description" xml:space="preserve">
<value>All monitors must have the same DPI scaling and will be treated as one large combined rectangle which contains all monitors</value>
</data>
<data name="ImageResizer_DefaultSize_NewSizePrefix" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Controls/Setting/Setting.xaml" />
<ResourceDictionary Source="ms-appx:///Controls/SettingsGroup/SettingsGroup.xaml" />
<ResourceDictionary Source="ms-appx:///Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
</Style>

<!-- Setting expander style -->

<Style x:Key="SettingExpanderStyle" TargetType="muxc:Expander">
<Setter Property="Background" Value="{ThemeResource CardBackgroundBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource CardBorderThickness}" />
Expand Down

0 comments on commit 4f335b9

Please sign in to comment.