172 lines
4.6 KiB
C#
172 lines
4.6 KiB
C#
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<TrackInfo> Rows { get; } = new ObservableCollection<TrackInfo>() { TrackInfo.Default };
|
|
|
|
public ObservableCollection<TrackInfo> Columns { get; } =
|
|
new ObservableCollection<TrackInfo>() { 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<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
|
{
|
|
if (EqualityComparer<T>.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;
|
|
|
|
/// <summary>
|
|
/// Changes the control display.
|
|
/// </summary>
|
|
public DisplayMode DisplayMode
|
|
{
|
|
get => _displayMode;
|
|
set => SetField(ref _displayMode, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Changes how the control is positioned.
|
|
/// </summary>
|
|
public PositionMode PositionMode
|
|
{
|
|
get => _positionMode;
|
|
set => SetField(ref _positionMode, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Changes how overflows are handled.
|
|
/// </summary>
|
|
public OverflowMode OverflowMode
|
|
{
|
|
get => _overflowMode;
|
|
set => SetField(ref _overflowMode, value);
|
|
}
|
|
|
|
public LayoutBox Box { get; } = new LayoutBox();
|
|
|
|
/// <summary>
|
|
/// The row of the control in a grid container.
|
|
/// </summary>
|
|
public int Row
|
|
{
|
|
get => _row;
|
|
set => SetField(ref _row, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The column of the control in a grid container.
|
|
/// </summary>
|
|
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<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
|
{
|
|
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
|
field = value;
|
|
OnPropertyChanged(propertyName);
|
|
return true;
|
|
}
|
|
}
|
|
}
|