Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Commit 2a062ad

Browse files
committed
Moved SideDrawer size managment to Shell
1 parent c58cfb2 commit 2a062ad

File tree

4 files changed

+103
-69
lines changed

4 files changed

+103
-69
lines changed

src/Quarrel/Controls/Shell/Shell.xaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,39 @@
88
xmlns:panels="using:Quarrel.Controls.Shell.Panels"
99
mc:Ignorable="d"
1010
d:DesignHeight="300"
11-
d:DesignWidth="400">
12-
<Grid Background="{ThemeResource CommandBarBackground}">
11+
d:DesignWidth="400"
12+
SizeChanged="OnSizeChanged">
13+
<Grid x:Name="root" Background="{ThemeResource CommandBarBackground}">
14+
<VisualStateManager.VisualStateGroups>
15+
<VisualStateGroup>
16+
<VisualState x:Name="Small">
17+
<VisualState.Setters>
18+
<!--<Setter Target="Drawer.Size" Value="Small"/>-->
19+
</VisualState.Setters>
20+
</VisualState>
21+
<VisualState x:Name="Medium">
22+
<VisualState.Setters>
23+
<!--<Setter Target="Drawer.Size" Value="Medium"/>-->
24+
</VisualState.Setters>
25+
</VisualState>
26+
<VisualState x:Name="Large">
27+
<VisualState.Setters>
28+
<!--<Setter Target="Drawer.Size" Value="Large"/>-->
29+
</VisualState.Setters>
30+
</VisualState>
31+
<VisualState x:Name="ExtraLarge">
32+
<VisualState.Setters>
33+
<!--<Setter Target="Drawer.Size" Value="ExtraLarge"/>-->
34+
</VisualState.Setters>
35+
</VisualState>
36+
</VisualStateGroup>
37+
</VisualStateManager.VisualStateGroups>
1338
<Grid.RowDefinitions>
1439
<RowDefinition Height="auto"/>
1540
<RowDefinition/>
1641
</Grid.RowDefinitions>
1742
<local:QuarrelCommandBar/>
18-
<local:SideDrawer x:Name="Drawer" Grid.Row="1">
43+
<local:SideDrawer x:Name="Drawer" Grid.Row="1" Size="Large">
1944
<local:SideDrawer.LeftContent>
2045
<Grid Background="{ThemeResource TertiaryPaneBackground}">
2146
<panels:GuildPanel/>

src/Quarrel/Controls/Shell/Shell.xaml.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Quarrel.Messages.Navigation;
77
using Quarrel.Messages.Panel;
88
using System;
9+
using Windows.UI.Xaml;
910
using Windows.UI.Xaml.Controls;
1011

1112
namespace Quarrel.Controls.Shell
@@ -23,6 +24,21 @@ public Shell()
2324
_messenger.Register<TogglePanelMessage>(this, (_, e) => GoToPanelState(e));
2425
}
2526

27+
/// <summary>
28+
/// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.Medium"/> size UI.
29+
/// </summary>
30+
public double MediumMinSize { get; set; } = 600;
31+
32+
/// <summary>
33+
/// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.Large"/> size UI.
34+
/// </summary>
35+
public double LargeMinSize { get; set; } = 1100;
36+
37+
/// <summary>
38+
/// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.ExtraLarge"/> size UI.
39+
/// </summary>
40+
public double ExtraLargeMinSize { get; set; } = 1400;
41+
2642
private void GoToPanelState(TogglePanelMessage state)
2743
{
2844
Action? action = state switch
@@ -38,5 +54,33 @@ private void GoToPanelState(TogglePanelMessage state)
3854

3955
action?.Invoke();
4056
}
57+
58+
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
59+
{
60+
double width = e.NewSize.Width;
61+
string stateName = string.Empty;
62+
if (width < MediumMinSize)
63+
{
64+
stateName = nameof(Small);
65+
Drawer.Size = SideDrawerSize.Small;
66+
}
67+
else if (width < LargeMinSize)
68+
{
69+
stateName = nameof(Medium);
70+
Drawer.Size = SideDrawerSize.Medium;
71+
}
72+
else if (width < ExtraLargeMinSize)
73+
{
74+
stateName = nameof(Large);
75+
Drawer.Size = SideDrawerSize.Large;
76+
}
77+
else
78+
{
79+
stateName = nameof(ExtraLarge);
80+
Drawer.Size = SideDrawerSize.ExtraLarge;
81+
}
82+
83+
VisualStateManager.GoToState(this, stateName, true);
84+
}
4185
}
4286
}

src/Quarrel/Controls/Shell/SideDrawer.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
xmlns:qc="using:Quarrel.Controls"
99
mc:Ignorable="d"
1010
d:DesignHeight="300"
11-
d:DesignWidth="400"
12-
SizeChanged="OnSizeChanged">
11+
d:DesignWidth="400">
1312

1413
<Grid x:Name="rootgrid" PointerPressed="OnPointerPressed">
1514
<Grid x:Name="leftwrap" HorizontalAlignment="Left">

src/Quarrel/Controls/Shell/SideDrawer.xaml.cs

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public sealed partial class SideDrawer : UserControl
2727
private static readonly DependencyProperty SecondaryPanelWidthProperty =
2828
DependencyProperty.Register(nameof(SecondaryPanelWidth), typeof(float), typeof(Shadow), new PropertyMetadata(228f, OnPanelWidthPropertyChanged));
2929

30-
private InteractionTracker _tracker;
31-
private VisualInteractionSource _interactionSource;
32-
private Compositor _compositor;
30+
private readonly InteractionTracker _tracker;
31+
private readonly VisualInteractionSource _interactionSource;
32+
private readonly Compositor _compositor;
3333

34-
private Visual _mainVisual;
35-
private Visual _leftVisual;
36-
private Visual _left2Visual;
37-
private Visual _rightVisual;
34+
private readonly Visual _mainVisual;
35+
private readonly Visual _leftVisual;
36+
private readonly Visual _left2Visual;
37+
private readonly Visual _rightVisual;
3838

3939
// These animations represent the position of the panes relative to the tracker position.
4040
private ExpressionAnimation? _mainTranslateAnimation;
@@ -46,9 +46,9 @@ public sealed partial class SideDrawer : UserControl
4646
// The start point is where the panel rests when the left panel is open
4747
// The mid point is where the panel rests when the panels are closed
4848
// The end point is where the panel rests when the right panel is open
49-
private InteractionTrackerInertiaRestingValue _startPoint;
50-
private InteractionTrackerInertiaRestingValue _midPoint;
51-
private InteractionTrackerInertiaRestingValue _endPoint;
49+
private readonly InteractionTrackerInertiaRestingValue _startPoint;
50+
private readonly InteractionTrackerInertiaRestingValue _midPoint;
51+
private readonly InteractionTrackerInertiaRestingValue _endPoint;
5252

5353
/// <summary>
5454
/// Inializes a new instance of the <see cref="SideDrawer"/> class.
@@ -137,21 +137,6 @@ public object RightContent
137137
set => RightContentControl.Content = value;
138138
}
139139

140-
/// <summary>
141-
/// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.Medium"/> size UI.
142-
/// </summary>
143-
public double MediumMinSize { get; set; } = 600;
144-
145-
/// <summary>
146-
/// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.Large"/> size UI.
147-
/// </summary>
148-
public double LargeMinSize { get; set; } = 1100;
149-
150-
/// <summary>
151-
/// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.ExtraLarge"/> size UI.
152-
/// </summary>
153-
public double ExtraLargeMinSize { get; set; } = 1400;
154-
155140
/// <summary>
156141
/// Gets or sets the width of the secondary panels.
157142
/// </summary>
@@ -194,7 +179,10 @@ public float PrimaryPanelWidth
194179
/// </remarks>
195180
public bool IsRightOpen => FlowDirection == FlowDirection.LeftToRight ? _tracker.Position.X > 0 : _tracker.Position.X < 0;
196181

197-
private SideDrawerSize Size
182+
/// <summary>
183+
/// Gets or sets the behavioral size of the side drawer control.
184+
/// </summary>
185+
public SideDrawerSize Size
198186
{
199187
get => (SideDrawerSize)GetValue(SizeProperty);
200188
set => SetValue(SizeProperty, value);
@@ -303,6 +291,11 @@ private void SetupComposition()
303291
_rightVisual.StartAnimation(TranslationX, _rightTranslateAnimation);
304292

305293
SetSnapPoints(-TotalPanelWidth, 0, SecondaryPanelWidth);
294+
295+
// Invoke size update
296+
var cache = Size;
297+
Size = SideDrawerSize.Small;
298+
Size = cache;
306299
}
307300

308301
private void SetupAnimations()
@@ -340,26 +333,6 @@ private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
340333
}
341334
}
342335

343-
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
344-
{
345-
SideDrawerSize size = SideDrawerSize.ExtraLarge;
346-
double width = e.NewSize.Width;
347-
if (width < MediumMinSize)
348-
{
349-
size = SideDrawerSize.Small;
350-
}
351-
else if (width < LargeMinSize)
352-
{
353-
size = SideDrawerSize.Medium;
354-
}
355-
else if (width < ExtraLargeMinSize)
356-
{
357-
size = SideDrawerSize.Large;
358-
}
359-
360-
Size = size;
361-
}
362-
363336
private async void SetSizeSmall(SideDrawerSize previous)
364337
{
365338
main.Margin = new Thickness(0, 0, 0, 0);
@@ -545,28 +518,21 @@ private static void OnSizePropertyChanged(DependencyObject d, DependencyProperty
545518
SideDrawerSize newSize = (SideDrawerSize)args.NewValue;
546519
SideDrawerSize oldSize = (SideDrawerSize)args.OldValue;
547520

548-
if (newSize == oldSize)
549-
{
550-
return;
551-
}
521+
if (!sideDrawer.IsLoaded) return;
522+
if (newSize == oldSize) return;
552523

553524
sideDrawer.TrackerTranslate(0);
554525

555-
switch (newSize)
526+
Action<SideDrawerSize> adjustment = newSize switch
556527
{
557-
case SideDrawerSize.Small:
558-
sideDrawer.SetSizeSmall(oldSize);
559-
break;
560-
case SideDrawerSize.Medium:
561-
sideDrawer.SetSizeMedium(oldSize);
562-
break;
563-
case SideDrawerSize.Large:
564-
sideDrawer.SetSizeLarge(oldSize);
565-
break;
566-
case SideDrawerSize.ExtraLarge:
567-
sideDrawer.SetSizeExtraLarge(oldSize);
568-
break;
569-
}
528+
SideDrawerSize.Small => sideDrawer.SetSizeSmall,
529+
SideDrawerSize.Medium => sideDrawer.SetSizeMedium,
530+
SideDrawerSize.Large => sideDrawer.SetSizeLarge,
531+
SideDrawerSize.ExtraLarge => sideDrawer.SetSizeExtraLarge,
532+
_ => sideDrawer.SetSizeSmall,
533+
};
534+
535+
adjustment?.Invoke(oldSize);
570536

571537
// Adjust tracker bounds for right to left flow direction
572538
if (sideDrawer.FlowDirection == FlowDirection.RightToLeft)

0 commit comments

Comments
 (0)