Merge pull request #170 from ccyr119/develop

ux: get brush color for LineBackgrounRenderer from themes
This commit is contained in:
leo 2024-06-05 21:06:48 +08:00 committed by GitHub
commit 557e6b48de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 131 additions and 25 deletions

View file

@ -25,6 +25,11 @@
<Color x:Key="Color.FG1">#FF1F1F1F</Color> <Color x:Key="Color.FG1">#FF1F1F1F</Color>
<Color x:Key="Color.FG2">#FF6F6F6F</Color> <Color x:Key="Color.FG2">#FF6F6F6F</Color>
<Color x:Key="Color.FG3">#FFFFFFFF</Color> <Color x:Key="Color.FG3">#FFFFFFFF</Color>
<Color x:Key="Color.TextDiffView.LineBG1.EMPTY">#3C000000</Color>
<Color x:Key="Color.TextDiffView.LineBG1.ADD">#3C00FF00</Color>
<Color x:Key="Color.TextDiffView.LineBG1.DELETED">#3CFF0000</Color>
<Color x:Key="Color.TextDiffView.LineBG2.ADD">#5A00FF00</Color>
<Color x:Key="Color.TextDiffView.LineBG2.DELETED">#50FF0000</Color>
</ResourceDictionary> </ResourceDictionary>
<ResourceDictionary x:Key="Dark"> <ResourceDictionary x:Key="Dark">
@ -51,6 +56,11 @@
<Color x:Key="Color.FG1">#FFDDDDDD</Color> <Color x:Key="Color.FG1">#FFDDDDDD</Color>
<Color x:Key="Color.FG2">#40F1F1F1</Color> <Color x:Key="Color.FG2">#40F1F1F1</Color>
<Color x:Key="Color.FG3">#FF252525</Color> <Color x:Key="Color.FG3">#FF252525</Color>
<Color x:Key="Color.TextDiffView.LineBG1.EMPTY">#FF424242</Color>
<Color x:Key="Color.TextDiffView.LineBG1.ADD">#FF38573C</Color>
<Color x:Key="Color.TextDiffView.LineBG1.DELETED">#FF633F3E</Color>
<Color x:Key="Color.TextDiffView.LineBG2.ADD">#FF388442</Color>
<Color x:Key="Color.TextDiffView.LineBG2.DELETED">#FF9F4247</Color>
</ResourceDictionary> </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries> </ResourceDictionary.ThemeDictionaries>
@ -79,4 +89,9 @@
<SolidColorBrush x:Key="Brush.FG3" Color="{DynamicResource Color.FG3}"/> <SolidColorBrush x:Key="Brush.FG3" Color="{DynamicResource Color.FG3}"/>
<SolidColorBrush x:Key="Brush.Accent" Color="{DynamicResource SystemAccentColor}"/> <SolidColorBrush x:Key="Brush.Accent" Color="{DynamicResource SystemAccentColor}"/>
<SolidColorBrush x:Key="Brush.AccentHovered" Color="{DynamicResource SystemListLowColor}"/> <SolidColorBrush x:Key="Brush.AccentHovered" Color="{DynamicResource SystemListLowColor}"/>
<SolidColorBrush x:Key="Brush.TextDiffView.LineBG1.EMPTY" Color="{DynamicResource Color.TextDiffView.LineBG1.EMPTY}"/>
<SolidColorBrush x:Key="Brush.TextDiffView.LineBG1.ADD" Color="{DynamicResource Color.TextDiffView.LineBG1.ADD}"/>
<SolidColorBrush x:Key="Brush.TextDiffView.LineBG1.DELETED" Color="{DynamicResource Color.TextDiffView.LineBG1.DELETED}"/>
<SolidColorBrush x:Key="Brush.TextDiffView.LineBG2.ADD" Color="{DynamicResource Color.TextDiffView.LineBG2.ADD}"/>
<SolidColorBrush x:Key="Brush.TextDiffView.LineBG2.DELETED" Color="{DynamicResource Color.TextDiffView.LineBG2.DELETED}"/>
</ResourceDictionary> </ResourceDictionary>

View file

