ux: use different inline code background for different themes

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-25 21:26:21 +08:00
parent 91acf0a32a
commit d2e688908c
No known key found for this signature in database
3 changed files with 18 additions and 1 deletions

View file

@ -25,6 +25,7 @@
<Color x:Key="Color.Diff.AddedHighlight">#A7E1A7</Color>
<Color x:Key="Color.Diff.DeletedHighlight">#F19B9D</Color>
<Color x:Key="Color.Link">#0000EE</Color>
<Color x:Key="Color.InlineCode">#FFE5E5E5</Color>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
@ -51,6 +52,7 @@
<Color x:Key="Color.Diff.AddedHighlight">#A0308D3C</Color>
<Color x:Key="Color.Diff.DeletedHighlight">#A09F4247</Color>
<Color x:Key="Color.Link">#4DAAFC</Color>
<Color x:Key="Color.InlineCode">#FF2E2E2E</Color>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
@ -79,6 +81,7 @@
<SolidColorBrush x:Key="Brush.Diff.AddedHighlight" Color="{DynamicResource Color.Diff.AddedHighlight}"/>
<SolidColorBrush x:Key="Brush.Diff.DeletedHighlight" Color="{DynamicResource Color.Diff.DeletedHighlight}"/>
<SolidColorBrush x:Key="Brush.Link" Color="{DynamicResource Color.Link}"/>
<SolidColorBrush x:Key="Brush.InlineCode" Color="{DynamicResource Color.InlineCode}"/>
<FontFamily x:Key="Fonts.Default">fonts:Inter#Inter</FontFamily>
<FontFamily x:Key="Fonts.Monospace">fonts:SourceGit#JetBrains Mono</FontFamily>

View file

@ -47,6 +47,15 @@ namespace SourceGit.Views
get => GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public static readonly StyledProperty<IBrush> InlineCodeBackgroundProperty =
AvaloniaProperty.Register<CommitSubjectPresenter, IBrush>(nameof(InlineCodeBackground), Brushes.Transparent);
public IBrush InlineCodeBackground
{
get => GetValue(InlineCodeBackgroundProperty);
set => SetValue(InlineCodeBackgroundProperty, value);
}
public static readonly StyledProperty<IBrush> ForegroundProperty =
AvaloniaProperty.Register<CommitSubjectPresenter, IBrush>(nameof(Foreground), Brushes.White);
@ -106,7 +115,7 @@ namespace SourceGit.Views
{
var rect = new Rect(inline.X, (height - inline.Text.Height - 2) * 0.5, inline.Text.WidthIncludingTrailingWhitespace + 8, inline.Text.Height + 2);
var roundedRect = new RoundedRect(rect, new CornerRadius(4));
context.DrawRectangle(new SolidColorBrush(new Color(52, 101, 108, 118)), null, roundedRect);
context.DrawRectangle(InlineCodeBackground, null, roundedRect);
context.DrawText(inline.Text, new Point(inline.X + 4, (height - inline.Text.Height) * 0.5));
}
else
@ -182,6 +191,10 @@ namespace SourceGit.Views
_needRebuildInlines = true;
InvalidateVisual();
}
else if (change.Property == InlineCodeBackgroundProperty)
{
InvalidateVisual();
}
}
protected override void OnPointerMoved(PointerEventArgs e)

View file

@ -158,6 +158,7 @@
<v:CommitSubjectPresenter Grid.Column="3"
FontFamily="{DynamicResource Fonts.Primary}"
CodeFontFamily="{DynamicResource Fonts.Monospace}"
InlineCodeBackground="{DynamicResource Brush.InlineCode}"
Foreground="{DynamicResource Brush.FG1}"
LinkForeground="{DynamicResource Brush.Link}"
Subject="{Binding Subject}"