Skip to content

Commit ed22916

Browse files
committed
enhance: allow wrap commit refs in INFORMATION page (#807)
1 parent 6c795e1 commit ed22916

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/Views/CommitBaseInfo.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@
172172

173173
<!-- REFS -->
174174
<TextBlock Grid.Row="3" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Refs}" IsVisible="{Binding HasDecorators}"/>
175-
<Border Grid.Row="3" Grid.Column="1" Margin="12,0,0,0" Height="24" IsVisible="{Binding HasDecorators}">
175+
<Border Grid.Row="3" Grid.Column="1" Margin="12,0,0,0" MinHeight="24" IsVisible="{Binding HasDecorators}">
176176
<v:CommitRefsPresenter TagBackground="{DynamicResource Brush.DecoratorTag}"
177177
Foreground="{DynamicResource Brush.FG1}"
178178
FontFamily="{DynamicResource Fonts.Primary}"
179179
FontSize="11"
180-
VerticalAlignment="Center"
180+
AllowWrap="True"
181+
Margin="0,4,0,0"
181182
UseGraphColor="False"/>
182183
</Border>
183184

src/Views/CommitRefsPresenter.cs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ public IBrush TagBackground
7373
set => SetValue(TagBackgroundProperty, value);
7474
}
7575

76+
public static readonly StyledProperty<bool> AllowWrapProperty =
77+
AvaloniaProperty.Register<CommitRefsPresenter, bool>(nameof(AllowWrap));
78+
79+
public bool AllowWrap
80+
{
81+
get => GetValue(AllowWrapProperty);
82+
set => SetValue(AllowWrapProperty, value);
83+
}
84+
7685
static CommitRefsPresenter()
7786
{
7887
AffectsMeasure<CommitRefsPresenter>(
@@ -93,10 +102,19 @@ public override void Render(DrawingContext context)
93102
var useGraphColor = UseGraphColor;
94103
var fg = Foreground;
95104
var bg = Background;
105+
var allowWrap = AllowWrap;
96106
var x = 1.0;
107+
var y = 0.0;
108+
97109
foreach (var item in _items)
98110
{
99-
var entireRect = new RoundedRect(new Rect(x, 0, item.Width, 16), new CornerRadius(2));
111+
if (allowWrap && x > 1.0 && x + item.Width > Bounds.Width)
112+
{
113+
x = 1.0;
114+
y += 20.0;
115+
}
116+
117+
var entireRect = new RoundedRect(new Rect(x, y, item.Width, 16), new CornerRadius(2));
100118

101119
if (item.IsHead)
102120
{
@@ -109,24 +127,24 @@ public override void Render(DrawingContext context)
109127
context.DrawRectangle(item.Brush, null, entireRect);
110128
}
111129

112-
context.DrawText(item.Label, new Point(x + 16, 8.0 - item.Label.Height * 0.5));
130+
context.DrawText(item.Label, new Point(x + 16, y + 8.0 - item.Label.Height * 0.5));
113131
}
114132
else
115133
{
116134
if (bg != null)
117135
context.DrawRectangle(bg, null, entireRect);
118136

119-
var labelRect = new RoundedRect(new Rect(x + 16, 0, item.Label.Width + 8, 16), new CornerRadius(0, 2, 2, 0));
137+
var labelRect = new RoundedRect(new Rect(x + 16, y, item.Label.Width + 8, 16), new CornerRadius(0, 2, 2, 0));
120138
using (context.PushOpacity(.2))
121139
context.DrawRectangle(item.Brush, null, labelRect);
122140

123-
context.DrawLine(new Pen(item.Brush), new Point(x + 16, 0), new Point(x + 16, 16));
124-
context.DrawText(item.Label, new Point(x + 20, 8.0 - item.Label.Height * 0.5));
141+
context.DrawLine(new Pen(item.Brush), new Point(x + 16, y), new Point(x + 16, y + 16));
142+
context.DrawText(item.Label, new Point(x + 20, y + 8.0 - item.Label.Height * 0.5));
125143
}
126144

127145
context.DrawRectangle(null, new Pen(item.Brush), entireRect);
128146

129-
using (context.PushTransform(Matrix.CreateTranslation(x + 3, 3)))
147+
using (context.PushTransform(Matrix.CreateTranslation(x + 3, y + 3)))
130148
context.DrawGeometry(fg, null, item.Icon);
131149

132150
x += item.Width + 4;
@@ -157,6 +175,9 @@ protected override Size MeasureOverride(Size availableSize)
157175
var tagBG = TagBackground;
158176
var labelSize = FontSize;
159177
var requiredWidth = 0.0;
178+
var requiredHeight = 16.0;
179+
var x = 0.0;
180+
var allowWrap = AllowWrap;
160181

161182
foreach (var decorator in refs)
162183
{
@@ -211,11 +232,24 @@ protected override Size MeasureOverride(Size availableSize)
211232
item.Width = 16 + (isHead ? 0 : 4) + label.Width + 4;
212233
_items.Add(item);
213234

214-
requiredWidth += item.Width + 4;
235+
x += item.Width + 4;
236+
if (allowWrap)
237+
{
238+
if (x > availableSize.Width)
239+
{
240+
requiredHeight += 20.0;
241+
x = item.Width;
242+
}
243+
}
215244
}
216245

246+
if (allowWrap && requiredHeight > 16.0)
247+
requiredWidth = availableSize.Width;
248+
else
249+
requiredWidth = x + 2;
250+
217251
InvalidateVisual();
218-
return new Size(requiredWidth + 2, 16);
252+
return new Size(requiredWidth, requiredHeight);
219253
}
220254

221255
InvalidateVisual();

0 commit comments

Comments
 (0)