Skip to content

Commit

Permalink
Merge pull request #262 from AuroraZiling/main
Browse files Browse the repository at this point in the history
[Fix] `WaveProgress` & `SukiWindow` critical issues
  • Loading branch information
kikipoulet authored Aug 7, 2024
2 parents 16c717d + b2ac08a commit ddec032
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 64 deletions.
10 changes: 6 additions & 4 deletions SukiUI/Controls/SukiWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
Style="{TemplateBinding BackgroundStyle}"
TransitionTime="{TemplateBinding BackgroundTransitionTime}"
TransitionsEnabled="{TemplateBinding BackgroundTransitionsEnabled}" />
<Panel Background="White" Opacity="0.1" IsVisible="{DynamicResource IsLight}" />

<Panel Background="White"
IsVisible="{DynamicResource IsLight}"
Opacity="0.1" />

<DockPanel LastChildFill="True">
<Panel DockPanel.Dock="Top">
<Panel.Styles>
Expand Down Expand Up @@ -78,7 +80,7 @@
<ItemsControl ItemsSource="{TemplateBinding RightWindowTitleBarControls}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft"/>
<StackPanel FlowDirection="RightToLeft" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Expand Down Expand Up @@ -116,7 +118,7 @@
</Border>
</ControlTemplate>
</Setter>

<Style Selector="^[WindowState=Maximized] /template/ PathIcon#MaximizeIcon">
<Setter Property="Data" Value="{x:Static icons:Icons.WindowRestore}" />
</Style>
Expand Down
63 changes: 29 additions & 34 deletions SukiUI/Controls/SukiWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public double TitleFontSize
}

public static readonly StyledProperty<FontWeight> TitleFontWeightProperty =
AvaloniaProperty.Register<SukiWindow, FontWeight>(nameof(TitleFontWeight),
defaultValue: FontWeight.Bold);
AvaloniaProperty.Register<SukiWindow, FontWeight>(nameof(TitleFontWeight), defaultValue: FontWeight.Bold);

public FontWeight TitleFontWeight
{
Expand Down Expand Up @@ -83,8 +82,7 @@ public AvaloniaList<MenuItem>? MenuItems
get => GetValue(MenuItemsProperty);
set => SetValue(MenuItemsProperty, value);
}



public static readonly StyledProperty<bool> CanMinimizeProperty =
AvaloniaProperty.Register<SukiWindow, bool>(nameof(CanMinimize), defaultValue: true);

Expand All @@ -103,7 +101,7 @@ public bool CanMove
set => SetValue(CanMoveProperty, value);
}

// BACKGROUND PROPERTIES
// Background properties
public static readonly StyledProperty<bool> BackgroundAnimationEnabledProperty =
AvaloniaProperty.Register<SukiWindow, bool>(nameof(BackgroundAnimationEnabled), defaultValue: false);

Expand All @@ -116,7 +114,6 @@ public bool BackgroundAnimationEnabled
public static readonly StyledProperty<SukiBackgroundStyle> BackgroundStyleProperty =
AvaloniaProperty.Register<SukiWindow, SukiBackgroundStyle>(nameof(BackgroundStyle),
defaultValue: SukiBackgroundStyle.Bubble);


/// <inheritdoc cref="SukiBackground.Style"/>
public SukiBackgroundStyle BackgroundStyle
Expand All @@ -137,7 +134,6 @@ public string? BackgroundShaderFile

public static readonly StyledProperty<string?> BackgroundShaderCodeProperty =
AvaloniaProperty.Register<SukiWindow, string?>(nameof(BackgroundShaderCode));


/// <inheritdoc cref="SukiBackground.ShaderCode"/>
public string? BackgroundShaderCode
Expand Down Expand Up @@ -166,10 +162,13 @@ public double BackgroundTransitionTime
set => SetValue(BackgroundTransitionTimeProperty, value);
}

public static readonly StyledProperty<Avalonia.Controls.Controls> RightWindowTitleBarControlsProperty = AvaloniaProperty.Register<SukiWindow, Avalonia.Controls.Controls>(nameof(RightWindowTitleBarControls), defaultValue: new Avalonia.Controls.Controls());
public static readonly StyledProperty<Avalonia.Controls.Controls> RightWindowTitleBarControlsProperty =
AvaloniaProperty.Register<SukiWindow, Avalonia.Controls.Controls>(nameof(RightWindowTitleBarControls),
defaultValue: new Avalonia.Controls.Controls());

