Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Foreman/Controls/ChooserIconGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,24 @@ public void ApplyDesignLayout() {
public void WireMouseWheel(MouseEventHandler handler) => gridSurface.MouseWheel += handler;

/// <summary>Size the grid to fit the allotted area; returns the outer width (cells + scrollbar).</summary>
public int ApplyLayout(int availableGridHeight, int maxLayoutWidth, int designCellSize, int minCellSize, int scrollbarWidth) {
int cellByHeight = availableGridHeight / VisibleRowCount;
public int ApplyLayout(int availableGridHeight, int maxLayoutWidth, int designCellSize, int minCellSize, int scrollbarWidth, int minOuterWidth = 0) {
int minGridHeight = minCellSize * VisibleRowCount;
int cellByHeight = Math.Max(1, availableGridHeight / VisibleRowCount);
int cellByWidth = Math.Max(1, (maxLayoutWidth - scrollbarWidth) / ColumnCount);
int cell = Math.Max(minCellSize, Math.Min(designCellSize, Math.Min(cellByHeight, cellByWidth)));
int cell = Math.Min(designCellSize, Math.Min(cellByHeight, cellByWidth));
if (availableGridHeight >= minGridHeight)
cell = Math.Max(minCellSize, cell);
else
cell = Math.Max(1, cell);

if (minOuterWidth > 0) {
int cellForMinOuter = (int)Math.Ceiling((minOuterWidth - scrollbarWidth) / (double)ColumnCount);
cellForMinOuter = Math.Max(minCellSize, Math.Min(designCellSize, cellForMinOuter));
if (cellForMinOuter * ColumnCount + scrollbarWidth <= maxLayoutWidth) {
int cellByHeightCap = Math.Max(1, availableGridHeight / VisibleRowCount);
cell = Math.Max(cell, Math.Min(cellForMinOuter, cellByHeightCap));
}
}

TargetCellSize = cell;
int gridHeight = cell * VisibleRowCount;
Expand All @@ -97,7 +111,7 @@ public int ApplyLayout(int availableGridHeight, int maxLayoutWidth, int designCe
MaximumSize = new Size(outerWidth, gridHeight);

ApplyCellGridBounds(gridWidth, gridHeight, scrollbarWidth);
ResumeLayout(true);
ResumeLayout(performLayout: false);
return outerWidth;
}

Expand Down
14 changes: 14 additions & 0 deletions Foreman/Controls/ChooserLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ internal static class ChooserLayout {
public const int DesignItemIconPixels = 40;
public const int DesignMinCellPixels = 18;
public const int DesignMinGroupIconPixels = 24;
public const int DesignFooterButtonHeightPixels = 38;
public const int DesignMinFooterButtonHeightPixels = 22;
public const float DesignFooterButtonFontSizePoints = 8.25f;
public const float DesignMinFooterButtonFontSizePoints = 6f;
public const int DesignMinVisibleRows = 4;

public static int DesignGridOuterWidth =>
Expand All @@ -43,5 +47,15 @@ public static int GroupIconSizeForCell(int cellSize, int designGroupSize, int mi
int fromCell = (int)Math.Round(cellSize * (DesignGroupIconPixels / (float)DesignCellPixels));
return Math.Min(designGroupSize, Math.Max(minGroupSize, fromCell));
}

public static int FooterButtonHeightForCell(int cellSize, int designFooterHeight, int minFooterHeight) {
int fromCell = (int)Math.Round(cellSize * (DesignFooterButtonHeightPixels / (float)DesignCellPixels));
return Math.Max(minFooterHeight, Math.Min(designFooterHeight, fromCell));
}

public static float FooterButtonFontSizeForCell(int cellSize, int designCellPixels, float designFontSize, float minFontSize) {
float fromCell = cellSize * (designFontSize / designCellPixels);
return Math.Max(minFontSize, Math.Min(designFontSize, fromCell));
}
}
}
26 changes: 21 additions & 5 deletions Foreman/Controls/IRChooserPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading