Skip to content

Commit

Permalink
SOO MANY CHANGES
Browse files Browse the repository at this point in the history
  • Loading branch information
itzbluebxrry committed Nov 5, 2023
1 parent 0f1be45 commit cdd1ac8
Show file tree
Hide file tree
Showing 48 changed files with 9,988 additions and 691 deletions.
219 changes: 219 additions & 0 deletions CubeKit.UI/Controls/Settings/Converters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

#nullable enable

namespace CubeKit.UI.Controls.Settings
{
/// <summary>
/// The generic base implementation of a value converter.
/// </summary>
/// <typeparam name="TSource">The source type.</typeparam>
/// <typeparam name="TTarget">The target type.</typeparam>
public abstract class ValueConverter<TSource, TTarget>
: IValueConverter
{
/// <summary>
/// Converts a source value to the target type.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public TTarget? Convert(TSource? value)
{
return Convert(value, null, null);
}

/// <summary>
/// Converts a target value back to the source type.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public TSource? ConvertBack(TTarget? value)
{
return ConvertBack(value, null, null);
}

/// <summary>
/// Modifies the source data before passing it to the target for display in the UI.
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
public object? Convert(object? value, Type? targetType, object? parameter, string? language)
{
// CastExceptions will occur when invalid value, or target type provided.
return Convert((TSource?)value, parameter, language);
}

/// <summary>
/// Modifies the target data before passing it to the source object. This method is called only in TwoWay bindings.
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
public object? ConvertBack(object? value, Type? targetType, object? parameter, string? language)
{
// CastExceptions will occur when invalid value, or target type provided.
return ConvertBack((TTarget?)value, parameter, language);
}

/// <summary>
/// Converts a source value to the target type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected virtual TTarget? Convert(TSource? value, object? parameter, string? language)
{
throw new NotSupportedException();
}

/// <summary>
/// Converts a target value back to the source type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected virtual TSource? ConvertBack(TTarget? value, object? parameter, string? language)
{
throw new NotSupportedException();
}
}

/// <summary>
/// The base class for converting instances of type T to object and vice versa.
/// </summary>
public abstract class ToObjectConverter<T>
: ValueConverter<T?, object?>
{
/// <summary>
/// Converts a source value to the target type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override object? Convert(T? value, object? parameter, string? language)
{
return value;
}

/// <summary>
/// Converts a target value back to the source type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override T? ConvertBack(object? value, object? parameter, string? language)
{
return (T?)value;
}
}

/// <summary>
/// Converts a boolean to and from a visibility value.
/// </summary>
public class InverseBooleanConverter
: ValueConverter<bool, bool>
{
/// <summary>
/// Converts a source value to the target type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override bool Convert(bool value, object? parameter, string? language)
{
return !value;
}

/// <summary>
/// Converts a target value back to the source type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override bool ConvertBack(bool value, object? parameter, string? language)
{
return !value;
}
}

public class NullToTrueConverter
: ValueConverter<object?, bool>
{
/// <summary>
/// Determines whether an inverse conversion should take place.
/// </summary>
/// <remarks>If set, the value True results in <see cref="Visibility.Collapsed"/>, and false in <see cref="Visibility.Visible"/>.</remarks>
public bool Inverse { get; set; }

/// <summary>
/// Converts a source value to the target type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override bool Convert(object? value, object? parameter, string? language)
{
return Inverse ? value != null : value == null;
}

/// <summary>
/// Converts a target value back to the source type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override object? ConvertBack(bool value, object? parameter, string? language)
{
return null;
}
}

public class StringNullOrWhiteSpaceToTrueConverter
: ValueConverter<string, bool>
{
/// <summary>
/// Determines whether an inverse conversion should take place.
/// </summary>
/// <remarks>If set, the value True results in <see cref="Visibility.Collapsed"/>, and false in <see cref="Visibility.Visible"/>.</remarks>
public bool Inverse { get; set; }

/// <summary>
/// Converts a source value to the target type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override bool Convert(string? value, object? parameter, string? language)
{
return Inverse ? !string.IsNullOrWhiteSpace(value) : string.IsNullOrWhiteSpace(value);
}

/// <summary>
/// Converts a target value back to the source type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override string ConvertBack(bool value, object? parameter, string? language)
{
return string.Empty;
}
}
}
90 changes: 90 additions & 0 deletions CubeKit.UI/Controls/Settings/SettingsBlockControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<UserControl
x:Class="CubeKit.UI.Controls.Settings.SettingsBlockControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CubeKit.UI.Controls.Settings"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<UserControl.Resources>
<local:InverseBooleanConverter x:Key="InverseBooleanConverter" />
<local:NullToTrueConverter x:Key="NullToFalseConverter" Inverse="True" />
<local:NullToTrueConverter x:Key="NullToTrueConverter" Inverse="False" />
<local:StringNullOrWhiteSpaceToTrueConverter x:Key="StringNullOrWhiteSpaceToFalseConverter" Inverse="True" />
<local:StringNullOrWhiteSpaceToTrueConverter x:Key="StringNullOrWhiteSpaceToTrueConverter" Inverse="False" />

