Skip to content

Commit 51326b0

Browse files
committed
replace volume dropdown with selector
1 parent da35519 commit 51326b0

3 files changed

Lines changed: 142 additions & 17 deletions

File tree

SettingsWindow.xaml

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,59 @@
7474
</DataTrigger>
7575
</Style.Triggers>
7676
</Style>
77+
<SolidColorBrush x:Key="VolumeSelectedBackgroundBrush"
78+
Color="{DynamicResource ControlStrongFillColorDefault}"
79+
Opacity="0.22" />
80+
<SolidColorBrush x:Key="VolumeHoverBackgroundBrush"
81+
Color="{DynamicResource ControlStrongFillColorDefault}"
82+
Opacity="0.12" />
83+
<SolidColorBrush x:Key="VolumeStrokeBrush"
84+
Color="{DynamicResource ControlStrongFillColorDefault}"
85+
Opacity="0.35" />
86+
<Style x:Key="VolumeChoiceStyle" TargetType="RadioButton">
87+
<Setter Property="Height" Value="28" />
88+
<Setter Property="Background" Value="Transparent" />
89+
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
90+
<Setter Property="HorizontalContentAlignment" Value="Center" />
91+
<Style.Triggers>
92+
<Trigger Property="IsMouseOver" Value="True">
93+
<Setter Property="Background" Value="{StaticResource VolumeHoverBackgroundBrush}" />
94+
</Trigger>
95+
<Trigger Property="IsChecked" Value="True">
96+
<Setter Property="Background" Value="{StaticResource VolumeSelectedBackgroundBrush}" />
97+
</Trigger>
98+
</Style.Triggers>
99+
</Style>
100+
<Style x:Key="LeftVolumeChoiceStyle"
101+
TargetType="RadioButton"
102+
BasedOn="{StaticResource VolumeChoiceStyle}">
103+
<Setter Property="Template">
104+
<Setter.Value>
105+
<ControlTemplate TargetType="RadioButton">
106+
<Border Background="{TemplateBinding Background}"
107+
CornerRadius="3,0,0,3">
108+
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
109+
VerticalAlignment="Center" />
110+
</Border>
111+
</ControlTemplate>
112+
</Setter.Value>
113+
</Setter>
114+
</Style>
115+
<Style x:Key="RightVolumeChoiceStyle"
116+
TargetType="RadioButton"
117+
BasedOn="{StaticResource VolumeChoiceStyle}">
118+
<Setter Property="Template">
119+
<Setter.Value>
120+
<ControlTemplate TargetType="RadioButton">
121+
<Border Background="{TemplateBinding Background}"
122+
CornerRadius="0,3,3,0">
123+
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
124+
VerticalAlignment="Center" />
125+
</Border>
126+
</ControlTemplate>
127+
</Setter.Value>
128+
</Setter>
129+
</Style>
77130
</Window.Resources>
78131
<Border Padding="12"
79132
Background="Transparent"
@@ -180,20 +233,9 @@
180233
</ToggleButton.ContextMenu>
181234
</ToggleButton>
182235

183-
<TextBlock Grid.Row="2" Text="Volume control" VerticalAlignment="Center" Margin="0,0,8,12" />
184-
<ComboBox x:Name="ScrollVolumeComboBox"
185-
Grid.Row="2"
186-
Grid.Column="1"
187-
Margin="0,0,0,12"
188-
AutomationProperties.Name="Volume control"
189-
SelectionChanged="Input_Changed">
190-
<ComboBoxItem Content="Current app" />
191-
<ComboBoxItem Content="System volume" />
192-
</ComboBox>
193-
194-
<TextBlock Grid.Row="3" Text="Show app icons" VerticalAlignment="Center" Margin="0,0,8,12" />
236+
<TextBlock Grid.Row="2" Text="Show app icons" VerticalAlignment="Center" Margin="0,0,8,12" />
195237
<ComboBox x:Name="AppIconModeComboBox"
196-
Grid.Row="3"
238+
Grid.Row="2"
197239
Grid.Column="1"
198240
Margin="0,0,0,12"
199241
AutomationProperties.Name="Show app icons"
@@ -203,6 +245,35 @@
203245
<ComboBoxItem Content="Multiple sources" />
204246
</ComboBox>
205247

