Create EquationTextBox control (#547)
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "Controls/CalculatorButton.h"
|
||||
#include "Controls/CalculationResult.h"
|
||||
#include "Controls/OverflowTextBlock.h"
|
||||
#include "Controls/EquationTextBox.h"
|
||||
#include "CalcViewModel/HistoryViewModel.h"
|
||||
#include "Views/CalculatorProgrammerDisplayPanel.xaml.h"
|
||||
#include "Views/CalculatorProgrammerOperators.xaml.h"
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<UserControl x:Class="CalculatorApp.EquationInputArea"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:CalculatorApp.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:CalculatorApp.ViewModel"
|
||||
@@ -11,76 +12,71 @@
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Margin="0,0,17,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock x:Uid="EquationInputAreaHeader"
|
||||
Grid.Column="0"
|
||||
Style="{ThemeResource SubheaderTextBlockStyle}"
|
||||
FontSize="20"/>
|
||||
|
||||
<Button Grid.Column="1"
|
||||
Click="AddEquationButton_Click"
|
||||
Content="+"/>
|
||||
</Grid>
|
||||
|
||||
<ListView x:Name="EquationInputList"
|
||||
Grid.Row="2"
|
||||
Margin="0,4,0,0"
|
||||
Grid.Row="0"
|
||||
Margin="0,8,0,0"
|
||||
IsItemClickEnabled="False"
|
||||
ItemsSource="{x:Bind Equations}"
|
||||
SelectionMode="None">
|
||||
|
||||
<ListView.Resources>
|
||||
<x:Double x:Key="ItemHeight">40</x:Double>
|
||||
</ListView.Resources>
|
||||
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="IsTabStop" Value="False"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Margin" Value="0,0,17,1"/>
|
||||
<Setter Property="Margin" Value="0,0,0,2"/>
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:EquationViewModel">
|
||||
<Grid Height="{StaticResource ItemHeight}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.Resources>
|
||||
<SolidColorBrush x:Key="LineColorBrush" Color="{x:Bind LineColor, Mode=OneWay}"/>
|
||||
</Grid.Resources>
|
||||
<Grid.Background>
|
||||
<StaticResource ResourceKey="LineColorBrush"/>
|
||||
</Grid.Background>
|
||||
|
||||
<Button Width="{StaticResource ItemHeight}"
|
||||
Height="{StaticResource ItemHeight}"
|
||||
Background="{StaticResource LineColorBrush}"/>
|
||||
<controls:EquationTextBox x:Uid="EquationInputButton"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,3,0"
|
||||
Style="{StaticResource EquationTextBoxStyle}"
|
||||
GotFocus="InputTextBox_GotFocus"
|
||||
KeyUp="InputTextBox_KeyUp"
|
||||
LostFocus="InputTextBox_LostFocus"
|
||||
RemoveButtonClicked="EquationTextBox_RemoveButtonClicked">
|
||||
<controls:EquationTextBox.EquationColor>
|
||||
<SolidColorBrush x:Name="EquationLineColor" Color="{x:Bind LineColor, Mode=OneWay}"/>
|
||||
</controls:EquationTextBox.EquationColor>
|
||||
<controls:EquationTextBox.KeyGraphFeaturesContent>
|
||||
<StackPanel x:Name="KeyGraphFeaturesGrid" Visibility="{x:Bind KeyGraphFeaturesVisibility, Mode=OneWay}">
|
||||
<TextBlock Text="Key Graph Features"/>
|
||||
<TextBlock Text="{x:Bind Expression, Mode=OneWay}"/>
|
||||
</StackPanel>
|
||||
</controls:EquationTextBox.KeyGraphFeaturesContent>
|
||||
<controls:EquationTextBox.ColorChooserFlyout>
|
||||
<Flyout x:Name="ColorChooserFlyout"
|
||||
x:Uid="ColorChooserFlyout"
|
||||
Placement="Bottom">
|
||||
<StackPanel>
|
||||
<ColorPicker x:Name="EquationColorPicker" Color="{x:Bind LineColor, Mode=TwoWay}"/>
|
||||
</StackPanel>
|
||||
</Flyout>
|
||||
</controls:EquationTextBox.ColorChooserFlyout>
|
||||
</controls:EquationTextBox>
|
||||
|
||||
<Rectangle x:Name="InputBackplate"
|
||||
Grid.Column="1"
|
||||
Margin="0,2,3,2"
|
||||
Fill="White"/>
|
||||
|
||||
<TextBox Grid.Column="1"
|
||||
Margin="0,2,3,2"
|
||||
GotFocus="InputTextBox_GotFocus"
|
||||
KeyUp="InputTextBox_KeyUp"
|
||||
LostFocus="InputTextBox_LostFocus"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
<Button Grid.Row="1"
|
||||
Margin="4"
|
||||
Click="AddEquationButton_Click"
|
||||
Content="+"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@@ -1,10 +1,12 @@
|
||||
#include "pch.h"
|
||||
#include "EquationInputArea.xaml.h"
|
||||
#include "CalcViewModel/Common/KeyboardShortcutManager.h"
|
||||
#include "Controls/EquationTextBox.h"
|
||||
|
||||
using namespace CalculatorApp;
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace CalculatorApp::ViewModel;
|
||||
using namespace CalculatorApp::Controls;
|
||||
using namespace Platform;
|
||||
using namespace std;
|
||||
using namespace Windows::System;
|
||||
@@ -12,6 +14,7 @@ using namespace Windows::UI;
|
||||
using namespace Windows::UI::ViewManagement;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::UI::Xaml::Controls::Primitives;
|
||||
using namespace Windows::UI::Xaml::Input;
|
||||
|
||||
namespace
|
||||
@@ -51,13 +54,6 @@ void EquationInputArea::OnEquationsPropertyChanged()
|
||||
if (Equations != nullptr && Equations->Size == 0)
|
||||
{
|
||||
AddNewEquation();
|
||||
|
||||
// For now, the first equation needs to be y = 0.
|
||||
// We can remove this when we can create empty graphs.
|
||||
if (EquationViewModel^ eqvm = Equations->GetAt(0))
|
||||
{
|
||||
eqvm->Expression = L"0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +68,6 @@ void EquationInputArea::AddNewEquation()
|
||||
eq->LineColor = GetNextLineColor();
|
||||
|
||||
Equations->Append(eq);
|
||||
EquationInputList->ScrollIntoView(eq);
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_GotFocus(Object^ sender, RoutedEventArgs^ e)
|
||||
@@ -84,18 +79,18 @@ void EquationInputArea::InputTextBox_LostFocus(Object^ sender, RoutedEventArgs^
|
||||
{
|
||||
KeyboardShortcutManager::HonorShortcuts(true);
|
||||
|
||||
auto tb = static_cast<TextBox^>(sender);
|
||||
auto tb = static_cast<EquationTextBox^>(sender);
|
||||
auto eq = static_cast<EquationViewModel^>(tb->DataContext);
|
||||
tb->Text = eq->Expression;
|
||||
tb->SetEquationText(eq->Expression);
|
||||
}
|
||||
|
||||
void EquationInputArea::InputTextBox_KeyUp(Object^ sender, KeyRoutedEventArgs^ e)
|
||||
{
|
||||
if (e->Key == VirtualKey::Enter)
|
||||
{
|
||||
auto tb = static_cast<TextBox^>(sender);
|
||||
auto tb = static_cast<EquationTextBox^>(sender);
|
||||
auto eq = static_cast<EquationViewModel^>(tb->DataContext);
|
||||
eq->Expression = tb->Text;
|
||||
eq->Expression = tb->GetEquationText();
|
||||
|
||||
e->Handled = true;
|
||||
}
|
||||
@@ -106,3 +101,15 @@ Color EquationInputArea::GetNextLineColor()
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % lineColorsSize;
|
||||
return lineColors[m_lastLineColorIndex];
|
||||
}
|
||||
|
||||
|
||||
void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object^ sender, RoutedEventArgs^ e)
|
||||
{
|
||||
auto tb = static_cast<EquationTextBox^>(sender);
|
||||
auto eq = static_cast<EquationViewModel^>(tb->DataContext);
|
||||
unsigned int index;
|
||||
if (Equations->IndexOf(eq, &index))
|
||||
{
|
||||
Equations->RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
@@ -29,5 +29,6 @@ namespace CalculatorApp
|
||||
|
||||
private:
|
||||
int m_lastLineColorIndex;
|
||||
void EquationTextBox_RemoveButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
};
|
||||
}
|
||||
|
@@ -43,10 +43,10 @@
|
||||
|
||||
<!-- Right portion of the screen -->
|
||||
<Grid x:Name="RightGrid"
|
||||
Grid.Row="0"
|
||||
Grid.Row="1"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="4,0,4,0">
|
||||
Margin="0,0,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="5*"/>
|
||||
<RowDefinition Height="3*"/>
|
||||
|
Reference in New Issue
Block a user