Allow line style to be changed (#1097)

* add line style

* start line style

* More fixes

* undo key

* more tweaks

* address comments

* Fix merge
This commit is contained in:
Pepe Rivera 2020-03-27 09:56:11 -07:00 committed by GitHub
parent 7dcfe0439c
commit fec7c907f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 383 additions and 92 deletions

View File

@ -45,7 +45,8 @@ namespace CalculatorApp
public enum class LineStyleType
{
Color
Color,
Pattern
};
public ref class TraceLogger sealed

View File

@ -5,13 +5,13 @@
xmlns:local="using:CalculatorApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel>
<GridView x:Name="ColorChooser"
ItemsSource="{x:Bind AvailableColors}"
Loaded="ColorChooserLoaded"
SelectionChanged="SelectionChanged"
SingleSelectionFollowsFocus="False">
<GridView.ItemContainerStyle>
<GridView.Resources>
<Style TargetType="GridViewItem">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
@ -68,7 +68,7 @@
</Setter.Value>
</Setter>
</Style>
</GridView.ItemContainerStyle>
</GridView.Resources>
<GridView.Header>
<TextBlock x:Uid="LineColorText" Margin="8,0,8,8"/>
</GridView.Header>
@ -79,6 +79,7 @@
VerticalAlignment="Stretch"
Fill="{x:Bind}"
StrokeThickness="0"
AutomationProperties.Name="{x:Bind local:EquationStylePanelControl.GetColorAutomationName((Brush))}"
UseLayoutRounding="false"/>
</DataTemplate>
</GridView.ItemTemplate>
@ -88,4 +89,34 @@
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
<ComboBox x:Name="StyleChooserBox"
x:Uid="StyleChooserBox"
MinWidth="200"
Margin="8,0"
Loaded="StyleChooserBox_Loaded"
SelectedItem="{x:Bind SelectedStyle}"
SelectionChanged="StyleChooserBox_SelectionChanged"
Visibility="Visible"
IsEnabled="{x:Bind EnableLineStylePicker}">
<ComboBox.ItemTemplate>
<!-- Set x:DataType to be Platform::Object so that we can pass it to the x:Bind function directly since we cannot pass an enum in c++/cx -->
<DataTemplate x:DataType="x:Object">
<Grid x:Name="LineGrid"
Height="20"
MaxWidth="200"
AutomationProperties.Name="{x:Bind local:EquationStylePanelControl.GetLineAutomationName((x:Object))}">
<Line VerticalAlignment="Center"
Stroke="{ThemeResource AppControlPageTextBaseHighColorBrush}"
StrokeThickness="2.5"
StrokeDashArray="{x:Bind local:EquationStylePanelControl.GetLinePattern((x:Object))}"
X1="0"
X2="200"
Y1="4"
Y2="4"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</UserControl>

View File

@ -3,6 +3,7 @@
#include "pch.h"
#include "EquationStylePanelControl.xaml.h"
#include "CalcViewModel/Common/AppResourceProvider.h"
using namespace CalculatorApp;
@ -19,13 +20,23 @@ using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::Xaml::Shapes;
using namespace GraphControl;
DEPENDENCY_PROPERTY_INITIALIZATION(EquationStylePanelControl, SelectedColor);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationStylePanelControl, SelectedStyle);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationStylePanelControl, EnableLineStylePicker);
DEPENDENCY_PROPERTY_INITIALIZATION(EquationStylePanelControl, AvailableColors);
EquationStylePanelControl::EquationStylePanelControl()
{
InitializeComponent();
auto allStyles = ref new Vector<EquationLineStyle>();
allStyles->Append(::EquationLineStyle::Solid);
allStyles->Append(::EquationLineStyle::Dash);
allStyles->Append(::EquationLineStyle::Dot);
StyleChooserBox->ItemsSource = allStyles;
}
void EquationStylePanelControl::SelectionChanged(Object ^ /*sender */, SelectionChangedEventArgs ^ e)
@ -79,3 +90,153 @@ void EquationStylePanelControl::SelectColor(Color selectedColor)
}
}
}
void EquationStylePanelControl::OnSelectedStylePropertyChanged(EquationLineStyle oldStyle, EquationLineStyle newStyle)
{
if (oldStyle != newStyle)
{
SelectStyle(newStyle);
TraceLogger::GetInstance()->LogGraphLineStyleChanged(LineStyleType::Pattern);
}
}
void EquationStylePanelControl::SelectStyle(EquationLineStyle selectedStyle)
{
for (auto item : StyleChooserBox->Items->GetView())
{
auto style = static_cast<EquationLineStyle>(item);
auto comboBoxItem = dynamic_cast<ComboBoxItem ^>(StyleChooserBox->ContainerFromItem(style));
if (!comboBoxItem)
{
continue;
}
if (style == selectedStyle)
{
comboBoxItem->IsSelected = true;
return;
}
else
{
comboBoxItem->IsSelected = false;
}
}
}
void EquationStylePanelControl::StyleChooserBox_SelectionChanged(Object ^ sender, SelectionChangedEventArgs ^ e)
{
if (e->AddedItems->Size > 0)
{
SelectedStyle = static_cast<EquationLineStyle>(e->AddedItems->GetAt(0));
}
}
void EquationStylePanelControl::StyleChooserBox_Loaded(Object ^ sender, RoutedEventArgs ^ e)
{
SelectStyle(SelectedStyle);
}
String ^ EquationStylePanelControl::GetColorAutomationName(Brush ^ brush)
{
auto resourceLoader = AppResourceProvider::GetInstance();
auto color = static_cast<SolidColorBrush ^>(brush);
if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush1")))
{
return resourceLoader->GetResourceString("equationColor1AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush2")))
{
return resourceLoader->GetResourceString("equationColor2AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush3")))
{
return resourceLoader->GetResourceString("equationColor3AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush4")))
{
return resourceLoader->GetResourceString("equationColor4AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush5")))
{
return resourceLoader->GetResourceString("equationColor5AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush6")))
{
return resourceLoader->GetResourceString("equationColor6AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush7")))
{
return resourceLoader->GetResourceString("equationColor7AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush8")))
{
return resourceLoader->GetResourceString("equationColor8AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush9")))
{
return resourceLoader->GetResourceString("equationColor9AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush10")))
{
return resourceLoader->GetResourceString("equationColor10AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush11")))
{
return resourceLoader->GetResourceString("equationColor11AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush12")))
{
return resourceLoader->GetResourceString("equationColor12AutomationName");
}
else if (color == safe_cast<SolidColorBrush ^>(Application::Current->Resources->Lookup(L"EquationBrush13")))
{
return resourceLoader->GetResourceString("equationColor13AutomationName");
}
else
{
return resourceLoader->GetResourceString("equationColor14AutomationName");
}
}
String ^ EquationStylePanelControl::GetLineAutomationName(Object ^ line)
{
auto resourceLoader = AppResourceProvider::GetInstance();
auto lineStyle = static_cast<Box<EquationLineStyle> ^>(line)->Value;
switch (lineStyle)
{
case ::EquationLineStyle::Dot:
return resourceLoader->GetResourceString("dotLineStyleAutomationName");
break;
case ::EquationLineStyle::Dash:
return resourceLoader->GetResourceString("dashLineStyleAutomationName");
break;
case ::EquationLineStyle::Solid:
default:
return resourceLoader->GetResourceString("solidLineStyleAutomationName");
break;
}
}
DoubleCollection ^ EquationStylePanelControl::GetLinePattern(Object ^ line)
{
auto lineStyle = static_cast<Box<EquationLineStyle> ^>(line)->Value;
auto linePattern = ref new DoubleCollection();
switch (lineStyle)
{
case ::EquationLineStyle::Dot:
linePattern->Append(1);
break;
case ::EquationLineStyle::Dash:
linePattern->Append(2);
linePattern->Append(1);
break;
default:
break;
}
return linePattern;
}

