[Mouse Jump] Customisable appearance - borders, margins, colours, etc - final part (#35521)

* [MouseJump] move Mouse Jump settings into separate control (#27511)

* [MouseJump] added Mouse Jump style controls to Settings UI (#27511)

* [MouseJump] added Mouse Jump style controls to Settings UI (#27511)

* [MouseJump] removing unused MouseJumpUI code (#27511)

* [MouseJump] whitespace (#27511)

* [MouseJump] fix spellcheck (#27511)

* [MouseJump] enabled "Copy to custom style" (#27511)

* [MouseJump] fixing build (internal members -> public) (#27511)

* [MouseJump] remove unused "using"s (#27511)

* [MouseJump] use custom styles in preview image (#27511)

* [MouseJump] fixing failing test (#27511)

* [MouseJump] fixing failing test (#27511)

* [MouseJump] fixing failing test (#27511)

* [MouseJump] fixing failing test (#27511)

* [MouseJump] delinting to trigger a build (#27511)

* [MouseJump] updated settings preview image ("browser" header) (#27511)

* [MouseJump] upgrade default "custom" style settings in config (#27511)

* [MouseJump] fixed a glitch in settings upgrade (#27511)

* [MouseJump] fixed spell checker (#27511)

* [MouseJump] typo in resource strings (image -> images) (#27511)

* Remove unused include
This commit is contained in:
Michael Clayton
2024-11-26 15:37:59 +00:00
committed by GitHub
parent 7c9876582c
commit 53212188b7
39 changed files with 1710 additions and 992 deletions

View File

@@ -0,0 +1,69 @@
// 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;
using Microsoft.UI.Xaml.Data;
using MouseJump.Common.Models.Settings;
namespace Microsoft.PowerToys.Settings.UI.Converters
{
public sealed partial class MouseJumpPreviewTypeConverter : IValueConverter
{
private static readonly PreviewType[] PreviewTypeOrder =
[
PreviewType.Compact, PreviewType.Bezelled, PreviewType.Custom,
];
private static readonly PreviewType DefaultPreviewType = PreviewType.Bezelled;
// Receives a string as a parameter and returns an int representing the index
// to select in the Segmented control on the Mouse Jump settings page
public object Convert(object value, Type targetType, object parameter, string language)
{
var previewType = MouseJumpPreviewTypeConverter.DefaultPreviewType;
if (value is not string previewTypeName)
{
// the value isn't a string so just use the default preview type
}
else if (Enum.IsDefined(typeof(PreviewType), previewTypeName))
{
// there's a case-sensitive match for the value
previewType = Enum.Parse<PreviewType>(previewTypeName);
}
else if (Enum.TryParse<PreviewType>(previewTypeName, true, out var previewTypeResult))
{
// there's a case-insensitive match for the value
previewType = previewTypeResult;
}
return Array.IndexOf(
MouseJumpPreviewTypeConverter.PreviewTypeOrder,
previewType);
}
// Receives an int as a parameter that represents the selected index in the Segmented
// control on the Mouse Jump settings page, and returns the name of the PreviewType enum
// for that index.
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
var previewType = MouseJumpPreviewTypeConverter.DefaultPreviewType;
if (value is not int segmentedIndex)
{
// the value isn't an int so just use the default preview type
}
else if ((segmentedIndex < 0) || (segmentedIndex > MouseJumpPreviewTypeConverter.PreviewTypeOrder.Length))
{
// not a valid selected index so just use the default preview type
}
else
{
previewType = MouseJumpPreviewTypeConverter.PreviewTypeOrder[segmentedIndex];
}
return previewType.ToString();
}
}
}