// -----------------------------------------------------------------------
//
// Copyright 2014 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Contracts;
using System.Reactive.Linq;
using Perspex.Layout;
using Perspex.Media;
public enum HorizontalAlignment
{
Stretch,
Left,
Center,
Right,
}
public enum VerticalAlignment
{
Stretch,
Top,
Center,
Bottom,
}
public abstract class Control : Visual, ILayoutable
{
public static readonly ReadOnlyPerspexProperty ParentProperty =
new ReadOnlyPerspexProperty(ParentPropertyRW);
public static readonly PerspexProperty BackgroundProperty =
PerspexProperty.Register("Background");
public static readonly PerspexProperty BorderBrushProperty =
PerspexProperty.Register("BorderBrush");
public static readonly PerspexProperty BorderThicknessProperty =
PerspexProperty.Register("BorderThickness");
public static readonly PerspexProperty IsMouseOverProperty =
PerspexProperty.Register("IsMouseOver");
public static readonly PerspexProperty HorizontalAlignmentProperty =
PerspexProperty.Register("HorizontalAlignment");
public static readonly PerspexProperty VerticalAlignmentProperty =
PerspexProperty.Register("VerticalAlignment");
public static readonly PerspexProperty MarginProperty =
PerspexProperty.Register("Margin");
internal static readonly PerspexProperty ParentPropertyRW =
PerspexProperty.Register("Parent");
public Control()
{
this.Classes = new PerspexList();
this.GetObservableWithHistory(ParentPropertyRW).Subscribe(this.ParentChanged);
this.GetObservable(IsMouseOverProperty).Subscribe(x =>
{
if (x)
{
this.Classes.Add(":mouseover");
}
else
{
this.Classes.Remove(":mouseover");
}
});
// Hacky hack hack!
this.GetObservable(BackgroundProperty).Skip(1).Subscribe(_ => this.InvalidateMeasure());
}
public Brush Background
{
get { return this.GetValue(BackgroundProperty); }
set { this.SetValue(BackgroundProperty, value); }
}
public Brush BorderBrush
{
get { return this.GetValue(BorderBrushProperty); }
set { this.SetValue(BorderBrushProperty, value); }
}
public double BorderThickness
{
get { return this.GetValue(BorderThicknessProperty); }
set { this.SetValue(BorderThicknessProperty, value); }
}
public PerspexList Classes
{
get;
private set;
}
public IEnumerable