View File

@ -16,7 +16,13 @@ namespace CalculatorApp
DEPENDENCY_PROPERTY_OWNER(EquationStylePanelControl);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, SelectedColor, Windows::UI::Colors::Black);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(GraphControl::EquationLineStyle, SelectedStyle, GraphControl::EquationLineStyle::Solid);
DEPENDENCY_PROPERTY_WITH_DEFAULT(Windows::Foundation::Collections::IVector<Windows::UI::Xaml::Media::SolidColorBrush ^> ^, AvailableColors, nullptr);
DEPENDENCY_PROPERTY(bool, EnableLineStylePicker);
static Windows::UI::Xaml::Media::DoubleCollection ^ GetLinePattern(Platform::Object ^ line);
static Platform::String ^ GetLineAutomationName(Platform::Object ^ line);
static Platform::String ^ GetColorAutomationName(Windows::UI::Xaml::Media::Brush ^ color);
private:
void SelectionChanged(Platform::Object ^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^ e);
@ -25,5 +31,9 @@ namespace CalculatorApp
Platform::Object ^ sender,
Windows::UI::Xaml::RoutedEventArgs ^ e);
void SelectColor(Windows::UI::Color selectedColor);
void OnSelectedStylePropertyChanged(GraphControl::EquationLineStyle oldStyle, GraphControl::EquationLineStyle newStyle);
void SelectStyle(GraphControl::EquationLineStyle selectedStyle);
void StyleChooserBox_SelectionChanged(Platform::Object ^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^ e);
void StyleChooserBox_Loaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
};
}

