/
puma
/
ppa
Обзор
Документация
Войти
/
puma
/
ppa
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
EtoUI/ArmyCardsLayoutFactory.cs
66 строк
2 KB
Margarita
new
20 май 2026, 12:29
20 май 2026, 12:29
d0634a2
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using Eto.Forms; using Eto.Drawing; public static class ArmyCardsLayoutFactory { public const int DefaultCardsPerRow = 9; public static Eto.Forms.Control CreateCardsGrid( IList<IUnit> units, Func<IUnit, int, Eto.Forms.Control> createCard, int cardsPerRow = DefaultCardsPerRow) { if (units == null) throw new ArgumentNullException(nameof(units)); if (createCard == null) throw new ArgumentNullException(nameof(createCard)); if (cardsPerRow <= 0) { cardsPerRow = DefaultCardsPerRow; } // ВАЖНО: // Никогда не возвращаем пустую таблицу для Eto.WinForms, // иначе TableLayout может падать в FillEmptyCells(). if (units.Count == 0) { return new Eto.Forms.Panel { Content = new Eto.Forms.Label { Text = "Армия пока пуста", TextAlignment = Eto.Forms.TextAlignment.Center } }; } var table = new Eto.Forms.TableLayout { Spacing = new Eto.Drawing.Size(10, 10) }; for (int i = 0; i < units.Count; i += cardsPerRow) { var row = new Eto.Forms.StackLayout { Orientation = Eto.Forms.Orientation.Horizontal, Spacing = 10 }; for (int j = i; j < i + cardsPerRow && j < units.Count; j++) { row.Items.Add(createCard(units[j], j)); } table.Rows.Add(new Eto.Forms.TableRow(row)); } table.Rows.Add(new Eto.Forms.TableRow(new Eto.Forms.Panel()) { ScaleHeight = true }); return new Eto.Forms.Scrollable { Content = table }; } }