Skip to content

Commit 9b01880

Browse files
committed
feat: 添加对悬停项关联的聚焦显示支持的支持,更新相关绘制逻辑以增强用户体验
1 parent dea814c commit 9b01880

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/Models/CommitGraph.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34

45
using Avalonia;
56
using Avalonia.Media;
@@ -32,6 +33,8 @@ public class Path(int color, bool isMerged)
3233
public List<Point> Points { get; } = [];
3334
public int Color { get; } = color;
3435
public bool IsMerged { get; } = isMerged;
36+
37+
public bool IsHoveredRelated { get; set; } = false;
3538
}
3639

3740
public class Link

src/ViewModels/Histories.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,28 @@ public void Select(IList commits, object selectedCommit)
238238
public void ProcessHoveredCommit(Models.Commit commit)
239239
{
240240
if (commit == null)
241+
{
242+
_commits.ForEach(c => c.IsHoveredRelated = false);
243+
_graph.Paths.ForEach(p => p.IsHoveredRelated = false);
241244
return;
245+
}
242246

243247
var childrens = this.GetChildrensPathInCurHistory(commit, out _, 0);
244-
Console.WriteLine($"=========");
245248
childrens.Reverse();
246249

247250
_commits.ForEach(c => c.IsHoveredRelated = false);
248251
childrens.ForEach(c => c.IsHoveredRelated = true);
252+
253+
_graph.Paths.ForEach(p => p.IsHoveredRelated = false);
254+
_graph.Paths[commit.PathIndex].IsHoveredRelated = true;
255+
childrens.ForEach(c => _graph.Paths[c.PathIndex].IsHoveredRelated = true);
256+
249257
HoveredCommitIndex = commit.Index;
250-
foreach (var c in childrens)
251-
{
252-
Console.WriteLine($"{c.Index}.{c.Subject}");
253-
}
254-
System.Console.WriteLine(childrens.Count);
258+
// Console.WriteLine($"=========");
259+
// foreach (var c in childrens)
260+
// Console.WriteLine($"{c.Index}.{c.Subject}");
261+
// System.Console.WriteLine(childrens.Count);
255262
}
256-
257263
public void MarkLastSelectedCommitsAsSelected(params IList<Models.Commit> commits)
258264
{
259265
var availableCommits = Commits.Where(x => commits.Any(y => y.SHA == x.SHA)).ToList();

src/Views/CommitGraph.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public override void Render(DrawingContext context)
8484

8585
private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double top, double bottom, double rowHeight)
8686
{
87+
var hoverBold = 2.0;
8788
var grayedPen = new Pen(new SolidColorBrush(Colors.Gray, 0.4), Models.CommitGraph.Pens[0].Thickness);
88-
var grayedPenHover = new Pen(new SolidColorBrush(Colors.Gray, 0.7), Models.CommitGraph.Pens[0].Thickness);
89+
var grayedPenHover = new Pen(grayedPen.Brush, grayedPen.Thickness + hoverBold);
8990
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch;
9091

9192
if (onlyHighlightCurrentBranch)
@@ -127,6 +128,7 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
127128

128129
var geo = new StreamGeometry();
129130
var pen = Models.CommitGraph.Pens[line.Color];
131+
var penHover = new Pen(pen.Brush, pen.Thickness + hoverBold);
130132

131133
using (var ctx = geo.Open())
132134
{
@@ -182,9 +184,9 @@ private void DrawCurves(DrawingContext context, Models.CommitGraph graph, double
182184

183185

184186
if (!line.IsMerged && onlyHighlightCurrentBranch)
185-
context.DrawGeometry(null, grayedPen, geo);
187+
context.DrawGeometry(null, line.IsHoveredRelated ? grayedPenHover : grayedPen, geo);
186188
else
187-
context.DrawGeometry(null, pen, geo);
189+
context.DrawGeometry(null, line.IsHoveredRelated ? penHover : pen, geo);
188190
}
189191

190192
foreach (var link in graph.Links)

0 commit comments

Comments
 (0)