-
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.
Fix issue with application not starting minimized
Rework window position on screen Add strategy to show window in bottom right corner Add structure to position the window baesed on a strategy
- Loading branch information
Showing
8 changed files
with
120 additions
and
16 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
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,12 @@ | ||
namespace ModularToolManager.Enums; | ||
|
||
/// <summary> | ||
/// Enum for the correct position of the window | ||
/// </summary> | ||
public enum WindowPositionEnum | ||
{ | ||
TopLeft, | ||
TopRight, | ||
BottomLeft, | ||
BottomRight, | ||
} |
20 changes: 20 additions & 0 deletions
20
src/ModularToolManager/Services/Ui/DefaultWindowPositionStrategyFactory.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,20 @@ | ||
using ModularToolManager.Enums; | ||
using ModularToolManager.Strategies.WindowPosition; | ||
|
||
namespace ModularToolManager.Services.Ui; | ||
|
||
/// <summary> | ||
/// Default factory for getting the window position strategy | ||
/// </summary> | ||
public class DefaultWindowPositionStrategyFactory : IWindowPositionFactory | ||
{ | ||
/// <inheritdoc/> | ||
public IWindowPositionStrategy? GetWindowPositionStrategy(WindowPositionEnum positionEnum) | ||
{ | ||
return positionEnum switch | ||
{ | ||
WindowPositionEnum.BottomRight => new BottomRightStrategy(), | ||
_ => new BottomRightStrategy() | ||
}; | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/ModularToolManager/Services/Ui/IWindowPositionFactory.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,17 @@ | ||
using ModularToolManager.Enums; | ||
using ModularToolManager.Strategies.WindowPosition; | ||
|
||
namespace ModularToolManager.Services.Ui; | ||
|
||
/// <summary> | ||
/// Factory to get a matching strategy for a requested window position | ||
/// </summary> | ||
public interface IWindowPositionFactory | ||
{ | ||
/// <summary> | ||
/// Get the strategy for the given window | ||
/// </summary> | ||
/// <param name="positionEnum">The position enum to use</param> | ||
/// <returns>The strategy to position the window on the given position</returns> | ||
IWindowPositionStrategy? GetWindowPositionStrategy(WindowPositionEnum positionEnum); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/ModularToolManager/Strategies/WindowPosition/BottomRightStrategy.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,24 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Platform; | ||
|
||
namespace ModularToolManager.Strategies.WindowPosition; | ||
|
||
/// <summary> | ||
/// Position a Window in the bottom right of a given screen | ||
/// </summary> | ||
public class BottomRightStrategy : IWindowPositionStrategy | ||
{ | ||
/// <inheritdoc/> | ||
public void PositionWindow(Window window, Screen? screen) | ||
{ | ||
if (screen is null) | ||
{ | ||
return; | ||
} | ||
PixelRect workingArea = screen.WorkingArea; | ||
double newXPos = workingArea.X + workingArea.Width - window.Width; | ||
double newYPos = workingArea.Y + workingArea.Height - window.Height; | ||
window.Position = new PixelPoint((int)newXPos, (int)newYPos); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/ModularToolManager/Strategies/WindowPosition/IWindowPositionStrategy.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,17 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Platform; | ||
|
||
namespace ModularToolManager.Strategies.WindowPosition; | ||
|
||
/// <summary> | ||
/// Strategy to position a window on the screen | ||
/// </summary> | ||
public interface IWindowPositionStrategy | ||
{ | ||
/// <summary> | ||
/// Position the given window on the screen | ||
/// </summary> | ||
/// <param name="window">The window which should be moved</param> | ||
/// <param name="screen">The screen to position the window on</param> | ||
void PositionWindow(Window window, Screen? screen); | ||
} |
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