Move Focus to Type button in new row on Adding a remap (#7586)

This commit is contained in:
Arjun Balgovind
2020-10-29 13:16:52 -07:00
committed by GitHub
parent 6e2191a34e
commit 06cd9409e9
6 changed files with 44 additions and 0 deletions

View File

@@ -15,6 +15,7 @@
#include "keyboardmanager/common/KeyboardManagerState.h"
#include "common/common.h"
#include "LoadingAndSavingRemappingHelper.h"
#include "UIHelpers.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
using namespace winrt::Windows::Foundation;
@@ -304,8 +305,12 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
addRemapKey.Margin({ 10, 10, 0, 25 });
addRemapKey.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
SingleKeyRemapControl::AddNewControlKeyRemapRow(keyRemapTable, keyboardRemapControlObjects);
// Whenever a remap is added move to the bottom of the screen
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
// Set focus to the first Type Button in the newly added row
UIHelpers::SetFocusOnTypeButtonInLastRow(keyRemapTable, KeyboardManagerConstants::RemapTableColCount);
});
// Set accessible name for the addRemapKey button

View File

@@ -13,6 +13,7 @@
#include <keyboardmanager/common/KeyboardManagerState.h>
#include "common/common.h"
#include "LoadingAndSavingRemappingHelper.h"
#include "UIHelpers.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
using namespace winrt::Windows::Foundation;
@@ -291,8 +292,12 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
addShortcut.Margin({ 10, 0, 0, 25 });
addShortcut.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects);
// Whenever a remap is added move to the bottom of the screen
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
// Set focus to the first Type Button in the newly added row
UIHelpers::SetFocusOnTypeButtonInLastRow(shortcutTable, KeyboardManagerConstants::ShortcutTableColCount);
});
// Set accessible name for the add shortcut button

View File

@@ -124,6 +124,7 @@
<ClCompile Include="ShortcutControl.cpp" />
<ClCompile Include="SingleKeyRemapControl.cpp" />
<ClCompile Include="Styles.cpp" />
<ClCompile Include="UIHelpers.cpp" />
<ClCompile Include="XamlBridge.cpp" />
</ItemGroup>
<ItemGroup>
@@ -137,6 +138,7 @@
<ClInclude Include="pch.h" />
<ClInclude Include="ShortcutControl.h" />
<ClInclude Include="SingleKeyRemapControl.h" />
<ClInclude Include="UIHelpers.h" />
<ClInclude Include="XamlBridge.h" />
</ItemGroup>
<ItemGroup>

View File

@@ -34,6 +34,9 @@
<ClCompile Include="BufferValidationHelpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UIHelpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Dialog.h">
@@ -69,6 +72,9 @@
<ClInclude Include="BufferValidationHelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="UIHelpers.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Source Files">

View File

@@ -0,0 +1,18 @@
#include "pch.h"
#include "UIHelpers.h"
namespace UIHelpers
{
// This method sets focus to the first Type button on the last row of the Grid
void SetFocusOnTypeButtonInLastRow(Grid& parent, long colCount)
{
// First element in the last row (StackPanel)
StackPanel firstElementInLastRow = parent.Children().GetAt(parent.Children().Size() - colCount).as<StackPanel>();
// Type button is the first child in the StackPanel
Button firstTypeButtonInLastRow = firstElementInLastRow.Children().GetAt(0).as<Button>();
// Set programmatic focus on the button
firstTypeButtonInLastRow.Focus(FocusState::Programmatic);
}
}

View File

@@ -0,0 +1,8 @@
#pragma once
// This namespace contains UI methods that are to be used for both KBM windows
namespace UIHelpers
{
// This method sets focus to the first Type button on the last row of the Grid
void SetFocusOnTypeButtonInLastRow(Grid& parent, long colCount);
}