Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented ProgressBar #60

Merged
merged 1 commit into from
Jul 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Perspex.Controls/Perspex.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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" />
Expand Down
37 changes: 37 additions & 0 deletions Perspex.Controls/Primitives/RangeBase.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 28 deletions Perspex.Controls/Primitives/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -48,24 +39,6 @@ public ScrollBar()
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); }
Expand Down
28 changes: 28 additions & 0 deletions Perspex.Controls/ProgressBar.cs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions Perspex.Themes.Default/DefaultTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public DefaultTheme()
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());
Expand Down
1 change: 1 addition & 0 deletions Perspex.Themes.Default/Perspex.Themes.Default.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
73 changes: 73 additions & 0 deletions Perspex.Themes.Default/ProgressBarStyle.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}