Skip to content

Commit

Permalink
Fix moving window on windows
Browse files Browse the repository at this point in the history
Use WindowDecorationMargin to not cover window decorations
  • Loading branch information
affederaffe committed Nov 16, 2023
1 parent dd169e3 commit bc327fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion BeatSaberModManager/Resources/Styles/HamburgerMenu.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@
<Setter Property="TabStripPlacement" Value="Left" />
<Setter Property="Template">
<ControlTemplate>
<Panel Background="{TemplateBinding PaneBackground}">
<Panel Background="{x:Null}">
<Rectangle Fill="{TemplateBinding PaneBackground}" IsHitTestVisible="False" />
<SplitView x:Name="PART_NavigationPane"
CompactPaneLength="{StaticResource PaneCompactWidth}"
DisplayMode="Inline"
IsPaneOpen="True"
Margin="{TemplateBinding ContentMargin}"
OpenPaneLength="{StaticResource PaneExpandWidth}"
PaneBackground="Transparent">
<SplitView.Pane>
Expand Down
14 changes: 14 additions & 0 deletions BeatSaberModManager/Views/Controls/HamburgerMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class HamburgerMenu : TabControl
/// </summary>
public static readonly StyledProperty<int> ExpandedModeThresholdWidthProperty = AvaloniaProperty.Register<HamburgerMenu, int>(nameof(ExpandedModeThresholdWidth), 1008);

/// <summary>
/// Defines the <see cref="ContentMarginProperty "/> property.
/// </summary>
public static readonly StyledProperty<Thickness> ContentMarginProperty = AvaloniaProperty.Register<HamburgerMenu, Thickness>(nameof(ContentMargin));

/// <summary>
/// Gets or sets the brush used to draw the pane's background.
/// </summary>
Expand Down Expand Up @@ -57,6 +62,15 @@ public int ExpandedModeThresholdWidth
set => SetValue(ExpandedModeThresholdWidthProperty, value);
}

/// <summary>
/// Gets or sets margin of the content.
/// </summary>
public Thickness ContentMargin
{
get => GetValue(ContentMarginProperty);
set => SetValue(ContentMarginProperty, value);
}

/// <inheritdoc />
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
Expand Down
3 changes: 2 additions & 1 deletion BeatSaberModManager/Views/Windows/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
x:Class="BeatSaberModManager.Views.Windows.MainWindow"
x:DataType="vm:MainWindowViewModel"
Name="Window"
Margin="{Binding #Window.OffScreenMargin}"
TransparencyLevelHint="Mica, Blur, None"
Title="{StaticResource MainWindow:Title}"
Icon="/Resources/Icons/Icon.ico"
Expand All @@ -22,7 +23,7 @@
<cv:StatusTypeEnumConverter x:Key="StatusTypeEnumConverter" />
</Window.Resources>

<c:HamburgerMenu x:Name="HamburgerMenu" Margin="{Binding #Window.OffScreenMargin}" SelectedIndex="{Binding SettingsViewModel.TabIndex, Mode=TwoWay}">
<c:HamburgerMenu x:Name="HamburgerMenu" Margin="{Binding #Window.OffScreenMargin}" ContentMargin="{Binding #Window.WindowDecorationMargin}" SelectedIndex="{Binding SettingsViewModel.TabIndex, Mode=TwoWay}">
<TabItem>
<p:IntroPage />
<TabItem.Header>
Expand Down
9 changes: 8 additions & 1 deletion BeatSaberModManager/Views/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using System;
using System.Linq;
using System.Reactive.Linq;

using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Chrome;
using Avalonia.Controls.Primitives;
using Avalonia.ReactiveUI;
using Avalonia.VisualTree;

using BeatSaberModManager.ViewModels;

using ReactiveUI;


namespace BeatSaberModManager.Views.Windows
{
Expand All @@ -27,7 +35,6 @@ public MainWindow(MainWindowViewModel viewModel)
InitializeComponent();
ViewModel = viewModel;
ExtendClientAreaToDecorationsHint = !OperatingSystem.IsLinux();
Margin = ExtendClientAreaToDecorationsHint ? WindowDecorationMargin : new Thickness();
viewModel.PickInstallDirInteraction.RegisterHandler(async context => context.SetOutput(await new InstallFolderDialogWindow().ShowDialog<string?>(this).ConfigureAwait(false)));
}
}
Expand Down

0 comments on commit bc327fc

Please sign in to comment.