mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-24 05:35:00 +00:00
style: add .editorconfig for code formatting. see issu #25
This commit is contained in:
parent
a8eeea4f78
commit
18aaa0a143
225 changed files with 7781 additions and 3911 deletions
|
@ -1,14 +1,17 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using System;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace SourceGit.Views {
|
||||
public class Avatar : Control, Models.IAvatarHost {
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class Avatar : Control, Models.IAvatarHost
|
||||
{
|
||||
private static readonly GradientStops[] FALLBACK_GRADIENTS = [
|
||||
new GradientStops() { new GradientStop(Colors.Orange, 0), new GradientStop(Color.FromRgb(255, 213, 134), 1) },
|
||||
new GradientStops() { new GradientStop(Colors.DodgerBlue, 0), new GradientStop(Colors.LightSkyBlue, 1) },
|
||||
|
@ -20,19 +23,24 @@ namespace SourceGit.Views {
|
|||
public static readonly StyledProperty<Models.User> UserProperty =
|
||||
AvaloniaProperty.Register<Avatar, Models.User>(nameof(User));
|
||||
|
||||
public Models.User User {
|
||||
public Models.User User
|
||||
{
|
||||
get => GetValue(UserProperty);
|
||||
set => SetValue(UserProperty, value);
|
||||
}
|
||||
|
||||
static Avatar() {
|
||||
static Avatar()
|
||||
{
|
||||
UserProperty.Changed.AddClassHandler<Avatar>(OnUserPropertyChanged);
|
||||
}
|
||||
|
||||
public Avatar() {
|
||||
public Avatar()
|
||||
{
|
||||
var refetch = new MenuItem() { Header = App.Text("RefetchAvatar") };
|
||||
refetch.Click += (o, e) => {
|
||||
if (User != null) {
|
||||
refetch.Click += (o, e) =>
|
||||
{
|
||||
if (User != null)
|
||||
{
|
||||
Models.AvatarManager.Request(_emailMD5, true);
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
@ -42,40 +50,50 @@ namespace SourceGit.Views {
|
|||
ContextMenu.Items.Add(refetch);
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context) {
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
if (User == null) return;
|
||||
|
||||
var corner = (float)Math.Max(2, Bounds.Width / 16);
|
||||
var img = Models.AvatarManager.Request(_emailMD5, false);
|
||||
if (img != null) {
|
||||
if (img != null)
|
||||
{
|
||||
var rect = new Rect(0, 0, Bounds.Width, Bounds.Height);
|
||||
context.PushClip(new RoundedRect(rect, corner));
|
||||
context.DrawImage(img, rect);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Point textOrigin = new Point((Bounds.Width - _fallbackLabel.Width) * 0.5, (Bounds.Height - _fallbackLabel.Height) * 0.5);
|
||||
context.DrawRectangle(_fallbackBrush, null, new Rect(0, 0, Bounds.Width, Bounds.Height), corner, corner);
|
||||
context.DrawText(_fallbackLabel, textOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAvatarResourceChanged(string md5) {
|
||||
if (_emailMD5 == md5) {
|
||||
public void OnAvatarResourceChanged(string md5)
|
||||
{
|
||||
if (_emailMD5 == md5)
|
||||
{
|
||||
InvalidateVisual();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e) {
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
Models.AvatarManager.Subscribe(this);
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e) {
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnUnloaded(e);
|
||||
Models.AvatarManager.Unsubscribe(this);
|
||||
}
|
||||
|
||||
private static void OnUserPropertyChanged(Avatar avatar, AvaloniaPropertyChangedEventArgs e) {
|
||||
if (avatar.User == null) {
|
||||
private static void OnUserPropertyChanged(Avatar avatar, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (avatar.User == null)
|
||||
{
|
||||
avatar._emailMD5 = null;
|
||||
return;
|
||||
}
|
||||
|
@ -91,7 +109,8 @@ namespace SourceGit.Views {
|
|||
var md5 = builder.ToString();
|
||||
if (avatar._emailMD5 != md5) avatar._emailMD5 = md5;
|
||||
|
||||
avatar._fallbackBrush = new LinearGradientBrush {
|
||||
avatar._fallbackBrush = new LinearGradientBrush
|
||||
{
|
||||
GradientStops = FALLBACK_GRADIENTS[sum % FALLBACK_GRADIENTS.Length],
|
||||
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
|
||||
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
|
||||
|
@ -100,8 +119,8 @@ namespace SourceGit.Views {
|
|||
var typeface = new Typeface("fonts:SourceGit#JetBrains Mono");
|
||||
|
||||
avatar._fallbackLabel = new FormattedText(
|
||||
placeholder,
|
||||
CultureInfo.CurrentCulture,
|
||||
placeholder,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
typeface,
|
||||
avatar.Width * 0.65,
|
||||
|
@ -114,4 +133,4 @@ namespace SourceGit.Views {
|
|||
private LinearGradientBrush _fallbackBrush = null;
|
||||
private string _emailMD5 = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue