Skip to content

Commit

Permalink
Edit timer widget
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 18, 2024
1 parent 917bdaa commit 42a6457
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 107 deletions.
4 changes: 4 additions & 0 deletions src/Shared/Corathing.Contracts/DataContexts/WidgetContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public WidgetContext(IServiceProvider services) : this()
{
_services = services;
}

public virtual void OnDestroy()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public interface ILocalizationService
/// On LocalizationChanged
/// </summary>
/// <param name="action"></param>
void Provide(string key, Action<string> action);
void Provide(string key, Action<string> action, string fallbackValue = "");
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ public string GetString(string key)
return "";
}

private bool TryGetString(string key, out string value)
{
value = "";
foreach (var resManager in _stringResourceManagers.Values)
{
if (CachedApplicationCultureInfo == null)
{
ApplySystemLanguage();
}
string? resultString = resManager.GetString(key, CachedApplicationCultureInfo);
if (!string.IsNullOrEmpty(resultString))
{
value = resultString;
return true;
}
}
return false;
}


public event PropertyChangedEventHandler? PropertyChanged;
private void RaisePropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down Expand Up @@ -194,9 +213,17 @@ public void RegisterStringResourceManager(string namespaceName, ResourceManager
/// <summary>
/// <inheritdoc/>
/// </summary>
public void Provide(string key, Action<string> action)
public void Provide(string key, Action<string> action, string fallbackValue = "")
{
action?.Invoke(GetString(key));
_refreshProvideActions.Add(() => action?.Invoke(GetString(key)));
if (string.IsNullOrEmpty(key))
{
action?.Invoke(fallbackValue);
_refreshProvideActions.Add(() => action?.Invoke(fallbackValue));
}
else
{
action?.Invoke(TryGetString(key, out string value) ? value : fallbackValue);
_refreshProvideActions.Add(() => action?.Invoke(TryGetString(key, out string value) ? value : fallbackValue));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@

namespace Corathing.UI.WPF.Controls.CircularProgressBars;

[ValueConversion(typeof(double[]), typeof(Point))]
public class AngleRadiusToPointConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length != 2)
if (values.Length != 3)
return new();

if (values[0] is double angle &&
values[1] is double radius)
values[1] is double radius &&
values[2] is Thickness offset)
{
double piang = angle * Math.PI / 180;

double px = Math.Sin(piang) * radius + radius;
double py = -Math.Cos(piang) * radius + radius;

return new Point(px, py);
return new Point(px + offset.Left, py + offset.Top);
}

return new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@
xmlns:circulars="clr-namespace:Corathing.UI.WPF.Controls.CircularProgressBars"
xmlns:converters="clr-namespace:Corathing.UI.WPF.Converters">

<converters:DoubleValueConverter x:Key="DoubleValueConverter" />
<circulars:AngleRadiusToPointConverter x:Key="AngleRadiusToPointConverter" />
<circulars:AngleToIsLargeConverter x:Key="AngleToIsLargeConverter" />
<circulars:RadiusToSizeConverter x:Key="RadiusToSizeConverter" />
<circulars:RadiusToStartPointConverter x:Key="RadiusToStartPointConverter" />

<Style TargetType="{x:Type circulars:CircularProgressBar}"
x:Key="AutoCircularProgressBar">
<Setter Property="Value"
Value="10" />
<Setter Property="Maximum"
Value="100" />
<Setter Property="StrokeThickness"
Value="10" />
<Setter Property="HighlightStroke"
Value="LightGreen" />
<Setter Property="ShadowStroke"
Value="LightGray" />
<Setter Property="HighlightThickness"
Value="8" />
<Setter Property="ShadowThickness"
Value="8" />
<Setter Property="Radius"
Value="50" />
<Setter Property="Duration"
Value="500" />
<Setter Property="HorizontalAlignment"
Value="Stretch" />
<Setter Property="VerticalAlignment"
Expand All @@ -27,55 +33,61 @@
Value="Clockwise" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type circulars:CircularProgressBar}">
<Canvas Width="{Binding Path=Radius,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}},
Converter={StaticResource DoubleValueConverter},
Mode=OneWay}"
Height="{Binding Path=Radius,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}},
Converter={StaticResource DoubleValueConverter},
Mode=OneWay}">
<Ellipse Width="{Binding Path=Radius,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}},
Converter={StaticResource DoubleValueConverter}, Mode=OneWay}"
Height="{Binding Path=Radius,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}},
Converter={StaticResource DoubleValueConverter}, Mode=OneWay}"
Margin="{Binding Path=ShadowStorkeMargin, RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
Stroke="LightGray"
StrokeThickness="{Binding Path=InnerThickness,
<ControlTemplate TargetType="{x:Type circulars:CircularProgressBar}" x:Name="PART_CircularProgressBarMain">
<Canvas Width="{Binding Path=Diameter,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
Height="{Binding Path=Diameter,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}">
<Ellipse Width="{Binding Path=ShadowDiameter,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
Height="{Binding Path=ShadowDiameter,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
Margin="{Binding Path=ShadowStorkeMargin,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
Stroke="{TemplateBinding ShadowStroke}"
StrokeThickness="{Binding Path=ShadowThickness,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}" />

<Path Stroke="{TemplateBinding Background}"
StrokeThickness="{TemplateBinding StrokeThickness}"
Margin="{Binding Path=HighlightStrokeMargin, RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}">
<Path Stroke="{TemplateBinding HighlightStroke}"
StrokeThickness="{TemplateBinding HighlightThickness}"
Width="{Binding Path=Diameter,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
Height="{Binding Path=Diameter,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}">

<Path.Data>
<PathGeometry>
<PathFigure StartPoint="{Binding Path=StartPoint,
Converter={StaticResource RadiusToStartPointConverter},
RelativeSource={RelativeSource FindAncestor,
AncestorType=circulars:CircularProgressBar}}">
<PathFigure>
<PathFigure.StartPoint>
<MultiBinding Converter="{StaticResource AngleRadiusToPointConverter}">
<MultiBinding.Bindings>
<Binding Path="StartAngle"
RelativeSource="{RelativeSource AncestorType=circulars:CircularProgressBar}" />
<Binding Path="HighlightRadius"
RelativeSource="{RelativeSource AncestorType=circulars:CircularProgressBar}" />
<Binding Path="HighlightStrokeMargin"
RelativeSource="{RelativeSource AncestorType=circulars:CircularProgressBar}" />
</MultiBinding.Bindings>
</MultiBinding>
</PathFigure.StartPoint>
<ArcSegment RotationAngle="0"
SweepDirection="{Binding Path=SweepDirection,
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
Size="{Binding Path=HighlightSize,
RelativeSource={RelativeSource FindAncestor,
AncestorType=circulars:CircularProgressBar}}"
IsLargeArc="{Binding Path=MidRadius,
Size="{Binding Path=HighlightRadius,
Converter={StaticResource RadiusToSizeConverter},
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}"
IsLargeArc="{Binding Path=Angle,
Converter={StaticResource AngleToIsLargeConverter},
RelativeSource={RelativeSource FindAncestor,
AncestorType=circulars:CircularProgressBar}}">
RelativeSource={RelativeSource AncestorType={x:Type circulars:CircularProgressBar}}}">
<ArcSegment.Point>
<MultiBinding Converter="{StaticResource AngleRadiusToPointConverter}">
<MultiBinding.Bindings>
<Binding Path="Angle"
RelativeSource="{RelativeSource FindAncestor,
AncestorType=circulars:CircularProgressBar}" />
<Binding Path="MidRadius"
RelativeSource="{RelativeSource FindAncestor,
AncestorType=circulars:CircularProgressBar}" />
RelativeSource="{RelativeSource AncestorType=circulars:CircularProgressBar}" />
<Binding Path="HighlightRadius"
RelativeSource="{RelativeSource AncestorType=circulars:CircularProgressBar}" />
<Binding Path="HighlightStrokeMargin"
RelativeSource="{RelativeSource AncestorType=circulars:CircularProgressBar}" />
</MultiBinding.Bindings>
</MultiBinding>
</ArcSegment.Point>
Expand All @@ -97,7 +109,7 @@
Value="10" />
<Setter Property="Maximum"
Value="100" />
<Setter Property="StrokeThickness"
<Setter Property="HighlightThickness"
Value="10" />
<Setter Property="Radius"
Value="50" />
Expand All @@ -114,7 +126,7 @@
StrokeThickness="1" />

<Path Stroke="{TemplateBinding Background}"
StrokeThickness="{TemplateBinding StrokeThickness}">
StrokeThickness="{TemplateBinding HighlightThickness}">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="50,0">
Expand Down
Loading

0 comments on commit 42a6457

Please sign in to comment.