Browse Source

Merge pull request #60 from ncarrillo/feat-win-progress

Implemented ProgressBar
pull/63/head
Steven Kirk 11 years ago
parent
commit
5860540bab
  1. 2
      Perspex.Controls/Perspex.Controls.csproj
  2. 37
      Perspex.Controls/Primitives/RangeBase.cs
  3. 29
      Perspex.Controls/Primitives/ScrollBar.cs
  4. 28
      Perspex.Controls/ProgressBar.cs
  5. 1
      Perspex.Themes.Default/DefaultTheme.cs
  6. 1
      Perspex.Themes.Default/Perspex.Themes.Default.csproj
  7. 73
      Perspex.Themes.Default/ProgressBarStyle.cs

2
Perspex.Controls/Perspex.Controls.csproj

@ -63,6 +63,8 @@
<Compile Include="Presenters\DeckPresenter.cs" />
<Compile Include="Primitives\AdornerDecorator.cs" />
<Compile Include="Primitives\AdornerLayer.cs" />
<Compile Include="Primitives\RangeBase.cs" />
<Compile Include="ProgressBar.cs" />
<Compile Include="RadioButton.cs" />
<Compile Include="CheckBox.cs" />
<Compile Include="ColumnDefinition.cs" />

37
Perspex.Controls/Primitives/RangeBase.cs

@ -0,0 +1,37 @@
namespace Perspex.Controls.Primitives
{
using System;
using System.Reactive;
using System.Reactive.Linq;
using Perspex.Controls.Templates;
public abstract class RangeBase : TemplatedControl
{
public static readonly PerspexProperty<double> MinimumProperty =
PerspexProperty.Register<RangeBase, double>("Minimum");
public static readonly PerspexProperty<double> MaximumProperty =
PerspexProperty.Register<RangeBase, double>("Maximum", defaultValue: 100.0);
public static readonly PerspexProperty<double> ValueProperty =
PerspexProperty.Register<RangeBase, double>("Value");
public double Minimum
{
get { return this.GetValue(MinimumProperty); }
set { this.SetValue(MinimumProperty, value); }
}
public double Maximum
{
get { return this.GetValue(MaximumProperty); }
set { this.SetValue(MaximumProperty, value); }
}
public double Value
{
get { return this.GetValue(ValueProperty); }
set { this.SetValue(ValueProperty, value); }
}
}
}

29
Perspex.Controls/Primitives/ScrollBar.cs

@ -11,17 +11,8 @@ namespace Perspex.Controls.Primitives
using System.Reactive.Linq;
using Perspex.Controls.Templates;
public class ScrollBar : TemplatedControl
public class ScrollBar : RangeBase
{
public static readonly PerspexProperty<double> MinimumProperty =
PerspexProperty.Register<ScrollBar, double>("Minimum");
public static readonly PerspexProperty<double> MaximumProperty =
PerspexProperty.Register<ScrollBar, double>("Maximum", defaultValue: 100.0);
public static readonly PerspexProperty<double> ValueProperty =
PerspexProperty.Register<ScrollBar, double>("Value");
public static readonly PerspexProperty<double> ViewportSizeProperty =
PerspexProperty.Register<ScrollBar, double>("ViewportSize", defaultValue: double.NaN);
@ -48,24 +39,6 @@ namespace Perspex.Controls.Primitives
this.Bind(ScrollBar.IsVisibleProperty, isVisible, BindingPriority.Style);
}
public double Minimum
{
get { return this.GetValue(MinimumProperty); }
set { this.SetValue(MinimumProperty, value); }
}
public double Maximum
{
get { return this.GetValue(MaximumProperty); }
set { this.SetValue(MaximumProperty, value); }
}
public double Value
{
get { return this.GetValue(ValueProperty); }
set { this.SetValue(ValueProperty, value); }
}
public double ViewportSize
{
get { return this.GetValue(ViewportSizeProperty); }

28
Perspex.Controls/ProgressBar.cs

@ -0,0 +1,28 @@
namespace Perspex.Controls
{
using System;
using System.Reactive;
using System.Reactive.Linq;
using Perspex.Controls.Templates;
using Perspex.Controls.Primitives;
public class ProgressBar : RangeBase
{
public static readonly PerspexProperty<bool> IsIndeterminateProperty =
PerspexProperty.Register<ProgressBar, bool>("IsIndeterminate", defaultValue: false);
public static readonly PerspexProperty<Orientation> OrientationProperty =
PerspexProperty.Register<ProgressBar, Orientation>("Orientation", defaultValue: Orientation.Horizontal);
protected override Size ArrangeOverride(Size finalSize)
{
var size = base.ArrangeOverride(finalSize);
var b = this.Bounds;
var indicator = this.GetTemplateChild<Border>("PART_Indicator");
indicator.Width = finalSize.Width * (this.Value / 100);
return size;
}
}
}

1
Perspex.Themes.Default/DefaultTheme.cs

@ -26,6 +26,7 @@ namespace Perspex.Themes.Default
this.Add(new MenuStyle());
this.Add(new MenuItemStyle());
this.Add(new PopupRootStyle());
this.Add(new ProgressBarStyle());
this.Add(new RadioButtonStyle());
this.Add(new ScrollBarStyle());
this.Add(new ScrollViewerStyle());

1
Perspex.Themes.Default/Perspex.Themes.Default.csproj

@ -73,6 +73,7 @@
<ItemGroup>
<Compile Include="MenuItemStyle.cs" />
<Compile Include="MenuStyle.cs" />
<Compile Include="ProgressBarStyle.cs" />
<Compile Include="ToolTipStyle.cs" />
<Compile Include="FocusAdornerStyle.cs" />
<Compile Include="DropDownStyle.cs" />

73
Perspex.Themes.Default/ProgressBarStyle.cs

@ -0,0 +1,73 @@
namespace Perspex.Themes.Default
{
using System.Linq;
using System.Reactive.Linq;
using Perspex.Controls;
using Perspex.Controls.Presenters;
using Perspex.Controls.Primitives;
using Perspex.Controls.Shapes;
using Perspex.Layout;
using Perspex.Media;
using Perspex.Styling;
public class ProgressBarStyle : Styles
{
public ProgressBarStyle()
{
this.AddRange(new[]
{
new Style(x => x.OfType<ProgressBar>())
{
Setters = new[]
{
new Setter(ProgressBar.TemplateProperty, ControlTemplate.Create<ProgressBar>(this.Template)),
new Setter(ProgressBar.BackgroundProperty, new SolidColorBrush(0xffdddddd)),
new Setter(ProgressBar.ForegroundProperty, new SolidColorBrush(0xffbee6fd)),
},
}
});
}
private Control Template(ProgressBar control)
{
Border container = new Border
{
[~Border.BackgroundProperty] = control[~ProgressBar.BackgroundProperty],
[~Border.BorderBrushProperty] = control[~ProgressBar.BorderBrushProperty],
[~Border.BorderThicknessProperty] = control[~ProgressBar.BorderThicknessProperty],
Content = new Grid
{
MinHeight = 14,
MinWidth = 200,
Children = new Controls
{
new Border
{
Name = "PART_Track",
BorderThickness = 1,
[~Border.BorderBrushProperty] = control[~ProgressBar.BackgroundProperty],
},
new Border
{
Name = "PART_Indicator",
BorderThickness = 1,
HorizontalAlignment = HorizontalAlignment.Left,
[~Border.BackgroundProperty] = control[~ProgressBar.ForegroundProperty],
Content = new Grid
{
Name = "Animation",
ClipToBounds = true,
}
}
}
}
};
return container;
}
}
}
Loading…
Cancel
Save