Skip to content

Commit

Permalink
! Make Quick Info background change according to tooltip text color
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Dec 5, 2024
1 parent 2644e2e commit 4333d6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
26 changes: 26 additions & 0 deletions Codist/QuickInfo/QuickInfoBackgroundController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,32 @@
using System.Windows.Media;
using CLR;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text.Classification;

namespace Codist.QuickInfo
{
sealed class QuickInfoBackgroundController : SingletonQuickInfoSource
{
#region Adaptive background brightness
static readonly IClassificationFormatMap __ToolTipFormatMap = InitFormatMap();
static bool __Init;

static IClassificationFormatMap InitFormatMap() {
var m = ServicesHelper.Instance.ClassificationFormatMap.GetClassificationFormatMap("tooltip");
m.ClassificationFormatMappingChanged += (s, args) => AdaptBackgroundBrightness(__ToolTipFormatMap);
return m;
}

static void AdaptBackgroundBrightness(IClassificationFormatMap formatMap) {
QuickInfoConfig c = Config.Instance.QuickInfo;
if (c.BackColor.A != 0
&& formatMap.DefaultTextProperties.ForegroundBrush is SolidColorBrush b
&& b.Color.IsDark() == c.BackColor.IsDark()) {
c.BackColor = c.BackColor.InvertBrightness();
}
}
#endregion

SolidColorBrush _Background;

public QuickInfoBackgroundController() {
Expand All @@ -20,11 +41,16 @@ public QuickInfoBackgroundController() {

void ConfigUpdated(ConfigUpdatedEventArgs args) {
if (args.UpdatedFeature.MatchFlags(Features.SuperQuickInfo)) {
AdaptBackgroundBrightness(__ToolTipFormatMap);
UpdateBackgroundBrush();
}
}

void UpdateBackgroundBrush() {
if (__Init == false) {
__Init = true;
AdaptBackgroundBrightness(__ToolTipFormatMap);
}
var bc = Config.Instance.QuickInfo.BackColor;
var o = bc.A;
if (o != 0) {
Expand Down
5 changes: 0 additions & 5 deletions Codist/SyntaxHighlight/FormatStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,6 @@ void InvertColorBrightness() {
}
}

var qi = Config.Instance.QuickInfo;
if (qi.BackColor.A != 0) {
qi.BackColor = qi.BackColor.InvertBrightness();
Config.Instance.FireConfigChangedEvent(Features.SuperQuickInfo);
}
var sm = Config.Instance.SymbolReferenceMarkerSettings;
if (sm.ReferenceMarker.A != 0 || sm.WriteMarker.A != 0 || sm.SymbolDefinition.A != 0) {
if (sm.ReferenceMarker.A != 0) {
Expand Down

0 comments on commit 4333d6f

Please sign in to comment.