Skip to content

Commit

Permalink
Move Focus to Type button in new row on Adding a remap (#7586)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunbalgovind committed Oct 29, 2020
1 parent 6e2191a commit 06cd940
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/modules/keyboardmanager/ui/KeyboardManagerUI.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down
18 changes: 18 additions & 0 deletions src/modules/keyboardmanager/ui/UIHelpers.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
8 changes: 8 additions & 0 deletions src/modules/keyboardmanager/ui/UIHelpers.h
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 06cd940

Please sign in to comment.