Skip to content

Commit

Permalink
More bugfixes/compose view improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
WamWooWam committed Nov 25, 2024
1 parent affacd9 commit 5a1b4a7
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 14 deletions.
8 changes: 7 additions & 1 deletion UniSky/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
<FeedTemplates xmlns="using:UniSky.Templates"/>

<!-- Controls -->
<ResourceDictionary Source="/Templates/SheetControlStyles.xaml"/>
<ResourceDictionary Source="/Controls/Sheet/SheetControl.xaml"/>
<ResourceDictionary Source="/Controls/RadialProgressBar/RadialProgressBar.xaml"/>
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="ApplicationPageBackgroundThemeBrush" Color="#FF080808" />
<SolidColorBrush x:Key="SystemControlSeparatorBrush" Color="#FF404040"/>
<Color x:Key="SystemListExtraLowColor">#10FFFFFF</Color>
</ResourceDictionary>
<ResourceDictionary x:Key="Default">
<SolidColorBrush x:Key="SystemControlSeparatorBrush" Color="#FFDEDEDE"/>
<Color x:Key="SystemListExtraLowColor">#10000000</Color>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

Expand All @@ -48,6 +51,9 @@
<x:Double x:Key="ControlContentThemeFontSize">14</x:Double>
<x:Double x:Key="ContentControlFontSize">14</x:Double>

<SolidColorBrush x:Key="SystemControlBackgroundListExtraLowBrush"
Color="{ThemeResource SystemListExtraLowColor}"/>

<Style TargetType="sheets:SheetControl" BasedOn="{StaticResource DefaultSheetControlStyle}"/>
</ResourceDictionary>
</controls:XamlControlsResources.MergedDictionaries>
Expand Down
41 changes: 39 additions & 2 deletions UniSky/Controls/Compose/ComposeSheet.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniSky.Controls.Compose"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:converters="using:UniSky.Converters"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:UniSky.Converters"
xmlns:extensions="using:UniSky.Extensions" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="320"
Style="{StaticResource DefaultSheetControlStyle}"
DataContext="{x:Bind ViewModel, Mode=OneWay}"
Expand All @@ -26,6 +28,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Grid x:Name="ErrorContainer"
Expand Down Expand Up @@ -90,10 +93,44 @@
<TextBox x:Name="PrimaryTextBox"
Style="{StaticResource BorderlessTextBoxStyle}"
Grid.Column="1"
Text="{x:Bind ViewModel.Text, Mode=TwoWay}"
Text="{x:Bind ViewModel.Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
PlaceholderText="What's happening?"
MaxLength="300" />
</Grid>
</UserControl>

<Grid x:Name="FooterContainer"
Grid.Row="2"
Background="{ThemeResource SystemControlBackgroundListExtraLowBrush}"
BorderBrush="{ThemeResource SystemControlSeparatorBrush}"
Padding="0,0,0,2"
extensions:HairlineBorder.Thickness="0,1,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<StackPanel Margin="2,0,0,0"
VerticalAlignment="Stretch"
Orientation="Horizontal">
<Button Style="{ThemeResource IconButtonStyle}"
Content="&#xEB9F;"
Margin="0,0,2,0"/>
<Button Style="{ThemeResource IconButtonStyle}"
Content="&#xE714;"
Margin="0,0,2,0"/>
<Button Style="{ThemeResource IconButtonStyle}"
Content="&#xE910;"
Margin="0,0,2,0"/>
</StackPanel>

<controls:RadialProgressBar Grid.Column="1"
Margin="8,6"
Minimum="0"
Maximum="{x:Bind ViewModel.MaxCharacters}"
Value="{x:Bind ViewModel.Characters, Mode=OneWay}"
Width="32"
Height="32"/>
</Grid>
</Grid>
</sheet:SheetControl>
8 changes: 6 additions & 2 deletions UniSky/Controls/Compose/ComposeSheet.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ private async void OnHiding(SheetControl sender, SheetHidingEventArgs e)

private void OnInputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
ContentGrid.Padding = new Thickness(0, 0, 0, args.OccludedRect.Top - args.OccludedRect.Bottom);
if (ActualWidth > 620) return;

ContentGrid.Padding = new Thickness(0, 0, 0, args.OccludedRect.Height);
args.EnsuredFocusedElementInView = true;
}

private void OnInputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
ContentGrid.Padding = new Thickness(0, 0, 0, args.OccludedRect.Top - args.OccludedRect.Bottom);
if (ActualWidth > 620) return;

ContentGrid.Padding = new Thickness(0, 0, 0, args.OccludedRect.Height);
args.EnsuredFocusedElementInView = true;
}

Expand Down
202 changes: 202 additions & 0 deletions UniSky/Controls/RadialProgressBar/RadialProgressBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// An alternative implementation of a progress bar.
/// Progression is represented by a loop filling up in a clockwise fashion.
/// Like the traditional progress bar, it inherits from RangeBase, so Minimum, Maximum and Value properties work the same way.
/// </summary>
[TemplatePart(Name = OutlineFigurePartName, Type = typeof(PathFigure))]
[TemplatePart(Name = OutlineArcPartName, Type = typeof(ArcSegment))]
[TemplatePart(Name = BarFigurePartName, Type = typeof(PathFigure))]
[TemplatePart(Name = BarArcPartName, Type = typeof(ArcSegment))]
[TemplatePart(Name = TextPartName, Type = typeof(TextBlock))]
public partial class RadialProgressBar : ProgressBar
{
private const string OutlineFigurePartName = "OutlineFigurePart";
private const string OutlineArcPartName = "OutlineArcPart";
private const string BarFigurePartName = "BarFigurePart";
private const string BarArcPartName = "BarArcPart";
private const string TextPartName = "ProgressTextPart";

private PathFigure outlineFigure;
private PathFigure barFigure;
private ArcSegment outlineArc;
private ArcSegment barArc;
private TextBlock textBlock;

private bool allTemplatePartsDefined = false;

/// <summary>
/// Called when the Minimum property changes.
/// </summary>
/// <param name="oldMinimum">Old value of the Minimum property.</param>
/// <param name="newMinimum">New value of the Minimum property.</param>
protected override void OnMinimumChanged(double oldMinimum, double newMinimum)
{
base.OnMinimumChanged(oldMinimum, newMinimum);
RenderSegment();
}

/// <summary>
/// Called when the Maximum property changes.
/// </summary>
/// <param name="oldMaximum">Old value of the Maximum property.</param>
/// <param name="newMaximum">New value of the Maximum property.</param>
protected override void OnMaximumChanged(double oldMaximum, double newMaximum)
{
base.OnMaximumChanged(oldMaximum, newMaximum);
RenderSegment();
}

/// <summary>
/// Called when the Value property changes.
/// </summary>
/// <param name="oldValue">Old value of the Value property.</param>
/// <param name="newValue">New value of the Value property.</param>
protected override void OnValueChanged(double oldValue, double newValue)
{
base.OnValueChanged(oldValue, newValue);
RenderSegment();
}

/// <summary>
/// Update the visual state of the control when its template is changed.
/// </summary>
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

outlineFigure = GetTemplateChild(OutlineFigurePartName) as PathFigure;
outlineArc = GetTemplateChild(OutlineArcPartName) as ArcSegment;
barFigure = GetTemplateChild(BarFigurePartName) as PathFigure;
barArc = GetTemplateChild(BarArcPartName) as ArcSegment;
textBlock = GetTemplateChild(TextPartName) as TextBlock;

allTemplatePartsDefined = outlineFigure != null && outlineArc != null && barFigure != null && barArc != null && textBlock != null;

RenderAll();
}

/// <summary>
/// Gets or sets the thickness of the circular outline and segment
/// </summary>
public double Thickness
{
get { return (double)GetValue(ThicknessProperty); }
set { SetValue(ThicknessProperty, value); }
}

/// <summary>
/// Identifies the Thickness dependency property
/// </summary>
public static readonly DependencyProperty ThicknessProperty = DependencyProperty.Register(nameof(Thickness), typeof(double), typeof(RadialProgressBar), new PropertyMetadata(0.0, ThicknessChangedHandler));

/// <summary>
/// Gets or sets the color of the circular outline on which the segment is drawn
/// </summary>
public Brush Outline
{
get { return (Brush)GetValue(OutlineProperty); }
set { SetValue(OutlineProperty, value); }
}

/// <summary>
/// Identifies the Outline dependency property
/// </summary>
public static readonly DependencyProperty OutlineProperty = DependencyProperty.Register(nameof(Outline), typeof(Brush), typeof(RadialProgressBar), new PropertyMetadata(new SolidColorBrush(Windows.UI.Colors.Transparent)));

/// <summary>
/// Initializes a new instance of the <see cref="RadialProgressBar"/> class.
/// Create a default circular progress bar
/// </summary>
public RadialProgressBar()
{
DefaultStyleKey = typeof(RadialProgressBar);
SizeChanged += SizeChangedHandler;
}

// Render outline and progress segment when thickness is changed
private static void ThicknessChangedHandler(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var sender = d as RadialProgressBar;
sender.RenderAll();
}

// Render outline and progress segment when control is resized.
private void SizeChangedHandler(object sender, SizeChangedEventArgs e)
{
var self = sender as RadialProgressBar;
self.RenderAll();
}

private double ComputeNormalizedRange()
{
var range = Maximum - Minimum;
var delta = Value - Minimum;
var output = range == 0.0 ? 0.0 : delta / range;
output = Math.Min(Math.Max(0.0, output), 0.9999);
return output;
}

// Compute size of ellipse so that the outer edge touches the bounding rectangle
private Size ComputeEllipseSize()
{
var safeThickness = Math.Max(Thickness, 0.0);
var width = Math.Max((ActualWidth - safeThickness) / 2.0, 0.0);
var height = Math.Max((ActualHeight - safeThickness) / 2.0, 0.0);
return new Size(width, height);
}

// Render the segment representing progress ratio.
private void RenderSegment()
{
if (!allTemplatePartsDefined)
{
return;
}

textBlock.Text = ((int)(Maximum - Value)).ToString();

var normalizedRange = ComputeNormalizedRange();

var angle = 2 * Math.PI * normalizedRange;
var size = ComputeEllipseSize();
var translationFactor = Math.Max(Thickness / 2.0, 0.0);

double x = (Math.Sin(angle) * size.Width) + size.Width + translationFactor;
double y = (((Math.Cos(angle) * size.Height) - size.Height) * -1) + translationFactor;

barArc.IsLargeArc = angle >= Math.PI;
barArc.Point = new Point(x, y);
}

// Render the progress segment and the loop outline. Needs to run when control is resized or retemplated
private void RenderAll()
{
if (!allTemplatePartsDefined)
{
return;
}

var size = ComputeEllipseSize();
var segmentWidth = size.Width;
var translationFactor = Math.Max(Thickness / 2.0, 0.0);

outlineFigure.StartPoint = barFigure.StartPoint = new Point(segmentWidth + translationFactor, translationFactor);
outlineArc.Size = barArc.Size = new Size(segmentWidth, size.Height);
outlineArc.Point = new Point(segmentWidth + translationFactor - 0.05, translationFactor);

RenderSegment();
}
}
}
63 changes: 63 additions & 0 deletions UniSky/Controls/RadialProgressBar/RadialProgressBar.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.UI.Controls">

<Style TargetType="local:RadialProgressBar" >
<Setter Property="Foreground" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
<Setter Property="Outline" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Thickness" Value="4"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:RadialProgressBar">
<Grid Background="{TemplateBinding Background}">
<!-- Gray outline of progress bar -->
<Path Fill="Transparent" Stroke="{TemplateBinding Outline}" StrokeThickness="{TemplateBinding Thickness}" StrokeDashCap="Flat">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure x:Name="OutlineFigurePart">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment x:Name="OutlineArcPart" IsLargeArc="True" SweepDirection="Clockwise"/>
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
<!-- Progress Bar -->
<Path Fill="Transparent" Stroke="{TemplateBinding Foreground}" StrokeThickness="{TemplateBinding Thickness}" StrokeDashCap="Flat">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure x:Name="BarFigurePart">
<PathFigure.Segments>
<PathSegmentCollection>
<ArcSegment x:Name="BarArcPart" IsLargeArc="False" SweepDirection="Clockwise" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>

<TextBlock x:Name="ProgressTextPart"
FontSize="12"
Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Typography.NumeralAlignment="Tabular"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
File renamed without changes.
Loading

0 comments on commit 5a1b4a7

Please sign in to comment.