Skip to content

Commit

Permalink
Added Number Properties UI (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Aug 9, 2023
1 parent cb202f2 commit 7ff3979
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Datalya/UserControls/NumberBlockPropertiesUI.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<UserControl x:Class="Datalya.UserControls.NumberBlockPropertiesUI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Datalya.UserControls"
xmlns:lang="clr-namespace:Datalya.Properties" FontFamily="..\Fonts\#Hauora" Foreground="{Binding Source={StaticResource Foreground1}}" mc:Ignorable="d" Height="450" Width="300">
<Grid d:Background="#fff">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Text="&#xF57E;" FontFamily="..\Fonts\#FluentSYstemIcons-Regular" Margin="0 0 10 0" FontSize="24" VerticalAlignment="Center" />
<TextBlock Text="{x:Static lang:Resources.NumberInput}" FontWeight="ExtraBold" FontSize="16" VerticalAlignment="Center" />
</StackPanel>

<TextBlock Text="{x:Static lang:Resources.Name}" FontWeight="ExtraBold" Margin="10,0,0,0" />
<TextBox x:Name="NameTxt" Style="{DynamicResource RegularTextBoxStyle}" Padding="7" Margin="10,5,10,15" BorderThickness="0" Background="{Binding Source={StaticResource Background2}}" Foreground="{Binding Source={StaticResource Foreground1}}" Text="{x:Static lang:Resources.NumberInput}" FontWeight="ExtraBold" TextAlignment="Center" />

<CheckBox x:Name="UseRangeChk" Margin="10 0" Content="{x:Static lang:Resources.SpecificRange}" Style="{DynamicResource CheckBoxStyle1}" BorderThickness="2" VerticalContentAlignment="Center" FontWeight="SemiBold" Checked="UseRangeChk_Checked" Unchecked="UseRangeChk_Unchecked"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Static lang:Resources.Min}" FontWeight="ExtraBold" Margin="10,0,0,0" VerticalAlignment="Center" />
<TextBox x:Name="MinTxt" Style="{DynamicResource RegularTextBoxStyle}" Padding="2" Margin="5" BorderThickness="0" Background="{Binding Source={StaticResource Background2}}" Foreground="{Binding Source={StaticResource Foreground1}}" d:Text="0" Width="50" FontWeight="ExtraBold" TextAlignment="Center" />
<TextBlock Text="{x:Static lang:Resources.Max}" FontWeight="ExtraBold" Margin="10,0,0,0" VerticalAlignment="Center" />
<TextBox x:Name="MaxTxt" Style="{DynamicResource RegularTextBoxStyle}" Padding="2" Margin="5" BorderThickness="0" Background="{Binding Source={StaticResource Background2}}" Foreground="{Binding Source={StaticResource Foreground1}}" d:Text="0" Width="50" FontWeight="ExtraBold" TextAlignment="Center" />
</StackPanel>
<CheckBox IsEnabled="False" x:Name="UseDropDownChk" Margin="10 0" Content="{x:Static lang:Resources.UseComboBox}" Style="{DynamicResource CheckBoxStyle1}" BorderThickness="2" VerticalContentAlignment="Center" FontWeight="SemiBold"/>
</StackPanel>

<Button x:Name="SaveBtn" Grid.Row="1" Click="SaveBtn_Click" Padding="5" Margin="10" HorizontalAlignment="Center" Style="{DynamicResource TabButtonStyle}" Background="{Binding Source={StaticResource AccentColor}}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" BorderThickness="0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<TextBlock Text="&#xF680;" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Margin="0,0,10,0" VerticalAlignment="Center" />
<TextBlock Text="{x:Static lang:Resources.Save}" FontWeight="ExtraBold" VerticalAlignment="Center" />
</StackPanel>
</Button>
</Grid>
</UserControl>
88 changes: 88 additions & 0 deletions Datalya/UserControls/NumberBlockPropertiesUI.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using Datalya.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Datalya.UserControls;
/// <summary>
/// Interaction logic for NumberBlockPropertiesUI.xaml
/// </summary>
public partial class NumberBlockPropertiesUI : UserControl
{
NumberBlockCreatorUI ParentElement { get; set; }
NumberBlock NumberBlock { get; set; }
public NumberBlockPropertiesUI(NumberBlockCreatorUI numberBlockCreatorUI, NumberBlock numberBlock)
{
InitializeComponent();
ParentElement = numberBlockCreatorUI;
NumberBlock = numberBlock;
if (numberBlock is not null)
{
NameTxt.Text = numberBlock.Name;
UseDropDownChk.IsChecked = numberBlock.UseComboBox;
UseDropDownChk.IsEnabled = numberBlock.UseRange;
UseRangeChk.IsChecked = numberBlock.UseRange;
MinTxt.Text = numberBlock.Range.HasValue ? numberBlock.Range.Value.Item1.ToString() : "";
MaxTxt.Text = numberBlock.Range.HasValue ? numberBlock.Range.Value.Item2.ToString() : "";
}
}

private void SaveBtn_Click(object sender, RoutedEventArgs e)
{
bool minOk = int.TryParse(MinTxt.Text, out int min);
bool maxOk = int.TryParse(MaxTxt.Text, out int max);

if ((UseRangeChk.IsChecked ?? false) && (!minOk || !maxOk)) return;
if (!string.IsNullOrEmpty(NameTxt.Text) && !string.IsNullOrWhiteSpace(NameTxt.Text))
{
NumberBlock = new() { Name = NameTxt.Text, UseComboBox = UseDropDownChk.IsChecked ?? false, UseRange = UseRangeChk.IsChecked ?? false, Range = (UseRangeChk.IsChecked ?? false) ? (Math.Min(min, max), Math.Max(min, max)) : null };
ParentElement.NameTxt.Text = NumberBlock.Name; // Set name
ParentElement.NumberBlock = NumberBlock; // Set
Global.CreatorPage.SaveChanges(); // Save
}
}

private void UseRangeChk_Checked(object sender, RoutedEventArgs e)
{
UseDropDownChk.IsEnabled = true;
}

private void UseRangeChk_Unchecked(object sender, RoutedEventArgs e)
{
UseDropDownChk.IsEnabled = false;
}
}

0 comments on commit 7ff3979

Please sign in to comment.