248+
<TextBlock Grid.Row="3" Text="Volume control" VerticalAlignment="Center" Margin="0,0,8,12" />
249+
<Border Grid.Row="3"
250+
Grid.Column="1"
251+
Margin="0,0,0,12"
252+
BorderBrush="{StaticResource VolumeStrokeBrush}"
253+
BorderThickness="1"
254+
CornerRadius="4">
255+
<Grid>
256+
<Grid.ColumnDefinitions>
257+
<ColumnDefinition Width="*" />
258+
<ColumnDefinition Width="1" />
259+
<ColumnDefinition Width="*" />
260+
</Grid.ColumnDefinitions>
261+
<RadioButton x:Name="VolumeCurrentAppRadio"
262+
Content="Current app"
263+
Style="{StaticResource LeftVolumeChoiceStyle}"
264+
AutomationProperties.Name="Current app volume"
265+
Checked="VolumeTarget_Checked" />
266+
<Border Grid.Column="1"
267+
Background="{StaticResource VolumeStrokeBrush}" />
268+
<RadioButton x:Name="VolumeSystemVolumeRadio"
269+
Grid.Column="2"
270+
Content="System"
271+
Style="{StaticResource RightVolumeChoiceStyle}"
272+
AutomationProperties.Name="System volume"
273+
Checked="VolumeTarget_Checked" />
274+
</Grid>
275+
</Border>
276+
206277
<TextBlock Grid.Row="4" Text="Player size" VerticalAlignment="Center" Margin="0,0,8,0" />
207278
<Grid Grid.Row="4" Grid.Column="1">
208279
<Grid.ColumnDefinitions>

SettingsWindow.xaml.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ private void LoadConfig()
3838
AppIconModeComboBox.SelectedIndex = !_config.ShowIcon
3939
? 1
4040
: _config.ShowIconOnlyWithMultipleSources ? 2 : 0;
41-
ScrollVolumeComboBox.SelectedIndex = _config.ScrollVolumeTarget == VolumeScrollTarget.WindowsMaster ? 1 : 0;
41+
var volumeTargetButton = _config.ScrollVolumeTarget == VolumeScrollTarget.WindowsMaster
42+
? VolumeSystemVolumeRadio
43+
: VolumeCurrentAppRadio;
44+
volumeTargetButton.IsChecked = true;
4245
ShowPreviousButtonMenuItem.IsChecked = _config.ShowPreviousButton;
4346
ShowPlayPauseButtonMenuItem.IsChecked = _config.ShowPlayPauseButton;
4447
ShowNextButtonMenuItem.IsChecked = _config.ShowNextButton;
@@ -194,6 +197,19 @@ private void Input_Changed(object sender, RoutedEventArgs e)
194197
SaveChanges();
195198
}
196199

200+
private void VolumeTarget_Checked(object sender, RoutedEventArgs e)
201+
{
202+
if (_loading)
203+
{
204+
return;
205+
}
206+
207+
_config.ScrollVolumeTarget = sender == VolumeSystemVolumeRadio
208+
? VolumeScrollTarget.WindowsMaster
209+
: VolumeScrollTarget.CurrentApp;
210+
SaveChanges();
211+
}
212+
197213
private void ScaleSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
198214
{
199215
UpdateScaleText();
@@ -286,9 +302,6 @@ private bool TryReadConfig()
286302
_config.ButtonIconColor = buttonIconColor;
287303
_config.ShowIcon = AppIconModeComboBox.SelectedIndex != 1;
288304
_config.ShowIconOnlyWithMultipleSources = AppIconModeComboBox.SelectedIndex == 2;
289-
_config.ScrollVolumeTarget = ScrollVolumeComboBox.SelectedIndex == 1
290-
? VolumeScrollTarget.WindowsMaster
291-
: VolumeScrollTarget.CurrentApp;
292305
var launchAtStartup = StartupCheckBox.IsChecked == true;
293306
if (launchAtStartup != _config.LaunchAtStartup)
294307
{

WPlayer.Tests/SettingsWindowTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,47 @@ public void AppIconModesLoadAndSaveInDisplayOrder()
7676
});
7777
}
7878

79+
[TestMethod]
80+
public void VolumeTargetButtonsLoadAndSave()
81+
{
82+
StaTest.Run(() =>
83+
{
84+
var saveCount = 0;
85+
var config = new AppConfig { ScrollVolumeTarget = VolumeScrollTarget.WindowsMaster };
86+
var settings = new SettingsWindow(config, () =>
87+
{
88+
saveCount++;
89+
return true;
90+
});
91+
try
92+
{
93+
var currentButton = (RadioButton)settings.FindName("VolumeCurrentAppRadio");
94+
var systemButton = (RadioButton)settings.FindName("VolumeSystemVolumeRadio");
95+
96+
Assert.IsTrue(systemButton.IsChecked);
97+
Assert.IsFalse(currentButton.IsChecked);
98+
99+
currentButton.IsChecked = true;
100+
101+
Assert.AreEqual(VolumeScrollTarget.CurrentApp, config.ScrollVolumeTarget);
102+
Assert.IsTrue(currentButton.IsChecked);
103+
Assert.IsFalse(systemButton.IsChecked);
104+
Assert.AreEqual(1, saveCount);
105+
106+
systemButton.IsChecked = true;
107+
108+
Assert.AreEqual(VolumeScrollTarget.WindowsMaster, config.ScrollVolumeTarget);
109+
Assert.IsTrue(systemButton.IsChecked);
110+
Assert.IsFalse(currentButton.IsChecked);
111+
Assert.AreEqual(2, saveCount);
112+
}
113+
finally
114+
{
115+
settings.Close();
116+
}
117+
});
118+
}
119+
79120
[TestMethod]
80121
public void ColorResetButtonAppearsAfterBlur()
81122
{

0 commit comments

Comments
 (0)