mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
0.1.8
This commit is contained in:
28
LanMontainDesktop/ComponentSystem/ComponentPlacementRules.cs
Normal file
28
LanMontainDesktop/ComponentSystem/ComponentPlacementRules.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace LanMontainDesktop.ComponentSystem;
|
||||
|
||||
public static class ComponentPlacementRules
|
||||
{
|
||||
public static (int WidthCells, int HeightCells) EnsureMinimumSize(
|
||||
DesktopComponentDefinition definition,
|
||||
int requestedWidthCells,
|
||||
int requestedHeightCells)
|
||||
{
|
||||
var width = Math.Max(definition.MinWidthCells, requestedWidthCells);
|
||||
var height = Math.Max(definition.MinHeightCells, requestedHeightCells);
|
||||
return (Math.Max(1, width), Math.Max(1, height));
|
||||
}
|
||||
|
||||
public static bool CanPlaceInStatusBar(DesktopComponentDefinition definition, int requestedHeightCells)
|
||||
{
|
||||
return definition.AllowStatusBarPlacement && requestedHeightCells == 1;
|
||||
}
|
||||
|
||||
public static (int Column, int Row) ClampToGrid(int requestedColumn, int requestedRow, int maxColumns, int maxRows)
|
||||
{
|
||||
var clampedColumn = Math.Clamp(requestedColumn, 0, Math.Max(0, maxColumns - 1));
|
||||
var clampedRow = Math.Clamp(requestedRow, 0, Math.Max(0, maxRows - 1));
|
||||
return (clampedColumn, clampedRow);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user