public GridZone(int spacing, MagneticSnap snapX, MagneticSnap snapY, Func <Orientation, int, bool> canSplit, GridData.Zone zone) { InitializeComponent(); OnSelectionChanged(); _splitter = new Rectangle { Fill = Application.Current.Resources[AccentColorBrushID] as SolidColorBrush, }; Body.Children.Add(_splitter); SplitterThickness = Math.Max(spacing, 1); SizeChanged += GridZone_SizeChanged; _snapX = snapX; _snapY = snapY; _canSplit = canSplit; _zone = zone; }
public GridZone(int spacing, MagneticSnap snapX, MagneticSnap snapY, Func<Orientation, int, bool> canSplit, GridData.Zone zone) { InitializeComponent(); OnSelectionChanged(); _splitter = new Rectangle { Fill = SystemParameters.WindowGlassBrush, }; Body.Children.Add(_splitter); SplitterThickness = Math.Max(spacing, 1); SizeChanged += GridZone_SizeChanged; _snapX = snapX; _snapY = snapY; _canSplit = canSplit; _zone = zone; }
private void SetupUI() { Size actualSize = WorkAreaSize(); if (actualSize.Width < 1 || _data == null || _data.Zones == null || Model == null) { return; } int spacing = Model.ShowSpacing ? Model.Spacing : 0; _data.MinZoneWidth = Convert.ToInt32(GridData.Multiplier / actualSize.Width * (MinZoneSize + (2 * spacing))); _data.MinZoneHeight = Convert.ToInt32(GridData.Multiplier / actualSize.Height * (MinZoneSize + (2 * spacing))); Preview.Children.Clear(); AdornerLayer.Children.Clear(); Preview.Width = actualSize.Width; Preview.Height = actualSize.Height; MagneticSnap snapX = new MagneticSnap(GridData.PrefixSum(Model.ColumnPercents).GetRange(1, Model.ColumnPercents.Count - 1), actualSize.Width); MagneticSnap snapY = new MagneticSnap(GridData.PrefixSum(Model.RowPercents).GetRange(1, Model.RowPercents.Count - 1), actualSize.Height); for (int zoneIndex = 0; zoneIndex < _data.Zones.Count; zoneIndex++) { // this is needed for the lambda int zoneIndexCopy = zoneIndex; var zone = _data.Zones[zoneIndex]; var zonePanel = new GridZone(spacing, snapX, snapY, (orientation, offset) => _data.CanSplit(zoneIndexCopy, offset, orientation), zone); zonePanel.UpdateShiftState(((App)Application.Current).MainWindowSettings.IsShiftKeyPressed); Preview.Children.Add(zonePanel); zonePanel.Split += OnSplit; zonePanel.MergeDrag += OnMergeDrag; zonePanel.MergeComplete += OnMergeComplete; SetZonePanelSize(zonePanel, zone); zonePanel.LabelID.Content = zoneIndex + 1; } foreach (var resizer in _data.Resizers) { var resizerThumb = new GridResizer(); resizerThumb.DragStarted += Resizer_DragStarted; resizerThumb.DragDelta += Resizer_DragDelta; resizerThumb.DragCompleted += Resizer_DragCompleted; resizerThumb.Orientation = resizer.Orientation; AdornerLayer.Children.Add(resizerThumb); if (resizer.Orientation == Orientation.Horizontal) { resizerThumb.LeftReferenceZone = resizer.PositiveSideIndices[0]; resizerThumb.RightReferenceZone = resizer.PositiveSideIndices.Last(); resizerThumb.TopReferenceZone = resizer.PositiveSideIndices[0]; resizerThumb.BottomReferenceZone = resizer.NegativeSideIndices[0]; } else { resizerThumb.LeftReferenceZone = resizer.PositiveSideIndices[0]; resizerThumb.RightReferenceZone = resizer.NegativeSideIndices[0]; resizerThumb.TopReferenceZone = resizer.PositiveSideIndices[0]; resizerThumb.BottomReferenceZone = resizer.PositiveSideIndices.Last(); } PlaceResizer(resizerThumb); } }