/// <summary>
/// Controls that are displayed on the right side of the title bar, to the left of the normal window control buttons. (Displays provided controls right-to-left)
/// Controls that are displayed on the right side of the title bar,
/// to the left of the normal window control buttons. (Displays provided controls right-to-left)
/// </summary>
public Avalonia.Controls.Controls RightWindowTitleBarControls
{
Expand All @@ -180,25 +179,25 @@ public Avalonia.Controls.Controls RightWindowTitleBarControls
public SukiWindow()
{
MenuItems = new AvaloniaList<MenuItem>();
RightWindowTitleBarControls = new Avalonia.Controls.Controls();
}

private IDisposable? _subscriptionDisposables;
private SukiBackground? _background;

protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);

if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
return;
if (desktop.MainWindow is SukiWindow s && s != this)
if (desktop.MainWindow is SukiWindow window && window != this)
{
if (Icon == null) Icon = s.Icon;
Icon ??= window.Icon;
// This would be nice to do, but obviously LogoContent is a control and you can't attach it twice.
// if (LogoContent is null) LogoContent = s.LogoContent;
}
}



protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
Expand All @@ -213,10 +212,12 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
if (e.NameScope.Get<Button>("PART_MaximizeButton") is { } maximize)
{
maximize.Click += OnMaximizeButtonClicked;
bool pointerOnMaxButton = false;
var setter = typeof(Button).GetProperty("IsPointerOver");
var pointerOnMaxButton = false;
var setter = typeof(Button).GetProperty("IsPointerOver");

var proc = (IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
// Windows Snap Layout
var proc =
(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
{
switch (msg)
{
Expand All @@ -231,17 +232,17 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
var point = new PixelPoint(
(short)(ToInt32(lParam) & 0xffff),
(short)(ToInt32(lParam) >> 16));
var buttonLeftTop = maximize.PointToScreen(new(0, 0));
var x = (buttonLeftTop.X - point.X) / RenderScaling;
var y = (point.Y - buttonLeftTop.Y) / RenderScaling;
var buttonLeftTop = maximize.PointToScreen(new Point(0, 0));
var x = (buttonLeftTop.X - point.X) / RenderScaling;
var y = (point.Y - buttonLeftTop.Y) / RenderScaling;
if (new Rect(0, 0,
maximize.DesiredSize.Width,
maximize.DesiredSize.Height)
.Contains(new Point(x, y)))
{
setter?.SetValue(maximize, true);
pointerOnMaxButton = true;
handled = true;
pointerOnMaxButton = true;
handled = true;
return (IntPtr)9;
}

Expand All @@ -252,21 +253,15 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

return IntPtr.Zero;

static int ToInt32(IntPtr ptr) => IntPtr.Size == 4 ? ptr.ToInt32() : (int)(ptr.ToInt64() & 0xffffffff);
static int ToInt32(IntPtr ptr) => IntPtr.Size == 4
? ptr.ToInt32() : (int)(ptr.ToInt64() & 0xffffffff);
};



Win32Properties.AddWndProcHookCallback(this, new Win32Properties.CustomWndProcHookCallback(proc));
}

if (e.NameScope.Get<Button>("PART_MinimizeButton") is { } minimize)
minimize.Click += (_, _) =>
{

WindowState = WindowState.Minimized;

};
minimize.Click += (_, _) => WindowState = WindowState.Minimized;

if (e.NameScope.Get<Button>("PART_CloseButton") is { } close)
close.Click += (_, _) => Close();
Expand All @@ -279,15 +274,16 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
}
catch
{
// ignored
}
}

private void OnMaximizeButtonClicked(object? sender, RoutedEventArgs args)
{
if (!CanResize) return;
WindowState = WindowState == WindowState.Maximized
? WindowState.Normal
: WindowState.Maximized;
? WindowState.Normal
: WindowState.Maximized;
}

private void OnWindowStateChanged(WindowState state)
Expand All @@ -307,5 +303,4 @@ protected override void OnUnloaded(RoutedEventArgs e)
base.OnUnloaded(e);
_subscriptionDisposables?.Dispose();
}

}
18 changes: 8 additions & 10 deletions SukiUI/Controls/WaveProgress.axaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

