-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from XanatosX/feature/104_add-posibility-to-p…
…osition-app-in-different-screen-corner [Feature] Implement possiblity to position tool window on different screen corners
- Loading branch information
Showing
15 changed files
with
234 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/ModularToolManager/Strategies/WindowPosition/BottomLeftStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Platform; | ||
|
||
namespace ModularToolManager.Strategies.WindowPosition; | ||
|
||
|
||
/// </summary> | ||
/// Strategy to position the given window in the bottom left corner of the screen. | ||
/// </summary> | ||
public class BottomLeftStrategy : IWindowPositionStrategy | ||
{ | ||
//<inheritdoc/> | ||
public void PositionWindow(Window window, Screen? screen) | ||
{ | ||
if (screen is null) | ||
{ | ||
return; | ||
} | ||
PixelRect workingArea = screen.WorkingArea; | ||
double newXPos = workingArea.X; | ||
double newYPos = workingArea.Bottom - window.Height; | ||
window.Position = new PixelPoint((int)newXPos, (int)newYPos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/ModularToolManager/Strategies/WindowPosition/TopLeftStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Platform; | ||
|
||
namespace ModularToolManager.Strategies.WindowPosition; | ||
|
||
/// <summary> | ||
/// Position a Window in the bottom left of a given screen | ||
/// </summary> | ||
public class TopLeftStrategy : IWindowPositionStrategy | ||
{ | ||
/// <inheritdoc/> | ||
public void PositionWindow(Window window, Screen? screen) | ||
{ | ||
if (screen is null ) | ||
{ | ||
return; | ||
} | ||
|
||
PixelRect workingArea = screen.WorkingArea; | ||
double newXPos = workingArea.X; | ||
double newYPos = workingArea.Y; | ||
window.Position = new PixelPoint((int)newXPos, (int)newYPos); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/ModularToolManager/Strategies/WindowPosition/TopRightStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Platform; | ||
|
||
namespace ModularToolManager.Strategies.WindowPosition; | ||
|
||
/// <summary> | ||
/// Position a Window in the top left of a given screen | ||
/// </summary> | ||
public class TopRightStrategy : IWindowPositionStrategy | ||
{ | ||
/// <inheritdoc/> | ||
public void PositionWindow(Window window, Screen? screen) | ||
{ | ||
if (screen is null) | ||
{ | ||
return; | ||
} | ||
|
||
PixelRect workingArea = screen.WorkingArea; | ||
double newXPos = workingArea.Right - window.Width; | ||
double newYPos = workingArea.Y; | ||
window.Position = new PixelPoint((int)newXPos, (int)newYPos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/ModularToolManager/ViewModels/WindowPositionStrategyViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using ModularToolManager.Enums; | ||
|
||
namespace ModularToolManager.ViewModels; | ||
|
||
/// <summary> | ||
/// View model for the window position strategy | ||
/// </summary> | ||
public partial class WindowPositionStrategyViewModel : ObservableObject | ||
{ | ||
/// <summary> | ||
/// The display name of the window position strategy | ||
/// </summary> | ||
[ObservableProperty] | ||
private string displayName; | ||
|
||
/// <summary> | ||
/// The stored window position enum | ||
/// </summary> | ||
public WindowPositionEnum WindowPosition {get; init;} | ||
|
||
/// <summary> | ||
/// Create a new instance of this class | ||
/// </summary> | ||
/// <param name="windowPositionEnum">The window position enum to create a view model for</param> | ||
public WindowPositionStrategyViewModel(WindowPositionEnum windowPositionEnum) | ||
{ | ||
WindowPosition = windowPositionEnum; | ||
DisplayName = windowPositionEnum switch | ||
{ | ||
WindowPositionEnum.TopLeft => Properties.Resources.Settings_WindowPosition_Top_Left, | ||
WindowPositionEnum.TopRight => Properties.Resources.Settings_WindowPosition_Top_Right, | ||
WindowPositionEnum.BottomLeft => Properties.Resources.Settings_WindowPosition_Bottom_Left, | ||
WindowPositionEnum.BottomRight => Properties.Resources.Settings_WindowPosition_Bottom_Right, | ||
_ => "" | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/ModularToolManager/Views/WindowPositionStrategyView.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="ModularToolManager.Views.WindowPositionStrategyView"> | ||
<TextBlock Text="{Binding DisplayName}" /> | ||
</UserControl> |
10 changes: 10 additions & 0 deletions
10
src/ModularToolManager/Views/WindowPositionStrategyView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Avalonia.Controls; | ||
|
||
namespace ModularToolManager.Views; | ||
public partial class WindowPositionStrategyView : UserControl | ||
{ | ||
public WindowPositionStrategyView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} |