Skip to content

Commit

Permalink
feat: add linear modern progressbar, partially implements #25
Browse files Browse the repository at this point in the history
  • Loading branch information
russkyc committed Oct 16, 2023
1 parent 2b7f60f commit f5eff75
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Russkyc.ModernControls.WPF/Controls/ModernProgressbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public partial class ModernProgressbar : Control
[DependencyProperty(typeof(double))]
public static readonly DependencyProperty ProgressProperty;

[DependencyProperty(typeof(bool))]
public static readonly DependencyProperty ShowProgressProperty;

[DependencyProperty(typeof(Thickness))]
public static readonly DependencyProperty TextMarginProperty;

[DependencyProperty(typeof(HorizontalAlignment))]
public static readonly DependencyProperty TextAlignmentProperty;

[DependencyProperty(typeof(Orientation))]
public static readonly DependencyProperty OrientationProperty;

// Border Styling
[DependencyProperty(typeof(CornerRadius))]
public static readonly DependencyProperty CornerRadiusProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// MIT License
//
// Copyright (c) 2023 Russell Camo (Russkyc)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;

namespace org.russkyc.moderncontrols.Converters;

[ValueConversion(typeof(Orientation), typeof(double))]
public class OrientationToAngleConverter : IValueConverter
{
public static OrientationToAngleConverter Instance = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not Orientation orientation)
{
return 0;
}

if (orientation is Orientation.Horizontal)
{
return 0;
}

return -90;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not double orientation)
{
return Orientation.Horizontal;
}

if (orientation is -90)
{
return Orientation.Vertical;
}

return Orientation.Horizontal;
}
}
17 changes: 17 additions & 0 deletions Russkyc.ModernControls.WPF/Styles/ModernProgressBarStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols">
<Style TargetType="{x:Type russkyc:ModernProgressbar}">
<Setter Property="Height" Value="15" />
<Setter Property="TextMargin" Value="3" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="Width" Value="100" />
<Setter Property="DefaultForeground" Value="{DynamicResource primary-default}" />
<Setter Property="DefaultBackground" Value="{DynamicResource bg-200}" />
Expand All @@ -16,6 +19,9 @@
Width="{Binding Width, RelativeSource={RelativeSource FindAncestor, AncestorType=russkyc:ModernProgressbar}}"
Height="{Binding Height, RelativeSource={RelativeSource FindAncestor, AncestorType=russkyc:ModernProgressbar}}"
VerticalAlignment="Stretch">
<Grid.RenderTransform>
<RotateTransform Angle="{Binding Orientation, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}, Converter={x:Static converters:OrientationToAngleConverter.Instance}}" />
</Grid.RenderTransform>
<Border
x:Name="Part_Track"
HorizontalAlignment="Stretch"
Expand All @@ -40,6 +46,17 @@
</TransformGroup>
</Border.RenderTransform>
</Border>
<TextBlock
Margin="{Binding TextMargin, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}"
HorizontalAlignment="{Binding TextAlignment, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}"
VerticalAlignment="Center"
FontFamily="{Binding FontFamily, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}"
FontSize="{Binding FontSize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}"
FontStretch="{Binding FontStretch, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}"
FontStyle="{Binding FontStyle, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}"
FontWeight="{Binding FontWeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}"
Foreground="#ffffff"
Text="{Binding Progress, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type russkyc:ModernProgressbar}}}" />
</Grid>
</ControlTemplate>
</Setter.Value>
Expand Down

0 comments on commit f5eff75

Please sign in to comment.