From 8590ae083900bd92bb26f5ab9c5d6497e457d7db Mon Sep 17 00:00:00 2001 From: Arjun Date: Mon, 20 Apr 2020 17:44:12 -0700 Subject: [PATCH 1/6] Added grid to edit keyboard --- .../keyboardmanager/ui/EditKeyboardWindow.cpp | 39 ++++++++++++----- .../ui/EditShortcutsWindow.cpp | 8 ++-- .../ui/SingleKeyRemapControl.cpp | 43 +++++++++++++------ .../ui/SingleKeyRemapControl.h | 2 +- 4 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp index 09cac2964f34..2e0ff469fa81 100644 --- a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp @@ -78,20 +78,22 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan xamlContainer.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); // Header for the window - Windows::UI::Xaml::Controls::StackPanel header; - header.Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal); + Windows::UI::Xaml::Controls::RelativePanel header; + //header.Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal); header.Margin({ 10, 10, 10, 30 }); - header.Spacing(10); + //header.Spacing(10); // Header text TextBlock headerText; headerText.Text(winrt::to_hstring("Remap Keyboard")); headerText.Foreground(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::Black() }); headerText.FontSize(30); - headerText.Margin({ 0, 0, 1000, 0 }); + headerText.Margin({ 0, 0, 0, 0 }); + header.SetAlignLeftWithPanel(headerText, true); // Header Cancel button Button cancelButton; + cancelButton.Margin({ 0, 0, 10, 0 }); cancelButton.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); cancelButton.Foreground(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::Black() }); cancelButton.Content(winrt::box_value(winrt::to_hstring("Cancel"))); @@ -107,10 +109,17 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan keyRemapInfoHeader.Margin({ 10, 0, 0, 10 }); // Table to display the key remaps - Windows::UI::Xaml::Controls::StackPanel keyRemapTable; - keyRemapTable.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); + Grid keyRemapTable; + ColumnDefinition firstColumn; + ColumnDefinition secondColumn; + ColumnDefinition thirdColumn; keyRemapTable.Margin({ 10, 10, 10, 20 }); - keyRemapTable.Spacing(10); + keyRemapTable.HorizontalAlignment(HorizontalAlignment::Stretch); + keyRemapTable.ColumnSpacing(10); + keyRemapTable.ColumnDefinitions().Append(firstColumn); + keyRemapTable.ColumnDefinitions().Append(secondColumn); + keyRemapTable.ColumnDefinitions().Append(thirdColumn); + keyRemapTable.RowDefinitions().Append(RowDefinition()); // Header row of the keys remap table Windows::UI::Xaml::Controls::StackPanel tableHeaderRow; @@ -124,7 +133,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan originalKeyRemapHeader.Foreground(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::Black() }); originalKeyRemapHeader.FontWeight(Text::FontWeights::Bold()); originalKeyRemapHeader.Margin({ 0, 0, 0, 10 }); - tableHeaderRow.Children().Append(originalKeyRemapHeader); + //tableHeaderRow.Children().Append(originalKeyRemapHeader); // Second header textblock in the header row of the keys remap table TextBlock newKeyRemapHeader; @@ -132,9 +141,17 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan newKeyRemapHeader.Foreground(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::Black() }); newKeyRemapHeader.FontWeight(Text::FontWeights::Bold()); newKeyRemapHeader.Margin({ 0, 0, 0, 10 }); - tableHeaderRow.Children().Append(newKeyRemapHeader); + //tableHeaderRow.Children().Append(newKeyRemapHeader); + ColumnDefinition primary; + ColumnDefinition secondary; - keyRemapTable.Children().Append(tableHeaderRow); + keyRemapTable.SetColumn(originalKeyRemapHeader, 0); + keyRemapTable.SetRow(originalKeyRemapHeader, 0); + keyRemapTable.SetColumn(newKeyRemapHeader, 1); + keyRemapTable.SetRow(newKeyRemapHeader, 0); + + keyRemapTable.Children().Append(originalKeyRemapHeader); + keyRemapTable.Children().Append(newKeyRemapHeader); // Message to display success/failure of saving settings. Flyout applyFlyout; @@ -161,6 +178,8 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan // Main Header Apply button Button applyButton; + header.SetAlignRightWithPanel(applyButton, true); + header.SetLeftOf(cancelButton, applyButton); applyButton.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); applyButton.Foreground(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::Black() }); applyButton.Content(winrt::box_value(winrt::to_hstring("Apply"))); diff --git a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp index c30d12de49a7..6eac7ee9720c 100644 --- a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp @@ -79,20 +79,20 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa xamlContainer.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); // Header for the window - Windows::UI::Xaml::Controls::StackPanel header; + Windows::UI::Xaml::Controls::RelativePanel header; header.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); - header.Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal); header.Margin({ 10, 10, 10, 30 }); - header.Spacing(10); // Header text TextBlock headerText; headerText.Text(winrt::to_hstring("Edit Shortcuts")); headerText.FontSize(30); headerText.Margin({ 0, 0, 100, 0 }); + header.SetAlignLeftWithPanel(headerText, true); // Cancel button Button cancelButton; + cancelButton.Margin({ 0, 0, 10, 0 }); cancelButton.Content(winrt::box_value(winrt::to_hstring("Cancel"))); cancelButton.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) { // Close the window since settings do not need to be saved @@ -152,6 +152,8 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa // Apply button Button applyButton; + header.SetAlignRightWithPanel(applyButton, true); + header.SetLeftOf(cancelButton, applyButton); applyButton.Content(winrt::box_value(winrt::to_hstring("Apply"))); applyButton.Flyout(applyFlyout); applyButton.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) { diff --git a/src/modules/keyboardmanager/ui/SingleKeyRemapControl.cpp b/src/modules/keyboardmanager/ui/SingleKeyRemapControl.cpp index 265fd819e87b..f25e290ef039 100644 --- a/src/modules/keyboardmanager/ui/SingleKeyRemapControl.cpp +++ b/src/modules/keyboardmanager/ui/SingleKeyRemapControl.cpp @@ -8,23 +8,31 @@ KeyboardManagerState* SingleKeyRemapControl::keyboardManagerState = nullptr; std::vector> SingleKeyRemapControl::singleKeyRemapBuffer; // Function to add a new row to the remap keys table. If the originalKey and newKey args are provided, then the displayed remap keys are set to those values. -void SingleKeyRemapControl::AddNewControlKeyRemapRow(StackPanel& parent, std::vector>>& keyboardRemapControlObjects, const DWORD originalKey, const DWORD newKey) +void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector>>& keyboardRemapControlObjects, const DWORD originalKey, const DWORD newKey) { // Parent element for the row - Windows::UI::Xaml::Controls::StackPanel tableRow; - tableRow.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); - tableRow.Spacing(100); - tableRow.Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal); + //Windows::UI::Xaml::Controls::StackPanel tableRow; + //tableRow.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() }); + //tableRow.Spacing(100); + //tableRow.Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal); // Create new SingleKeyRemapControl objects dynamically so that we does not get destructed std::vector> newrow; newrow.push_back(std::move(std::unique_ptr(new SingleKeyRemapControl(singleKeyRemapBuffer.size(), 0)))); newrow.push_back(std::move(std::unique_ptr(new SingleKeyRemapControl(singleKeyRemapBuffer.size(), 1)))); keyboardRemapControlObjects.push_back(std::move(newrow)); + + // Add to grid + int debug = parent.RowDefinitions().Size(); + parent.RowDefinitions().Append(RowDefinition()); + parent.SetColumn(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->getSingleKeyRemapControl(), 0); + parent.SetRow(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->getSingleKeyRemapControl(), parent.RowDefinitions().Size() - 1); + parent.SetColumn(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl(), 1); + parent.SetRow(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl(), parent.RowDefinitions().Size() - 1); // SingleKeyRemapControl for the original key. - tableRow.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->getSingleKeyRemapControl()); + parent.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->getSingleKeyRemapControl()); // SingleKeyRemapControl for the new remap key - tableRow.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl()); + parent.Children().Append(keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->getSingleKeyRemapControl()); // Set the key text if the two keys are not null (i.e. default args) if (originalKey != NULL && newKey != NULL) @@ -57,17 +65,24 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(StackPanel& parent, std::ve deleteSymbol.Glyph(L"\xE74D"); deleteRemapKeys.Content(deleteSymbol); deleteRemapKeys.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) { - StackPanel currentRow = sender.as