Two colors for tags

Update the idl to allow us to specify separate FG and BG colors. I think that's better honestly.
This commit is contained in:
Mike Griese
2024-12-13 17:37:05 -06:00
committed by GitHub
7 changed files with 52 additions and 22 deletions

View File

@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CmdPal.Ext.WindowWalker.Commands;
using Microsoft.CmdPal.Ext.WindowWalker.Components;
using Microsoft.CmdPal.Ext.WindowWalker.Helpers;
using Microsoft.CmdPal.Ext.WindowWalker.Properties;
using Microsoft.CmdPal.Extensions.Helpers;
@@ -27,10 +26,10 @@ internal static class ResultHelper
{
if (searchControllerResults == null || searchControllerResults.Count == 0)
{
return new List<WindowWalkerListItem>();
return [];
}
List<WindowWalkerListItem> resultsList = new List<WindowWalkerListItem>(searchControllerResults.Count);
var resultsList = new List<WindowWalkerListItem>(searchControllerResults.Count);
var addExplorerInfo = searchControllerResults.Any(x =>
string.Equals(x.Result.Process.Name, "explorer.exe", StringComparison.OrdinalIgnoreCase) &&
x.Result.Process.IsShellProcess);
@@ -77,7 +76,7 @@ internal static class ResultHelper
/// <returns>String with the subtitle</returns>
private static string GetSubtitle(Window window)
{
if (window == null || !(window is Window))
if (window is null or not Window)
{
return string.Empty;
}
@@ -95,7 +94,7 @@ internal static class ResultHelper
tags.Add(new Tag
{
Text = Resources.windowwalker_NotResponding,
Color = ColorHelpers.FromRgb(220, 20, 60),
Foreground = ColorHelpers.FromRgb(220, 20, 60),
});
}

View File

@@ -453,7 +453,7 @@ internal sealed partial class PokedexExtensionPage : ListPage
return new ListItem(new PokemonPage(pokemon))
{
Subtitle = $"#{pokemon.Number}",
Tags = pokemon.Types.Select(t => new Tag() { Text = t, Color = GetColorForType(t) }).ToArray(),
Tags = pokemon.Types.Select(t => new Tag() { Text = t, Background = GetColorForType(t) }).ToArray(),
};
}

View File

@@ -17,7 +17,9 @@ public partial class TagViewModel(ITag _tag, IPageContext context) : ExtensionOb
public string Tooltip { get; private set; } = string.Empty;
public OptionalColor Color { get; private set; }
public OptionalColor Foreground { get; private set; }
public OptionalColor Background { get; private set; }
public IconDataType Icon { get; private set; } = new(string.Empty);
@@ -35,12 +37,14 @@ public partial class TagViewModel(ITag _tag, IPageContext context) : ExtensionOb
Command = new(model.Command);
Text = model.Text;
Color = model.Color;
Foreground = model.Foreground;
Background = model.Background;
Tooltip = model.ToolTip;
Icon = model.Icon;
UpdateProperty(nameof(Text));
UpdateProperty(nameof(Color));
UpdateProperty(nameof(Foreground));
UpdateProperty(nameof(Background));
UpdateProperty(nameof(Tooltip));
UpdateProperty(nameof(Icon));
}

View File

@@ -5,7 +5,6 @@
using Microsoft.CmdPal.Extensions;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Windows.UI;
namespace WindowsCommandPalette;
@@ -21,11 +20,26 @@ public sealed class TagViewModel
internal IconElement IcoElement => Microsoft.Terminal.UI.IconPathConverter.IconMUX(Icon?.Icon ?? string.Empty, 10);
public Windows.UI.Color Color
public Windows.UI.Color Foreground
{
get
{
var color = _tag.Color;
var color = _tag.Foreground;
if (color.HasValue)
{
var c = color.Color;
return Windows.UI.Color.FromArgb(c.A, c.R, c.G, c.B);
}
return default;
}
}
public Windows.UI.Color Background
{
get
{
var color = _tag.Background;
if (color.HasValue)
{
var c = color.Color;
@@ -38,11 +52,11 @@ public sealed class TagViewModel
// TODO! VV These guys should have proper theme-aware lookups for default values
// All this code is exceptionally terrible, but it's just here to keep the POC app running at this point.
internal Brush BorderBrush => new SolidColorBrush(Color);
internal Brush BorderBrush => new SolidColorBrush(Foreground);
internal Brush TextBrush => new SolidColorBrush(Color.A == 0 ? Windows.UI.Color.FromArgb(255, 255, 255, 255) : Color);
internal Brush TextBrush => new SolidColorBrush(Foreground.A == 0 ? Windows.UI.Color.FromArgb(255, 255, 255, 255) : Foreground);
internal Brush BackgroundBrush => new SolidColorBrush(Color.A == 0 ? Color : Windows.UI.Color.FromArgb((byte)(Color.A / 4), Color.R, Color.G, Color.B));
internal Brush BackgroundBrush => new SolidColorBrush(Background);
public TagViewModel(ITag tag)
{

View File

@@ -1275,7 +1275,8 @@ block, and the generator will pull this into the file first. -->
interface ITag {
IconDataType Icon { get; };
String Text { get; };
OptionalColor Color { get; };
OptionalColor Foreground { get; };
OptionalColor Background { get; };
String ToolTip { get; };
ICommand Command { get; };
};

View File

@@ -6,19 +6,30 @@ namespace Microsoft.CmdPal.Extensions.Helpers;
public class Tag : BaseObservable, ITag
{
private OptionalColor _color;
private OptionalColor _foreground;
private OptionalColor _background;
private IconDataType _icon = new(string.Empty);
private string _text = string.Empty;
private string _toolTip = string.Empty;
private ICommand? _command;
public OptionalColor Color
public OptionalColor Foreground
{
get => _color;
get => _foreground;
set
{
_color = value;
OnPropertyChanged(nameof(Color));
_foreground = value;
OnPropertyChanged(nameof(Foreground));
}
}
public OptionalColor Background
{
get => _background;
set
{
_background = value;
OnPropertyChanged(nameof(Background));
}
}

View File

@@ -132,7 +132,8 @@ namespace Microsoft.CmdPal.Extensions
interface ITag {
IconDataType Icon { get; };
String Text { get; };
OptionalColor Color { get; };
OptionalColor Foreground { get; };
OptionalColor Background { get; };
String ToolTip { get; };
ICommand Command { get; };
};