Skip to content

Commit

Permalink
[Mouse Jump] - adding predefined "preview types" to settings ui - mic…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Jul 29, 2024
1 parent e764470 commit 9442d29
Show file tree
Hide file tree
Showing 11 changed files with 420 additions and 163 deletions.
11 changes: 11 additions & 0 deletions src/modules/MouseUtils/MouseJump.Common/Helpers/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ namespace MouseJump.Common.Helpers;

public static class ConfigHelper
{
public static Color? ToUnnamedColor(Color? value)
{
if (!value.HasValue)
{
return null;
}

var color = value.Value;
return Color.FromArgb(color.A, color.R, color.G, color.B);
}

public static string? SerializeToConfigColorString(Color? value)
{
if (!value.HasValue)
Expand Down
24 changes: 12 additions & 12 deletions src/modules/MouseUtils/MouseJump.Common/Helpers/StyleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace MouseJump.Common.Helpers;
public static class StyleHelper
{
/// <summary>
/// Default v2 preview style
/// Compact (legacy) preview style
/// </summary>
internal static readonly PreviewStyle DefaultPreviewStyle = new(
public static readonly PreviewStyle CompactPreviewStyle = new(
canvasSize: new(
width: 1600,
height: 1200
Expand All @@ -27,7 +27,7 @@ public static class StyleHelper
depth: 0
),
paddingStyle: new(
all: 4
all: 0
),
backgroundStyle: new(
color1: Color.FromArgb(0xFF, 0x0D, 0x57, 0xD2),
Expand All @@ -36,12 +36,12 @@ public static class StyleHelper
),
screenStyle: new(
marginStyle: new(
all: 4
all: 0
),
borderStyle: new(
color: Color.FromArgb(0xFF, 0x22, 0x22, 0x22),
all: 12,
depth: 4
all: 0,
depth: 0
),
paddingStyle: PaddingStyle.Empty,
backgroundStyle: new(
Expand All @@ -52,9 +52,9 @@ public static class StyleHelper
);

/// <summary>
/// Legacy preview style
/// Bezelled preview style
/// </summary>
public static readonly PreviewStyle LegacyPreviewStyle = new(
public static readonly PreviewStyle BezelledPreviewStyle = new(
canvasSize: new(
width: 1600,
height: 1200
Expand All @@ -67,7 +67,7 @@ public static class StyleHelper
depth: 0
),
paddingStyle: new(
all: 0
all: 4
),
backgroundStyle: new(
color1: Color.FromArgb(0xFF, 0x0D, 0x57, 0xD2),
Expand All @@ -76,12 +76,12 @@ public static class StyleHelper
),
screenStyle: new(
marginStyle: new(
all: 0
all: 4
),
borderStyle: new(
color: Color.FromArgb(0xFF, 0x22, 0x22, 0x22),
all: 0,
depth: 0
all: 12,
depth: 4
),
paddingStyle: PaddingStyle.Empty,
backgroundStyle: new(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.

namespace MouseJumpUI.Common.Models.Settings;

public enum PreviewType
{
Custom = 0,
Compact = 1,
Bezelled = 2,
}
2 changes: 1 addition & 1 deletion src/modules/MouseUtils/MouseJumpUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void ShowPreview()
var screens = ScreenHelper.GetAllScreens().Select(screen => screen.DisplayArea).ToList();
var activatedLocation = MouseHelper.GetCursorPosition();
this.PreviewLayout = LayoutHelper.GetPreviewLayout(
previewStyle: StyleHelper.LegacyPreviewStyle.WithCanvasSize(
previewStyle: StyleHelper.CompactPreviewStyle.WithCanvasSize(
new(
appSettings.Properties.ThumbnailSize.Width,
appSettings.Properties.ThumbnailSize.Height
Expand Down
11 changes: 11 additions & 0 deletions src/settings-ui/Settings.UI.Library/MouseJumpProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ public MouseJumpThumbnailSize ThumbnailSize
set;
}

/// <summary>
/// Gets or sets the preview type.
/// Allowed values are "compact", "bezelled", "custom"
/// </summary>
[JsonPropertyName("preview_type")]
public string PreviewType
{
get;
set;
}

[JsonPropertyName("background_color_1")]
public string BackgroundColor1
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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 MouseJumpUI.Common.Models.Settings;

namespace Microsoft.PowerToys.Settings.UI.Converters
{
public sealed 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();
}
}
}
1 change: 1 addition & 0 deletions src/settings-ui/Settings.UI/PowerToys.Settings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" />
<PackageReference Include="CommunityToolkit.WinUI.Animations" />
Expand Down
Loading

1 comment on commit 9442d29

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (1)

bezelled

Previously acknowledged words that are now absent COMMANDTITLE FILELOCKSMITHLIB gdnbaselines GPT interactable JArray ksh localport OOBEPT Pathto qwertyuiopasdfghjklzxcvbnm qwrtyuiopsghjklzxvnm redirectedfrom runsettings runspace testhost toggleswitch 🫥
Some files were automatically ignored 🙈

These sample patterns would exclude them:

^src/modules/launcher/Plugins/Microsoft\.PowerToys\.Run\.Plugin\.TimeDate/Properties/

You should consider adding them to:

.github/actions/spell-check/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words and update file exclusions, you could run the following commands

... in a clone of the [email protected]:mikeclayton/PowerToys.git repository
on the dev/mikeclayton/mousejump-styles branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/mikeclayton/PowerToys/actions/runs/10135747094/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (1889) from .github/actions/spell-check/expect.txt and unrecognized words (1)

Dictionary Entries Covers Uniquely
cspell:r/src/r.txt 543 1 1
cspell:cpp/src/people.txt 23 1
cspell:cpp/src/ecosystem.txt 51 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:r/src/r.txt
          cspell:cpp/src/people.txt
          cspell:cpp/src/ecosystem.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Warnings (1)

See the 📜action log or 📝 job summary for details.

ℹ️ Warnings Count
ℹ️ binary-file 2

See ℹ️ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.