theme: add ThemeOverrides.OpacityForNotMergedCommits to customize the opacity of commits that not belongs (haven't been merged) to current branch in histories (#268)

This commit is contained in:
leo 2024-07-18 10:46:39 +08:00
parent b2ed1b283a
commit 14469b1399
No known key found for this signature in database
5 changed files with 22 additions and 16 deletions

View file

@ -188,6 +188,8 @@ namespace SourceGit
else
Models.CommitGraph.SetDefaultPens(overrides.GraphPenThickness);
Models.Commit.OpacityForNotMerged = overrides.OpacityForNotMergedCommits;
app.Resources.MergedDictionaries.Add(resDic);
app._themeOverrides = resDic;
}

View file

@ -1,5 +1,4 @@
using Avalonia.Data.Converters;
using Avalonia.Media;
namespace SourceGit.Converters
{
@ -7,11 +6,5 @@ namespace SourceGit.Converters
{
public static readonly FuncValueConverter<bool, double> ToPageTabWidth =
new FuncValueConverter<bool, double>(x => x ? 200 : double.NaN);
public static readonly FuncValueConverter<bool, double> HalfIfFalse =
new FuncValueConverter<bool, double>(x => x ? 1 : 0.5);
public static readonly FuncValueConverter<bool, FontWeight> BoldIfTrue =
new FuncValueConverter<bool, FontWeight>(x => x ? FontWeight.Bold : FontWeight.Regular);
}
}

View file

@ -2,11 +2,18 @@
using System.Collections.Generic;
using Avalonia;
using Avalonia.Media;
namespace SourceGit.Models
{
public class Commit
{
public static double OpacityForNotMerged
{
get;
set;
} = 0.5;
public string SHA { get; set; } = string.Empty;
public User Author { get; set; } = User.Invalid;
public ulong AuthorTime { get; set; } = 0;
@ -25,5 +32,8 @@ namespace SourceGit.Models
public bool IsCommitterVisible => !Author.Equals(Committer) || AuthorTime != CommitterTime;
public bool IsCurrentHead => Decorators.Find(x => x.Type is DecoratorType.CurrentBranchHead or DecoratorType.CurrentCommitHead) != null;
public double Opacity => IsMerged ? 1 : OpacityForNotMerged;
public FontWeight FontWeight => IsCurrentHead ? FontWeight.Bold : FontWeight.Regular;
}
}

View file

@ -8,6 +8,7 @@ namespace SourceGit.Models
{
public Dictionary<string, Color> BasicColors { get; set; } = new Dictionary<string, Color>();
public double GraphPenThickness { get; set; } = 2;
public double OpacityForNotMergedCommits { get; set; } = 0.5;
public List<Color> GraphColors { get; set; } = new List<Color>();
}
}

View file

@ -103,8 +103,8 @@
<TextBlock Classes="monospace"
Text="{Binding Subject}"
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
Opacity="{Binding Opacity}"
FontWeight="{Binding FontWeight}"/>
</StackPanel>
</Border>
</DataTemplate>
@ -124,13 +124,13 @@
VerticalAlignment="Center"
IsHitTestVisible="False"
User="{Binding Author}"
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"/>
Opacity="{Binding Opacity}"/>
<TextBlock Grid.Column="1"
Classes="monospace"
Text="{Binding Author.Name}"
Margin="8,0,0,0"
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
Opacity="{Binding Opacity}"
FontWeight="{Binding FontWeight}"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@ -147,8 +147,8 @@
Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
Margin="8,0"
HorizontalAlignment="Center"
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"/>
Opacity="{Binding Opacity}"
FontWeight="{Binding FontWeight}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
@ -169,8 +169,8 @@
<v:CommitTimeTextBlock Classes="monospace"
Margin="8,0"
HorizontalAlignment="Center"
Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"
FontWeight="{Binding IsCurrentHead, Converter={x:Static c:BoolConverters.BoldIfTrue}}"
Opacity="{Binding Opacity}"
FontWeight="{Binding FontWeight}"
Timestamp="{Binding CommitterTime}"
ShowAsDateTime="{Binding Source={x:Static vm:Preference.Instance}, Path=!DisplayTimeAsPeriodInHistories}"/>
</DataTemplate>