Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically change mini-window window controls alignment based on window position #125

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vATIS.Desktop/Ui/Windows/CompactWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
PointerExited="OnPointerExited"
PointerPressed="OnPointerPressed">
<Panel ClipToBounds="True">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Spacing="3" ZIndex="1" Margin="3" IsVisible="{Binding IsControlsVisible, DataType=vm:CompactWindowViewModel}">
<StackPanel Name="WindowControls" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Spacing="3" ZIndex="1" Margin="3" IsVisible="{Binding IsControlsVisible, DataType=vm:CompactWindowViewModel}">
<ToggleButton Theme="{StaticResource PinButtonSmall}" Command="{Binding ToggleIsTopMost, DataType=vm:CompactWindowTopMostViewModel, Source={x:Static vm:CompactWindowTopMostViewModel.Instance}}" IsChecked="{Binding IsTopMost, DataType=vm:CompactWindowTopMostViewModel, Mode=OneWay, Source={x:Static vm:CompactWindowTopMostViewModel.Instance}}" />
<Button Theme="{StaticResource CompactViewButtonSmall}" Command="{Binding InvokeMainWindowCommand, DataType=vm:CompactWindowViewModel}" CommandParameter="{Binding ElementName=Window}" />
</StackPanel>
Expand Down
27 changes: 27 additions & 0 deletions vATIS.Desktop/Ui/Windows/CompactWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
// </copyright>

using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.ReactiveUI;
using Vatsim.Vatis.Ui.ViewModels;

Expand Down Expand Up @@ -67,6 +70,30 @@ private void OnPositionChanged(object? sender, PixelPointEventArgs e)
{
model.UpdatePosition(this);
}

// Get the bounding rectangle of all screens combined
var totalScreenBounds = Screens.All
.Select(s => s.WorkingArea)
.Aggregate((acc, next) => acc.Union(next));

var totalLeft = totalScreenBounds.X;
var totalRight = totalScreenBounds.X + totalScreenBounds.Width;

var windowLeft = Position.X;
var windowRight = windowLeft + (int)Width;

var isRightOffScreen = windowRight > totalRight;
var isRightFullyVisible = windowRight <= totalRight && windowLeft >= totalLeft;

// Update alignment only if the window is partially off-screen
if (isRightOffScreen)
{
WindowControls.HorizontalAlignment = HorizontalAlignment.Left;
}
else if (isRightFullyVisible)
{
WindowControls.HorizontalAlignment = HorizontalAlignment.Right;
}
}

private void OnPointerEntered(object? sender, PointerEventArgs e)
Expand Down