<UserControl x:Class="SukiUI.Controls.WaveProgress"
<UserControl x:Class="SukiUI.Controls.WaveProgress"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -24,9 +23,9 @@
ClipToBounds="False"
CornerRadius="100">
<Border.Resources>
<waveProgress:WaveProgressValueConverter x:Key="WValueConvert" />
<waveProgress:WaveProgressValueTextConverter x:Key="WValueTextConvert" />
<waveProgress:WaveProgressValueColorConverter x:Key="WValueColorConvert" />
<waveProgress:WaveProgressValueConverter x:Key="WValueConverter" />
<waveProgress:WaveProgressValueTextConverter x:Key="WValueTextConverter" />
<waveProgress:WaveProgressValueColorConverter x:Key="WValueColorConverter" />
<waveProgress:WaveProgressGradientOffsetConverter x:Key="WGradientConverter" />
</Border.Resources>

Expand All @@ -39,7 +38,7 @@
<Panel>
<Canvas Width="200" Height="200">
<Path Canvas.Top="{TemplateBinding Value,
Converter={StaticResource WValueConvert}}"
Converter={StaticResource WValueConverter}}"
Classes="WaveAnimatedFast"
Data="M 0,50 H 700 V 350 H 0 M 0,50 C 25,55 75,45 100,50 S 175,55 200,50 S 275,45 300,50 S 375,55 400,50 S 475,45 500,50 S 575,55 600,50 S 675,45 700,50"
Fill="{TemplateBinding Value,
Expand All @@ -57,7 +56,7 @@
</Path.Transitions>
</Path>
<Path Canvas.Top="{TemplateBinding Value,
Converter={StaticResource WValueConvert}}"
Converter={StaticResource WValueConverter}}"
Classes="WaveAnimated"
Data="M 0,50 H 700 V 350 H 0 M 0,50 C 25,55 75,45 100,50 S 175,55 200,50 S 275,45 300,50 S 375,55 400,50 S 475,45 500,50 S 575,55 600,50 S 675,45 700,50"
Fill="{TemplateBinding Value,
Expand All @@ -68,7 +67,6 @@
<Transitions>
<DoubleTransition Property="Canvas.Top" Duration="0:0:2.5">
<DoubleTransition.Easing>

<CircularEaseOut />
</DoubleTransition.Easing>
</DoubleTransition>
Expand All @@ -82,9 +80,9 @@
VerticalAlignment="Center"
Classes="h2"
Foreground="{TemplateBinding Value,
Converter={StaticResource WValueColorConvert}}"
Converter={StaticResource WValueColorConverter}}"
Text="{TemplateBinding Value,
Converter={StaticResource WValueTextConvert}}">
Converter={StaticResource WValueTextConverter}}">
<TextBlock.Transitions>
<Transitions>
<DoubleTransition Property="Opacity" Duration="0:0:0.3" />
Expand Down
24 changes: 8 additions & 16 deletions SukiUI/Controls/WaveProgress.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public partial class WaveProgress : UserControl
public WaveProgress()
{
InitializeComponent();

var theme = SukiTheme.GetInstance();
theme.OnBaseThemeChanged += _ =>
{
Expand All @@ -27,33 +28,24 @@ private void InitializeComponent()
AvaloniaXamlLoader.Load(this);
}

private double _value = 50;
public static readonly StyledProperty<double> ValueProperty =
AvaloniaProperty.Register<WaveProgress, double>(nameof(Value), defaultValue: 50);

public double Value
{
get => _value;
get => GetValue(ValueProperty);
set
{
if (value is < 0 or > 100)
return;

SetValue(ValueProperty,value);
if (value is >= 0 and <= 100)
SetValue(ValueProperty, value);
}
}

public static readonly StyledProperty<double> ValueProperty =
AvaloniaProperty.Register<CircleProgressBar, double>(nameof(Value), defaultValue: 50);



public static readonly StyledProperty<bool> IsTextVisibleProperty = AvaloniaProperty.Register<WaveProgress, bool>(nameof(IsTextVisible), defaultValue: true);

public bool IsTextVisible
{
get { return GetValue(IsTextVisibleProperty); }
set
{
SetValue(IsTextVisibleProperty, value);
}
get => GetValue(IsTextVisibleProperty);
set => SetValue(IsTextVisibleProperty, value);
}
}

0 comments on commit ddec032

Please sign in to comment.