@ -13,6 +13,11 @@
<DataTemplate DataType="m:TextDiff"> <DataTemplate DataType="m:TextDiff">
<v:CombinedTextDiffPresenter BorderBrush="{DynamicResource Brush.Border2}" <v:CombinedTextDiffPresenter BorderBrush="{DynamicResource Brush.Border2}"
BorderThickness="0" BorderThickness="0"
LineBGEmpty = "{DynamicResource Brush.TextDiffView.LineBG1.EMPTY}"
LineBGAdd = "{DynamicResource Brush.TextDiffView.LineBG1.ADD}"
LineBGDeleted = "{DynamicResource Brush.TextDiffView.LineBG1.DELETED}"
SecondaryLineBGAdd = "{DynamicResource Brush.TextDiffView.LineBG2.ADD}"
SecondaryLineBGDeleted = "{DynamicResource Brush.TextDiffView.LineBG2.DELETED}"
Foreground="{DynamicResource Brush.FG1}" Foreground="{DynamicResource Brush.FG1}"
SecondaryFG="{DynamicResource Brush.FG2}" SecondaryFG="{DynamicResource Brush.FG2}"
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
@ -31,6 +36,11 @@
IsOld="True" IsOld="True"
BorderBrush="{DynamicResource Brush.Border2}" BorderBrush="{DynamicResource Brush.Border2}"
BorderThickness="0" BorderThickness="0"
LineBGEmpty = "{DynamicResource Brush.TextDiffView.LineBG1.EMPTY}"
LineBGAdd = "{DynamicResource Brush.TextDiffView.LineBG1.ADD}"
LineBGDeleted = "{DynamicResource Brush.TextDiffView.LineBG1.DELETED}"
SecondaryLineBGAdd = "{DynamicResource Brush.TextDiffView.LineBG2.ADD}"
SecondaryLineBGDeleted = "{DynamicResource Brush.TextDiffView.LineBG2.DELETED}"
Foreground="{DynamicResource Brush.FG1}" Foreground="{DynamicResource Brush.FG1}"
SecondaryFG="{DynamicResource Brush.FG2}" SecondaryFG="{DynamicResource Brush.FG2}"
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
@ -45,6 +55,11 @@
IsOld="False" IsOld="False"
BorderBrush="{DynamicResource Brush.Border2}" BorderBrush="{DynamicResource Brush.Border2}"
BorderThickness="0" BorderThickness="0"
LineBGEmpty = "{DynamicResource Brush.TextDiffView.LineBG1.EMPTY}"
LineBGAdd = "{DynamicResource Brush.TextDiffView.LineBG1.ADD}"
LineBGDeleted = "{DynamicResource Brush.TextDiffView.LineBG1.DELETED}"
SecondaryLineBGAdd = "{DynamicResource Brush.TextDiffView.LineBG2.ADD}"
SecondaryLineBGDeleted = "{DynamicResource Brush.TextDiffView.LineBG2.DELETED}"
Foreground="{DynamicResource Brush.FG1}" Foreground="{DynamicResource Brush.FG1}"
SecondaryFG="{DynamicResource Brush.FG2}" SecondaryFG="{DynamicResource Brush.FG2}"
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"

View file