View File

@ -3944,9 +3944,13 @@
<comment>Label text for the max text box</comment>
</data>
<data name="LineColorText.Text" xml:space="preserve">
<value>Line Color</value>
<value>Color</value>
<comment>Label for the Line Color section of the style picker</comment>
</data>
<data name="StyleChooserBox.Header" xml:space="preserve">
<value>Style</value>
<comment>Label for the Line Style section of the style picker</comment>
</data>
<data name="KeyGraphFeaturesLabel.Text" xml:space="preserve">
<value>Function analysis</value>
<comment>Title for KeyGraphFeatures Control</comment>
@ -4462,4 +4466,72 @@
<value>Select All</value>
<comment>Select all menu item from the Equation TextBox</comment>
</data>
<data name="solidLineStyleAutomationName" xml:space="preserve">
<value>Solid line style</value>
<comment>Name of the solid line style for a graphed equation</comment>
</data>
<data name="dotLineStyleAutomationName" xml:space="preserve">
<value>Dot line style</value>
<comment>Name of the dotted line style for a graphed equation</comment>
</data>
<data name="dashLineStyleAutomationName" xml:space="preserve">
<value>Dash line style</value>
<comment>Name of the dashed line style for a graphed equation</comment>
</data>
<data name="equationColor1AutomationName" xml:space="preserve">
<value>Navy Blue</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor2AutomationName" xml:space="preserve">
<value>Seafoam</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor3AutomationName" xml:space="preserve">
<value>Violet</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor4AutomationName" xml:space="preserve">
<value>Green</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor5AutomationName" xml:space="preserve">
<value>Mint Green</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor6AutomationName" xml:space="preserve">
<value>Dark Green</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor7AutomationName" xml:space="preserve">
<value>Charcoal</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor8AutomationName" xml:space="preserve">
<value>Red</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor9AutomationName" xml:space="preserve">
<value>Plum Light</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor10AutomationName" xml:space="preserve">
<value>Magenta</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor11AutomationName" xml:space="preserve">
<value>Yellow Gold</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor12AutomationName" xml:space="preserve">
<value>Orange Bright</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor13AutomationName" xml:space="preserve">
<value>Brown</value>
<comment>Name of color in the color picker</comment>
</data>
<data name="equationColor14AutomationName" xml:space="preserve">
<value>Black</value>
<comment>Name of color in the color picker</comment>
</data>
</root>