<Style x:Key="TextBlockGroupHeaderStyle" TargetType="TextBlock">
<Setter Property="Margin" Value="0,8,0,4" />
<Setter Property="FontSize" Value="16" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="FontWeight" Value="Bold" />
</Style>

<Style x:Key="GridSettingsBlockStyle" TargetType="Grid">
<Setter Property="Background" Value="{ThemeResource ExpanderHeaderBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="{StaticResource ExpanderMinHeight}" />
<Setter Property="Padding" Value="{StaticResource ExpanderContentPadding}" />
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
</Style>

<Style x:Key="ButtonSettingsBlockStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
<Setter Property="Background" Value="{ThemeResource ExpanderHeaderBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="{StaticResource ExpanderContentPadding}" />
<Setter Property="MinHeight" Value="{StaticResource ExpanderMinHeight}" />
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
</Style>
</UserControl.Resources>

<Grid>
<!-- Expander -->
<Grid x:Name="ExpanderPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToFalseConverter}}">
<Grid x:Name="ExpanderGrid" x:Load="{x:Bind IsClickable, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}">
<muxc:Expander HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Expanding="Expander_Expanding" Collapsed="Expander_Collapsed">
<muxc:Expander.Header>
<local:SettingsDisplayControl Icon="{x:Bind Icon, Mode=OneWay}"
Margin="0,16"
AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}"
Title="{x:Bind Title, Mode=OneWay}"
Description="{x:Bind Description, Mode=OneWay}"
SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}"/>
</muxc:Expander.Header>

<ContentPresenter Margin="-16" HorizontalAlignment="Stretch" Content="{x:Bind ExpandableContent, Mode=OneWay}" />
</muxc:Expander>
</Grid>
</Grid>
<!-- Button -->
<Grid x:Name="ButtonPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToTrueConverter}}">
<Grid x:Name="ButtonGrid" x:Load="{x:Bind IsClickable, Mode=OneWay}">
<Button x:Name="ActionableButton" Style="{StaticResource ButtonSettingsBlockStyle}" Click="ActionableButton_Click">
<local:SettingsDisplayControl Icon="{x:Bind Icon, Mode=OneWay}"
AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}"
Title="{x:Bind Title, Mode=OneWay}"
Description="{x:Bind Description, Mode=OneWay}"
SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}"/>
</Button>
</Grid>
</Grid>
<!-- Grid -->
<Grid x:Name="StaticPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToTrueConverter}}">
<Grid x:Name="StaticGrid" x:Load="{x:Bind IsClickable, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}" Style="{StaticResource GridSettingsBlockStyle}">
<local:SettingsDisplayControl Icon="{x:Bind Icon, Mode=OneWay}"
AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}"
Title="{x:Bind Title, Mode=OneWay}"
Description="{x:Bind Description, Mode=OneWay}"
SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}"/>
</Grid>
</Grid>
</Grid>
</UserControl>
Loading

0 comments on commit cdd1ac8

Please sign in to comment.