This commit is contained in:
lincube
2026-02-28 12:30:16 +08:00
parent 310c0f224f
commit 473a84e47b
13 changed files with 750 additions and 327 deletions

View 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);
}
}