View File

@ -848,7 +848,9 @@
RemoveButtonClicked="EquationTextBox_RemoveButtonClicked">
<controls:EquationTextBox.ColorChooserFlyout>
<Flyout x:Uid="ColorChooserFlyout" Placement="Bottom">
<local:EquationStylePanelControl SelectedColor="{x:Bind LineColor, Mode=TwoWay}"/>
<local:EquationStylePanelControl EnableLineStylePicker="{x:Bind GraphEquation.IsInequality, Converter={StaticResource BooleanNegationConverter}, Mode=OneWay}"
SelectedColor="{x:Bind LineColor, Mode=TwoWay}"
SelectedStyle="{x:Bind GraphEquation.EquationStyle, Mode=TwoWay}"/>
</Flyout>
</controls:EquationTextBox.ColorChooserFlyout>
</controls:EquationTextBox>

View File

@ -565,6 +565,7 @@ namespace GraphControl
eq->GraphedEquation->TrySelectEquation();
}
eq->GraphedEquation->GetGraphEquationOptions()->SetLineStyle(static_cast<::Graphing::Renderer::LineStyle>(eq->EquationStyle));
eq->GraphedEquation->GetGraphEquationOptions()->SetLineWidth(LineWidth);
eq->GraphedEquation->GetGraphEquationOptions()->SetSelectedEquationLineWidth(LineWidth + ((LineWidth <= 2) ? 1 : 2));
}

View File

@ -26,6 +26,7 @@ namespace GraphControl
{
wstring request;
wstring_view expr{ Expression->Data() };
IsInequality = false;
// Check for unicode characters of less than, less than or equal to, greater than and greater than or equal to.
if (expr.find(L">&#x3E;<") != wstring_view::npos || expr.find(L">&#x3C;<") != wstring_view::npos || expr.find(L">&#x2265;<") != wstring_view::npos
@ -33,6 +34,8 @@ namespace GraphControl
|| expr.find(L">&lt;<") != wstring_view::npos || expr.find(L">&gt;<") != wstring_view::npos)
{
request = L"<mrow><mi>plotIneq2D</mi><mfenced separators=\"\">";
IsInequality = true;
EquationStyle = EquationLineStyle::Dash;
}
else if (expr.find(L">=<") != wstring_view::npos)
{

View File

@ -7,6 +7,16 @@
namespace GraphControl
{
public
enum class EquationLineStyle : int
{
Solid,
Dot,
Dash,
DashDot,
DashDotDot
};
public enum class ErrorType
{
Evaluation,
@ -211,7 +221,9 @@ namespace GraphControl
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsLineEnabled);
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsValidated);
OBSERVABLE_NAMED_PROPERTY_RW(bool, HasGraphError);
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsInequality);
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsSelected);
OBSERVABLE_NAMED_PROPERTY_RW(EquationLineStyle, EquationStyle);
OBSERVABLE_NAMED_PROPERTY_RW(ErrorType, GraphErrorType);
OBSERVABLE_NAMED_PROPERTY_RW(int, GraphErrorCode);
@ -221,12 +233,10 @@ namespace GraphControl
void set(Windows::UI::Color value);
}
static property Platform::String
^ LineColorPropertyName { Platform::String ^ get(); }
public : Platform::String
^ GetRequest();
static property Platform::String ^ LineColorPropertyName { Platform::String ^ get(); }
public:
Platform::String ^ GetRequest();
bool IsGraphableEquation();
internal:

View File

@ -158,7 +158,7 @@ public
{
auto equation = static_cast<Equation ^>(sender);
auto propertyName = args->PropertyName;
if (propertyName == GraphControl::Equation::LineColorPropertyName || propertyName == GraphControl::Equation::IsSelectedPropertyName)
if (propertyName == GraphControl::Equation::LineColorPropertyName || propertyName == GraphControl::Equation::IsSelectedPropertyName || propertyName == GraphControl::Equation::EquationStylePropertyName)
{
EquationStyleChanged(equation);
}