mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
refactor: replace all window with custom ChromelessWindow
This commit is contained in:
parent
68061f82b1
commit
f5b35d3db2
23 changed files with 414 additions and 649 deletions
54
src/Views/ChromelessWindow.cs
Normal file
54
src/Views/ChromelessWindow.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class ChromelessWindow : Window
|
||||
{
|
||||
protected override Type StyleKeyOverride => typeof(Window);
|
||||
|
||||
public ChromelessWindow()
|
||||
{
|
||||
if (OperatingSystem.IsLinux())
|
||||
Classes.Add("custom_window_frame");
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
|
||||
if (Classes.Contains("custom_window_frame") && CanResize)
|
||||
{
|
||||
string[] borderNames = [
|
||||
"PART_BorderTopLeft",
|
||||
"PART_BorderTop",
|
||||
"PART_BorderTopRight",
|
||||
"PART_BorderLeft",
|
||||
"PART_BorderRight",
|
||||
"PART_BorderBottomLeft",
|
||||
"PART_BorderBottom",
|
||||
"PART_BorderBottomRight",
|
||||
];
|
||||
|
||||
foreach (var name in borderNames)
|
||||
{
|
||||
var border = e.NameScope.Find<Border>(name);
|
||||
if (border != null)
|
||||
{
|
||||
border.PointerPressed -= OnWindowBorderPointerPressed;
|
||||
border.PointerPressed += OnWindowBorderPointerPressed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnWindowBorderPointerPressed(object sender, PointerPressedEventArgs e)
|
||||
{
|
||||
if (sender is Border border && border.Tag is WindowEdge edge)
|
||||
BeginResizeDrag(edge, e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue