mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-24 02:40:24 +08:00
refactor: remove unused ConterPresenter
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -131,14 +131,19 @@
|
||||
<Grid Classes="view_mode" ColumnDefinitions="Auto,*,Auto,Auto,Auto">
|
||||
<Path Grid.Column="0" Classes="icon" Data="{StaticResource Icons.Changes}"/>
|
||||
<TextBlock Grid.Column="1" Classes="header" Text="{DynamicResource Text.WorkingCopy}"/>
|
||||
<v:CounterPresenter Grid.Column="2"
|
||||
Margin="6,0"
|
||||
VerticalAlignment="Center"
|
||||
Count="{Binding LocalChangesCount}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="10"
|
||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||
Background="{DynamicResource Brush.Badge}"/>
|
||||
<Border Grid.Column="2"
|
||||
Height="18"
|
||||
CornerRadius="9"
|
||||
Padding="9,0"
|
||||
Margin="6,0"
|
||||
VerticalAlignment="Center"
|
||||
Background="{DynamicResource Brush.Badge}"
|
||||
IsVisible="{Binding LocalChangesCount, Mode=OneWay, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
|
||||
<TextBlock Text="{Binding LocalChangesCount, Mode=OneWay}"
|
||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="10"/>
|
||||
</Border>
|
||||
<Path Grid.Column="3"
|
||||
Width="12" Height="12"
|
||||
Margin="0,0,6,0"
|
||||
@@ -159,14 +164,19 @@
|
||||
<Grid Classes="view_mode" ColumnDefinitions="Auto,*,Auto,Auto">
|
||||
<Path Grid.Column="0" Classes="icon" Data="{StaticResource Icons.Stashes}"/>
|
||||
<TextBlock Grid.Column="1" Classes="header" Text="{DynamicResource Text.Stashes}"/>
|
||||
<v:CounterPresenter Grid.Column="2"
|
||||
Margin="6,0"
|
||||
VerticalAlignment="Center"
|
||||
Count="{Binding StashesCount}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="10"
|
||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||
Background="{DynamicResource Brush.Badge}"/>
|
||||
<Border Grid.Column="2"
|
||||
Height="18"
|
||||
CornerRadius="9"
|
||||
Padding="6,0"
|
||||
Margin="6,0"
|
||||
VerticalAlignment="Center"
|
||||
Background="{DynamicResource Brush.Badge}"
|
||||
IsVisible="{Binding StashesCount, Mode=OneWay, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
|
||||
<TextBlock Text="{Binding StashesCount, Mode=OneWay}"
|
||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="10"/>
|
||||
</Border>
|
||||
<Button Grid.Column="3"
|
||||
Classes="icon_button"
|
||||
Width="26" Height="26"
|
||||
|
||||
@@ -1,105 +1,12 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class CounterPresenter : Control
|
||||
{
|
||||
public static readonly StyledProperty<int> CountProperty =
|
||||
AvaloniaProperty.Register<CounterPresenter, int>(nameof(Count));
|
||||
|
||||
public int Count
|
||||
{
|
||||
get => GetValue(CountProperty);
|
||||
set => SetValue(CountProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
|
||||
TextBlock.FontFamilyProperty.AddOwner<CounterPresenter>();
|
||||
|
||||
public FontFamily FontFamily
|
||||
{
|
||||
get => GetValue(FontFamilyProperty);
|
||||
set => SetValue(FontFamilyProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<double> FontSizeProperty =
|
||||
TextBlock.FontSizeProperty.AddOwner<CounterPresenter>();
|
||||
|
||||
public double FontSize
|
||||
{
|
||||
get => GetValue(FontSizeProperty);
|
||||
set => SetValue(FontSizeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<IBrush> ForegroundProperty =
|
||||
AvaloniaProperty.Register<CounterPresenter, IBrush>(nameof(Foreground), Brushes.White);
|
||||
|
||||
public IBrush Foreground
|
||||
{
|
||||
get => GetValue(ForegroundProperty);
|
||||
set => SetValue(ForegroundProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<IBrush> BackgroundProperty =
|
||||
AvaloniaProperty.Register<CounterPresenter, IBrush>(nameof(Background), Brushes.White);
|
||||
|
||||
public IBrush Background
|
||||
{
|
||||
get => GetValue(BackgroundProperty);
|
||||
set => SetValue(BackgroundProperty, value);
|
||||
}
|
||||
|
||||
static CounterPresenter()
|
||||
{
|
||||
AffectsMeasure<CounterPresenter>(
|
||||
FontSizeProperty,
|
||||
FontFamilyProperty,
|
||||
ForegroundProperty,
|
||||
CountProperty);
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
base.Render(context);
|
||||
|
||||
if (_label != null)
|
||||
{
|
||||
context.DrawRectangle(Background, null, new RoundedRect(new Rect(0, 0, _label.Width + 18, 18), new CornerRadius(9)));
|
||||
context.DrawText(_label, new Point(9, 9 - _label.Height * 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
if (Count > 0)
|
||||
{
|
||||
_label = new FormattedText(
|
||||
Count.ToString(),
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(FontFamily),
|
||||
FontSize,
|
||||
Foreground);
|
||||
}
|
||||
else
|
||||
{
|
||||
_label = null;
|
||||
}
|
||||
|
||||
InvalidateVisual();
|
||||
return _label != null ? new Size(_label.Width + 18, 18) : new Size(0, 0);
|
||||
}
|
||||
|
||||
private FormattedText _label = null;
|
||||
}
|
||||
|
||||
public partial class Repository : UserControl
|
||||
{
|
||||
public Repository()
|
||||
|
||||
Reference in New Issue
Block a user