Skip to content

Commit

Permalink
Dynamically change mini-window window controls based on window positi…
Browse files Browse the repository at this point in the history
…on (#125)
  • Loading branch information
justinshannon authored Feb 7, 2025
1 parent 0527dae commit 4fb353e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vATIS.Desktop/Ui/Windows/CompactWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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

0 comments on commit 4fb353e

Please sign in to comment.