Skip to content

Commit c4929dd

Browse files
committed
refactor: remove unused ConterPresenter
Signed-off-by: leo <longshuang@msn.cn>
1 parent b15d714 commit c4929dd

File tree

2 files changed

+26
-109
lines changed

2 files changed

+26
-109
lines changed

src/Views/Repository.axaml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,19 @@
131131
<Grid Classes="view_mode" ColumnDefinitions="Auto,*,Auto,Auto,Auto">
132132
<Path Grid.Column="0" Classes="icon" Data="{StaticResource Icons.Changes}"/>
133133
<TextBlock Grid.Column="1" Classes="header" Text="{DynamicResource Text.WorkingCopy}"/>
134-
<v:CounterPresenter Grid.Column="2"
135-
Margin="6,0"
136-
VerticalAlignment="Center"
137-
Count="{Binding LocalChangesCount}"
138-
FontFamily="{DynamicResource Fonts.Monospace}"
139-
FontSize="10"
140-
Foreground="{DynamicResource Brush.BadgeFG}"
141-
Background="{DynamicResource Brush.Badge}"/>
134+
<Border Grid.Column="2"
135+
Height="18"
136+
CornerRadius="9"
137+
Padding="9,0"
138+
Margin="6,0"
139+
VerticalAlignment="Center"
140+
Background="{DynamicResource Brush.Badge}"
141+
IsVisible="{Binding LocalChangesCount, Mode=OneWay, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
142+
<TextBlock Text="{Binding LocalChangesCount, Mode=OneWay}"
143+
Foreground="{DynamicResource Brush.BadgeFG}"
144+
FontFamily="{DynamicResource Fonts.Monospace}"
145+
FontSize="10"/>
146+
</Border>
142147
<Path Grid.Column="3"
143148
Width="12" Height="12"
144149
Margin="0,0,6,0"
@@ -159,14 +164,19 @@
159164
<Grid Classes="view_mode" ColumnDefinitions="Auto,*,Auto,Auto">
160165
<Path Grid.Column="0" Classes="icon" Data="{StaticResource Icons.Stashes}"/>
161166
<TextBlock Grid.Column="1" Classes="header" Text="{DynamicResource Text.Stashes}"/>
162-
<v:CounterPresenter Grid.Column="2"
163-
Margin="6,0"
164-
VerticalAlignment="Center"
165-
Count="{Binding StashesCount}"
166-
FontFamily="{DynamicResource Fonts.Monospace}"
167-
FontSize="10"
168-
Foreground="{DynamicResource Brush.BadgeFG}"
169-
Background="{DynamicResource Brush.Badge}"/>
167+
<Border Grid.Column="2"
168+
Height="18"
169+
CornerRadius="9"
170+
Padding="6,0"
171+
Margin="6,0"
172+
VerticalAlignment="Center"
173+
Background="{DynamicResource Brush.Badge}"
174+
IsVisible="{Binding StashesCount, Mode=OneWay, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
175+
<TextBlock Text="{Binding StashesCount, Mode=OneWay}"
176+
Foreground="{DynamicResource Brush.BadgeFG}"
177+
FontFamily="{DynamicResource Fonts.Monospace}"
178+
FontSize="10"/>
179+
</Border>
170180
<Button Grid.Column="3"
171181
Classes="icon_button"
172182
Width="26" Height="26"

src/Views/Repository.axaml.cs

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,12 @@
11
using System;
2-
using System.Globalization;
32

43
using Avalonia;
54
using Avalonia.Controls;
65
using Avalonia.Input;
76
using Avalonia.Interactivity;
8-
using Avalonia.Media;
97

108
namespace SourceGit.Views
119
{
12-
public class CounterPresenter : Control
13-
{
14-
public static readonly StyledProperty<int> CountProperty =
15-
AvaloniaProperty.Register<CounterPresenter, int>(nameof(Count));
16-
17-
public int Count
18-
{
19-
get => GetValue(CountProperty);
20-
set => SetValue(CountProperty, value);
21-
}
22-
23-
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
24-
TextBlock.FontFamilyProperty.AddOwner<CounterPresenter>();
25-
26-
public FontFamily FontFamily
27-
{
28-
get => GetValue(FontFamilyProperty);
29-
set => SetValue(FontFamilyProperty, value);
30-
}
31-
32-
public static readonly StyledProperty<double> FontSizeProperty =
33-
TextBlock.FontSizeProperty.AddOwner<CounterPresenter>();
34-
35-
public double FontSize
36-
{
37-
get => GetValue(FontSizeProperty);
38-
set => SetValue(FontSizeProperty, value);
39-
}
40-
41-
public static readonly StyledProperty<IBrush> ForegroundProperty =
42-
AvaloniaProperty.Register<CounterPresenter, IBrush>(nameof(Foreground), Brushes.White);
43-
44-
public IBrush Foreground
45-
{
46-
get => GetValue(ForegroundProperty);
47-
set => SetValue(ForegroundProperty, value);
48-
}
49-
50-
public static readonly StyledProperty<IBrush> BackgroundProperty =
51-
AvaloniaProperty.Register<CounterPresenter, IBrush>(nameof(Background), Brushes.White);
52-
53-
public IBrush Background
54-
{
55-
get => GetValue(BackgroundProperty);
56-
set => SetValue(BackgroundProperty, value);
57-
}
58-
59-
static CounterPresenter()
60-
{
61-
AffectsMeasure<CounterPresenter>(
62-
FontSizeProperty,
63-
FontFamilyProperty,
64-
ForegroundProperty,
65-
CountProperty);
66-
}
67-
68-
public override void Render(DrawingContext context)
69-
{
70-
base.Render(context);
71-
72-
if (_label != null)
73-
{
74-
context.DrawRectangle(Background, null, new RoundedRect(new Rect(0, 0, _label.Width + 18, 18), new CornerRadius(9)));
75-
context.DrawText(_label, new Point(9, 9 - _label.Height * 0.5));
76-
}
77-
}
78-
79-
protected override Size MeasureOverride(Size availableSize)
80-
{
81-
if (Count > 0)
82-
{
83-
_label = new FormattedText(
84-
Count.ToString(),
85-
CultureInfo.CurrentCulture,
86-
FlowDirection.LeftToRight,
87-
new Typeface(FontFamily),
88-
FontSize,
89-
Foreground);
90-
}
91-
else
92-
{
93-
_label = null;
94-
}
95-
96-
InvalidateVisual();
97-
return _label != null ? new Size(_label.Width + 18, 18) : new Size(0, 0);
98-
}
99-
100-
private FormattedText _label = null;
101-
}
102-
10310
public partial class Repository : UserControl
10411
{
10512
public Repository()

0 commit comments

Comments
 (0)