| 1 | using Avalonia; |
| 2 | using Avalonia.Controls; |
| 3 | using Avalonia.Layout; |
| 4 | using CascadeIDE.Features.UiChrome; |
| 5 | using MainDockCols = CascadeIDE.Features.UiChrome.UiWorkspaceLayoutDimensions.MainWindowMainGridColumns; |
| 6 | |
| 7 | namespace CascadeIDE.Services; |
| 8 | |
| 9 | /// <summary> |
| 10 | /// Применение размеров панелей главного окна: одна точка для VM, code-behind и <c>ide_set_panel_size</c>. |
| 11 | /// </summary> |
| 12 | public static class UiWorkspaceLayout |
| 13 | { |
| 14 | /// <summary>Колонка PFD MainGrid: ширина региона Pfd в px (0 — свернуть).</summary> |
| 15 | public static void ApplyPfdRegionColumnWidth(Grid mainGrid, double widthPixels) |
| 16 | { |
| 17 | if (mainGrid.ColumnDefinitions.Count <= MainDockCols.PfdRegion) |
| 18 | return; |
| 19 | var w = Math.Max(0, widthPixels); |
| 20 | mainGrid.ColumnDefinitions[MainDockCols.PfdRegion].Width = new GridLength(w); |
| 21 | } |
| 22 | |
| 23 | /// <summary>Регион Pfd: видимая ширина по умолчанию или 0.</summary> |
| 24 | public static void ApplyPfdRegionExpanded(Grid mainGrid, bool visible) => |
| 25 | ApplyPfdRegionColumnWidth( |
| 26 | mainGrid, |
| 27 | visible ? UiWorkspaceLayoutRuntimeMetrics.PfdRegionDefaultWidthPixels : 0); |
| 28 | |
| 29 | /// <summary>Колонка MFD в MainGrid (не Forward): ширина региона Mfd (px); при 0 — колонка схлопнута.</summary> |
| 30 | public static void ApplyMfdRegionColumns(Grid mainGrid, Grid? workspaceHealthColumnsGrid, double mfdRegionWidthPixels) |
| 31 | { |
| 32 | var w = Math.Max(0, mfdRegionWidthPixels); |
| 33 | |
| 34 | if (mainGrid.ColumnDefinitions.Count >= MainDockCols.Count) |
| 35 | mainGrid.ColumnDefinitions[MainDockCols.MfdRegion].Width = new GridLength(w); |
| 36 | |
| 37 | // Дублирующая сетка (если есть в разметке) с тем же порядком колонок, что у MainGrid. |
| 38 | if (workspaceHealthColumnsGrid is { ColumnDefinitions.Count: >= MainDockCols.Count } inner) |
| 39 | inner.ColumnDefinitions[MainDockCols.MfdRegion].Width = new GridLength(w); |
| 40 | } |
| 41 | |
| 42 | /// <summary>Найти MainGrid и WorkspaceHealthColumnsGrid по корню окна и применить ширину региона Mfd.</summary> |
| 43 | public static bool TryApplyMfdRegionColumnsFromRoot(Visual root, double mfdRegionWidthPixels) |
| 44 | { |
| 45 | if (UiControlAppearance.FindControlByName(root, "MainGrid") is not Grid main |
| 46 | || main.ColumnDefinitions.Count < MainDockCols.Count) |
| 47 | return false; |
| 48 | var inner = UiControlAppearance.FindControlByName(root, "WorkspaceHealthColumnsGrid") as Grid; |
| 49 | ApplyMfdRegionColumns(main, inner, mfdRegionWidthPixels); |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | /// <summary>Строка bottom dock в <c>MainGrid</c> (индекс строки).</summary> |
| 54 | public static void ApplyBottomRowHeight(Grid mainGrid, int rowIndex, double heightPixels) |
| 55 | { |
| 56 | if (mainGrid.RowDefinitions.Count <= rowIndex) |
| 57 | return; |
| 58 | var h = Math.Max(UiWorkspaceLayoutRuntimeMetrics.BottomPanelMinRowPixels, heightPixels); |
| 59 | mainGrid.RowDefinitions[rowIndex].Height = new GridLength(h); |
| 60 | } |
| 61 | |
| 62 | /// <summary>Строка 4 MainGrid — высота зоны над нижней панелью (терминал / сборка / …).</summary> |
| 63 | public static void ApplyBottomSplitterRowHeight(Grid mainGrid, double heightPixels) => |
| 64 | ApplyBottomRowHeight(mainGrid, 4, heightPixels); |
| 65 | |
| 66 | /// <summary>Строка вывода сборки в <c>EditorColumnGrid</c>.</summary> |
| 67 | public static void ApplyBuildOutputRowHeight(Grid editorColumnGrid, double heightPixels) |
| 68 | { |
| 69 | if (editorColumnGrid.RowDefinitions.Count <= 3) |
| 70 | return; |
| 71 | var h = Math.Max(UiWorkspaceLayoutRuntimeMetrics.BottomPanelMinRowPixels, heightPixels); |
| 72 | editorColumnGrid.RowDefinitions[3].Height = new GridLength(h); |
| 73 | } |
| 74 | |
| 75 | } |
| 76 | |