Skip to content

Commit 408067c

Browse files
committed
feat: 添加对悬停相关提交的支持,更新图形和视图模型以增强用户交互
1 parent 78f2394 commit 408067c

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/Models/CommitGraph.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class Dot
5757
public Point Center;
5858
public int Color;
5959
public bool IsMerged;
60+
public bool IsHoveredRelated = false;
6061
}
6162

6263
public List<Path> Paths { get; } = [];

src/ViewModels/Histories.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,13 @@ public void ProcessHoveredCommit(Models.Commit commit)
246246

247247
_commits.ForEach(c => c.IsHoveredRelated = false);
248248
childrens.ForEach(c => c.IsHoveredRelated = true);
249+
Graph.Dots.ForEach(p => p.IsHoveredRelated = false);
250+
childrens.ForEach(c => Graph.Dots[c.Index].IsHoveredRelated = true);
251+
249252
HoveredCommitId = commit.Index;
250-
foreach (var c in childrens)
251-
{
252-
Console.WriteLine($"{c.Index}.{c.Subject}");
253-
}
254-
System.Console.WriteLine(childrens.Count);
253+
// foreach (var c in childrens)
254+
// Console.WriteLine($"{c.Index}.{c.Subject}");
255+
// System.Console.WriteLine(childrens.Count);
255256
}
256257

257258
public void MarkLastSelectedCommitsAsSelected(params IList<Models.Commit> commits)

src/Views/CommitGraph.cs

Lines changed: 11 additions & 7 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 = 0.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)
@@ -217,6 +219,7 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
217219
var dotFillPen = new Pen(dotFill, 2);
218220
var grayedPen = new Pen(Brushes.Gray, Models.CommitGraph.Pens[0].Thickness);
219221
var onlyHighlightCurrentBranch = OnlyHighlightCurrentBranch;
222+
var hoverBold = 1.0;
220223

221224
foreach (var dot in graph.Dots)
222225
{
@@ -230,26 +233,27 @@ private void DrawAnchors(DrawingContext context, Models.CommitGraph graph, doubl
230233
var pen = Models.CommitGraph.Pens[dot.Color];
231234
if (!dot.IsMerged && onlyHighlightCurrentBranch)
232235
pen = grayedPen;
236+
hoverBold = dot.IsHoveredRelated ? 1 : 0;
233237

234238
switch (dot.Type)
235239
{
236240
case Models.CommitGraph.DotType.Head:
237-
context.DrawEllipse(dotFill, pen, center, 6, 6);
241+
context.DrawEllipse(dotFill, pen, center, 6 + hoverBold, 6 + hoverBold);
238242
context.DrawEllipse(pen.Brush, null, center, 3, 3);
239243
break;
240244
case Models.CommitGraph.DotType.Merge:
241-
context.DrawEllipse(pen.Brush, null, center, 6, 6);
245+
context.DrawEllipse(pen.Brush, null, center, 6 + hoverBold, 6 + hoverBold);
242246
context.DrawLine(dotFillPen, new Point(center.X, center.Y - 3), new Point(center.X, center.Y + 3));
243247
context.DrawLine(dotFillPen, new Point(center.X - 3, center.Y), new Point(center.X + 3, center.Y));
244248
break;
245249
case Models.CommitGraph.DotType.Filter:
246-
context.DrawEllipse(pen.Brush, null, center, 7, 7);
250+
context.DrawEllipse(pen.Brush, null, center, 7 + hoverBold, 7 + hoverBold);
247251
context.DrawLine(dotFillPen, new Point(center.X, center.Y - 5), new Point(center.X, center.Y + 5));
248252
context.DrawLine(dotFillPen, new Point(center.X - 4, center.Y - 3), new Point(center.X + 4, center.Y + 3));
249253
context.DrawLine(dotFillPen, new Point(center.X + 4, center.Y - 3), new Point(center.X - 4, center.Y + 3));
250254
break;
251255
default:
252-
context.DrawEllipse(dotFill, pen, center, 3, 3);
256+
context.DrawEllipse(dotFill, pen, center, 3 + hoverBold, 3 + hoverBold);
253257
break;
254258
}
255259
}

0 commit comments

Comments
 (0)