using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; using System.Numerics; using System.Runtime.CompilerServices; namespace Dashboard.Layout { public enum DisplayMode { None, Inline, Block, } public enum ContainerMode { Basic, Flex, Grid, } public enum FlowDirection { Row, Column, RowReverse, ColumnReverse, } public enum PositionMode { Absolute, Relative, } public enum OverflowMode { Hidden, Overflow, ScrollHorizontal, ScrollVertical, ScrollBoth, } public record struct TrackInfo(float Width, LayoutUnit Unit) { public static readonly TrackInfo Default = new TrackInfo(0, LayoutUnit.Auto); } public class ContainerLayoutInfo : INotifyPropertyChanged { private ContainerMode _containerMode; private FlowDirection _flowDirection = FlowDirection.Row; public ObservableCollection Rows { get; } = new ObservableCollection() { TrackInfo.Default }; public ObservableCollection Columns { get; } = new ObservableCollection() { TrackInfo.Default }; public ContainerMode ContainerMode { get => _containerMode; set => SetField(ref _containerMode, value); } public FlowDirection FlowDirection { get => _flowDirection; set => SetField(ref _flowDirection, value); } public event PropertyChangedEventHandler? PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } protected bool SetField(ref T field, T value, [CallerMemberName] string? propertyName = null) { if (EqualityComparer.Default.Equals(field, value)) return false; field = value; OnPropertyChanged(propertyName); return true; } } public class LayoutInfo : INotifyPropertyChanged { private DisplayMode _displayMode = DisplayMode.Inline; private PositionMode _positionMode = PositionMode.Relative; private OverflowMode _overflowMode = OverflowMode.Overflow; private int _row = 0; private int _column = 0; /// /// Changes the control display. /// public DisplayMode DisplayMode { get => _displayMode; set => SetField(ref _displayMode, value); } /// /// Changes how the control is positioned. /// public PositionMode PositionMode { get => _positionMode; set => SetField(ref _positionMode, value); } /// /// Changes how overflows are handled. /// public OverflowMode OverflowMode { get => _overflowMode; set => SetField(ref _overflowMode, value); } public LayoutBox Box { get; } = new LayoutBox(); /// /// The row of the control in a grid container. /// public int Row { get => _row; set => SetField(ref _row, value); } /// /// The column of the control in a grid container. /// public int Column { get => _column; set => SetField(ref _column, value); } public event PropertyChangedEventHandler? PropertyChanged; public LayoutInfo() { Box.PropertyChanged += BoxOnPropertyChanged; // Rows.CollectionChanged += RowsChanged; // Columns.CollectionChanged += ColumnsChanged; } private void BoxOnPropertyChanged(object? sender, PropertyChangedEventArgs e) { OnPropertyChanged(nameof(Box)); } protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private bool SetField(ref T field, T value, [CallerMemberName] string? propertyName = null) { if (EqualityComparer.Default.Equals(field, value)) return false; field = value; OnPropertyChanged(propertyName); return true; } } }