(GUI): added slider widget to settings window.

This commit is contained in:
morkt 2018-04-13 19:48:48 +04:00
parent 12bff91ba2
commit 5c3abe63c0
2 changed files with 24 additions and 1 deletions

View File

@ -46,7 +46,18 @@ IN THE SOFTWARE.
<CheckBox DataContext="{TemplateBinding DataContext}" IsChecked="{Binding Value}"
Content="{Binding Text}" ToolTip="{Binding Description}" Margin="2"/>
</ControlTemplate>
<TextBlock x:Key="FormatsPanel" Text="Not much settings implemented so far."/>
<ControlTemplate x:Key="BoundSlider" TargetType="Slider">
<StackPanel Orientation="Vertical" Margin="2" DataContext="{TemplateBinding DataContext}">
<TextBlock Text="{Binding Text}" ToolTip="{Binding Description}" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<StackPanel Orientation="Horizontal" Margin="0,2,0,0" VerticalAlignment="Center">
<Slider Orientation="Horizontal" IsSnapToTickEnabled="True" Width="120" x:Name="GaugeSlider"
TickPlacement="BottomRight" Ticks="{TemplateBinding Ticks}"
Minimum="{Binding Path=Source.Min}" Maximum="{Binding Path=Source.Max}"
Value="{Binding Value}"/>
<TextBlock Text="{Binding ElementName=GaugeSlider,Path=Value}" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Margin="2,0,0,0"/>
</StackPanel>
</StackPanel>
</ControlTemplate>
<Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton">
<Setter Property="Focusable" Value="False"/>

View File

@ -32,6 +32,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using GameRes;
using GARbro.GUI.Properties;
using GARbro.GUI.Strings;
@ -181,8 +182,19 @@ namespace GARbro.GUI
return container;
}
UIElement CreateGaugeWidget (FixedGaugeSetting setting)
{
return new Slider {
Template = (ControlTemplate)this.Resources["BoundSlider"],
DataContext = CreateSettingView<int> (setting),
Ticks = new DoubleCollection (setting.ValuesSet.Select (x => (double)x)),
};
}
UIElement CreateSettingWidget<TUnknown> (IResourceSetting setting, TUnknown value)
{
if (setting is FixedGaugeSetting)
return CreateGaugeWidget (setting as FixedGaugeSetting);
if (value is bool)
return CreateCheckBoxWidget (setting);
if (value is Encoding)