@ -118,10 +118,6 @@ namespace SourceGit.Views
public class LineBackgroundRenderer : IBackgroundRenderer public class LineBackgroundRenderer : IBackgroundRenderer
{ {
private static readonly Brush BG_EMPTY = new SolidColorBrush(Color.FromArgb(60, 0, 0, 0));
private static readonly Brush BG_ADDED = new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
private static readonly Brush BG_DELETED = new SolidColorBrush(Color.FromArgb(50, 255, 0, 0));
public KnownLayer Layer => KnownLayer.Background; public KnownLayer Layer => KnownLayer.Background;
public LineBackgroundRenderer(CombinedTextDiffPresenter editor) public LineBackgroundRenderer(CombinedTextDiffPresenter editor)
@ -139,7 +135,7 @@ namespace SourceGit.Views
{ {
if (line.FirstDocumentLine == null) if (line.FirstDocumentLine == null)
continue; continue;
var index = line.FirstDocumentLine.LineNumber; var index = line.FirstDocumentLine.LineNumber;
if (index > _editor.DiffData.Lines.Count) if (index > _editor.DiffData.Lines.Count)
break; break;
@ -159,11 +155,11 @@ namespace SourceGit.Views
switch (type) switch (type)
{ {
case Models.TextDiffLineType.None: case Models.TextDiffLineType.None:
return BG_EMPTY; return _editor.LineBGEmpty;
case Models.TextDiffLineType.Added: case Models.TextDiffLineType.Added:
return BG_ADDED; return _editor.LineBGAdd;
case Models.TextDiffLineType.Deleted: case Models.TextDiffLineType.Deleted:
return BG_DELETED; return _editor.LineBGDeleted;
default: default:
return null; return null;
} }
@ -174,9 +170,6 @@ namespace SourceGit.Views
public class LineStyleTransformer : DocumentColorizingTransformer public class LineStyleTransformer : DocumentColorizingTransformer
{ {
private static readonly Brush HL_ADDED = new SolidColorBrush(Color.FromArgb(128, 0, 190, 0));
private static readonly Brush HL_DELETED = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0));
public LineStyleTransformer(CombinedTextDiffPresenter editor) public LineStyleTransformer(CombinedTextDiffPresenter editor)
{ {
_editor = editor; _editor = editor;
@ -202,7 +195,7 @@ namespace SourceGit.Views
if (info.Highlights.Count > 0) if (info.Highlights.Count > 0)
{ {
var bg = info.Type == Models.TextDiffLineType.Added ? HL_ADDED : HL_DELETED; var bg = info.Type == Models.TextDiffLineType.Added ? _editor.SecondaryLineBGAdd : _editor.SecondaryLineBGDeleted;
foreach (var highlight in info.Highlights) foreach (var highlight in info.Highlights)
{ {
ChangeLinePart(line.Offset + highlight.Start, line.Offset + highlight.Start + highlight.Count, v => ChangeLinePart(line.Offset + highlight.Start, line.Offset + highlight.Start + highlight.Count, v =>
@ -225,6 +218,51 @@ namespace SourceGit.Views
set => SetValue(DiffDataProperty, value); set => SetValue(DiffDataProperty, value);
} }
public static readonly StyledProperty<IBrush> LineBGEmptyProperty =
AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(LineBGEmpty), new SolidColorBrush(Color.FromArgb(60, 0, 0, 0)));
public IBrush LineBGEmpty
{
get => GetValue(LineBGEmptyProperty);
set => SetValue(LineBGEmptyProperty, value);
}
public static readonly StyledProperty<IBrush> LineBGAddProperty =
AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(LineBGAdd), new SolidColorBrush(Color.FromArgb(60, 0, 255, 0)));
public IBrush LineBGAdd
{
get => GetValue(LineBGAddProperty);
set => SetValue(LineBGAddProperty, value);
}
public static readonly StyledProperty<IBrush> LineBGDeletedProperty =
AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(LineBGDeleted), new SolidColorBrush(Color.FromArgb(60, 255, 0, 0)));
public IBrush LineBGDeleted
{
get => GetValue(LineBGDeletedProperty);
set => SetValue(LineBGDeletedProperty, value);
}
public static readonly StyledProperty<IBrush> SecondaryLineBGAddProperty =
AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(SecondaryLineBGAdd), new SolidColorBrush(Color.FromArgb(90, 0, 255, 0)));
public IBrush SecondaryLineBGAdd
{
get => GetValue(SecondaryLineBGAddProperty);
set => SetValue(SecondaryLineBGAddProperty, value);
}
public static readonly StyledProperty<IBrush> SecondaryLineBGDeletedProperty =
AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(SecondaryLineBGDeleted), new SolidColorBrush(Color.FromArgb(80, 255, 0, 0)));
public IBrush SecondaryLineBGDeleted
{
get => GetValue(SecondaryLineBGDeletedProperty);
set => SetValue(SecondaryLineBGDeletedProperty, value);
}
public static readonly StyledProperty<IBrush> SecondaryFGProperty = public static readonly StyledProperty<IBrush> SecondaryFGProperty =
AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(SecondaryFG), Brushes.Gray); AvaloniaProperty.Register<CombinedTextDiffPresenter, IBrush>(nameof(SecondaryFG), Brushes.Gray);
@ -499,10 +537,6 @@ namespace SourceGit.Views
public class LineBackgroundRenderer : IBackgroundRenderer public class LineBackgroundRenderer : IBackgroundRenderer
{ {
private static readonly Brush BG_EMPTY = new SolidColorBrush(Color.FromArgb(60, 0, 0, 0));
private static readonly Brush BG_ADDED = new SolidColorBrush(Color.FromArgb(60, 0, 255, 0));
private static readonly Brush BG_DELETED = new SolidColorBrush(Color.FromArgb(60, 255, 0, 0));
public KnownLayer Layer => KnownLayer.Background; public KnownLayer Layer => KnownLayer.Background;
public LineBackgroundRenderer(SingleSideTextDiffPresenter editor) public LineBackgroundRenderer(SingleSideTextDiffPresenter editor)
@ -521,7 +555,7 @@ namespace SourceGit.Views
{ {
if (line.FirstDocumentLine == null) if (line.FirstDocumentLine == null)
continue; continue;
var index = line.FirstDocumentLine.LineNumber; var index = line.FirstDocumentLine.LineNumber;
if (index > infos.Count) if (index > infos.Count)
break; break;
@ -541,11 +575,11 @@ namespace SourceGit.Views
switch (type) switch (type)
{ {
case Models.TextDiffLineType.None: case Models.TextDiffLineType.None:
return BG_EMPTY; return _editor.LineBGEmpty;
case Models.TextDiffLineType.Added: case Models.TextDiffLineType.Added:
return BG_ADDED; return _editor.LineBGAdd;
case Models.TextDiffLineType.Deleted: case Models.TextDiffLineType.Deleted:
return BG_DELETED; return _editor.LineBGDeleted;
default: default:
return null; return null;
} }
@ -556,9 +590,6 @@ namespace SourceGit.Views
public class LineStyleTransformer : DocumentColorizingTransformer public class LineStyleTransformer : DocumentColorizingTransformer
{ {
private static readonly Brush HL_ADDED = new SolidColorBrush(Color.FromArgb(90, 0, 255, 0));
private static readonly Brush HL_DELETED = new SolidColorBrush(Color.FromArgb(80, 255, 0, 0));
public LineStyleTransformer(SingleSideTextDiffPresenter editor) public LineStyleTransformer(SingleSideTextDiffPresenter editor)
{ {
_editor = editor; _editor = editor;
@ -585,7 +616,7 @@ namespace SourceGit.Views
if (info.Highlights.Count > 0) if (info.Highlights.Count > 0)
{ {
var bg = info.Type == Models.TextDiffLineType.Added ? HL_ADDED : HL_DELETED; var bg = info.Type == Models.TextDiffLineType.Added ? _editor.LineBGAdd : _editor.LineBGDeleted;
foreach (var highlight in info.Highlights) foreach (var highlight in info.Highlights)
{ {
ChangeLinePart(line.Offset + highlight.Start, line.Offset + highlight.Start + highlight.Count, v => ChangeLinePart(line.Offset + highlight.Start, line.Offset + highlight.Start + highlight.Count, v =>
@ -617,6 +648,51 @@ namespace SourceGit.Views
set => SetValue(DiffDataProperty, value); set => SetValue(DiffDataProperty, value);
} }
public static readonly StyledProperty<IBrush> LineBGEmptyProperty =
AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(LineBGEmpty), new SolidColorBrush(Color.FromArgb(60, 0, 0, 0)));
public IBrush LineBGEmpty
{
get => GetValue(LineBGEmptyProperty);
set => SetValue(LineBGEmptyProperty, value);
}
public static readonly StyledProperty<IBrush> LineBGAddProperty =
AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(LineBGAdd), new SolidColorBrush(Color.FromArgb(60, 0, 255, 0)));
public IBrush LineBGAdd
{
get => GetValue(LineBGAddProperty);
set => SetValue(LineBGAddProperty, value);
}
public static readonly StyledProperty<IBrush> LineBGDeletedProperty =
AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(LineBGDeleted), new SolidColorBrush(Color.FromArgb(60, 255, 0, 0)));
public IBrush LineBGDeleted
{
get => GetValue(LineBGDeletedProperty);
set => SetValue(LineBGDeletedProperty, value);
}
public static readonly StyledProperty<IBrush> SecondaryLineBGAddProperty =
AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(SecondaryLineBGAdd), new SolidColorBrush(Color.FromArgb(90, 0, 255, 0)));
public IBrush SecondaryLineBGAdd
{
get => GetValue(SecondaryLineBGAddProperty);
set => SetValue(SecondaryLineBGAddProperty, value);
}
public static readonly StyledProperty<IBrush> SecondaryLineBGDeletedProperty =
AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(SecondaryLineBGDeleted), new SolidColorBrush(Color.FromArgb(80, 255, 0, 0)));
public IBrush SecondaryLineBGDeleted
{
get => GetValue(SecondaryLineBGDeletedProperty);
set => SetValue(SecondaryLineBGDeletedProperty, value);
}
public static readonly StyledProperty<IBrush> SecondaryFGProperty = public static readonly StyledProperty<IBrush> SecondaryFGProperty =
AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(SecondaryFG), Brushes.Gray); AvaloniaProperty.Register<SingleSideTextDiffPresenter, IBrush>(nameof(SecondaryFG), Brushes.Gray);
@ -736,7 +812,7 @@ namespace SourceGit.Views
}; };
menu.Items.Add(copy); menu.Items.Add(copy);
TextArea.TextView.OpenContextMenu(menu); TextArea.TextView.OpenContextMenu(menu);
e.Handled = true; e.Handled = true;
} }