From 14469b13990d9c6d93b447b4b967bd894167ba49 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 18 Jul 2024 10:46:39 +0800 Subject: [PATCH] theme: add `ThemeOverrides.OpacityForNotMergedCommits` to customize the opacity of commits that not belongs (haven't been merged) to current branch in histories (#268) --- src/App.axaml.cs | 2 ++ src/Converters/BoolConverters.cs | 7 ------- src/Models/Commit.cs | 10 ++++++++++ src/Models/ThemeOverrides.cs | 1 + src/Views/Histories.axaml | 18 +++++++++--------- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 67bd3aad..7abf8293 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -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; } diff --git a/src/Converters/BoolConverters.cs b/src/Converters/BoolConverters.cs index 2eb8c60a..2d738700 100644 --- a/src/Converters/BoolConverters.cs +++ b/src/Converters/BoolConverters.cs @@ -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 ToPageTabWidth = new FuncValueConverter(x => x ? 200 : double.NaN); - - public static readonly FuncValueConverter HalfIfFalse = - new FuncValueConverter(x => x ? 1 : 0.5); - - public static readonly FuncValueConverter BoldIfTrue = - new FuncValueConverter(x => x ? FontWeight.Bold : FontWeight.Regular); } } diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 30c2c499..1137ad0c 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -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; } } diff --git a/src/Models/ThemeOverrides.cs b/src/Models/ThemeOverrides.cs index e14b1f1a..ccd9f57e 100644 --- a/src/Models/ThemeOverrides.cs +++ b/src/Models/ThemeOverrides.cs @@ -8,6 +8,7 @@ namespace SourceGit.Models { public Dictionary BasicColors { get; set; } = new Dictionary(); public double GraphPenThickness { get; set; } = 2; + public double OpacityForNotMergedCommits { get; set; } = 0.5; public List GraphColors { get; set; } = new List(); } } diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index 6e89a036..1a74a08a 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -103,8 +103,8 @@ + Opacity="{Binding Opacity}" + FontWeight="{Binding FontWeight}"/> @@ -124,13 +124,13 @@ VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}" - Opacity="{Binding IsMerged, Converter={x:Static c:BoolConverters.HalfIfFalse}}"/> + Opacity="{Binding Opacity}"/> + Opacity="{Binding Opacity}" + FontWeight="{Binding FontWeight}"/> @@ -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}"/> @@ -169,8 +169,8 @@