mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
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);
|
|
}
|
|
}
|