diff options
author | RasmusNylander <43042651+RasmusNylander@users.noreply.github.com> | 2021-12-15 18:44:55 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-06 17:54:03 +0100 |
commit | b2a6c9e5ea302760ac24fbac0ec5a9d176793662 (patch) | |
tree | 84cde49670dd1a34e5f9b79ccaf5ea5b733d8826 /Userland/Applications | |
parent | 8eb8949d9cb8c574ca58dad69337545247895766 (diff) | |
download | serenity-b2a6c9e5ea302760ac24fbac0ec5a9d176793662.zip |
KeyboardMapper: Extract creation of map-selection buttons
Extract the creation of map-selection radio buttons from create_frame
into the new private method add_map_radio_button(map_name, button_text)
turning 24 lines into 4 + 6 lines. This makes create_frame a little
easier to read. :^)
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp | 39 | ||||
-rw-r--r-- | Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h | 1 |
2 files changed, 14 insertions, 26 deletions
diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp index 1258ee2edf..c4ca361c48 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp @@ -13,7 +13,6 @@ #include <LibGUI/RadioButton.h> #include <LibKeyboard/CharacterMap.h> #include <LibKeyboard/CharacterMapFile.h> -#include <string.h> KeyboardMapperWidget::KeyboardMapperWidget() { @@ -92,35 +91,23 @@ void KeyboardMapperWidget::create_frame() m_map_group->set_layout<GUI::HorizontalBoxLayout>(); m_map_group->set_fixed_width(450); - auto& radio_map = m_map_group->add<GUI::RadioButton>("Default"); - radio_map.set_name("map"); - radio_map.on_checked = [&](bool) { - set_current_map("map"); - }; - auto& radio_shift = m_map_group->add<GUI::RadioButton>("Shift"); - radio_shift.set_name("shift_map"); - radio_shift.on_checked = [this](bool) { - set_current_map("shift_map"); - }; - auto& radio_altgr = m_map_group->add<GUI::RadioButton>("AltGr"); - radio_altgr.set_name("altgr_map"); - radio_altgr.on_checked = [this](bool) { - set_current_map("altgr_map"); - }; - auto& radio_alt = m_map_group->add<GUI::RadioButton>("Alt"); - radio_alt.set_name("alt_map"); - radio_alt.on_checked = [this](bool) { - set_current_map("alt_map"); - }; - auto& radio_shift_altgr = m_map_group->add<GUI::RadioButton>("Shift+AltGr"); - radio_shift_altgr.set_name("shift_altgr_map"); - radio_shift_altgr.on_checked = [this](bool) { - set_current_map("shift_altgr_map"); - }; + add_map_radio_button("map", "Default"); + add_map_radio_button("shift_map", "Shift"); + add_map_radio_button("altgr_map", "AltGr"); + add_map_radio_button("alt_map", "Alt"); + add_map_radio_button("shift_altgr_map", "Shift+AltGr"); bottom_widget.layout()->add_spacer(); } +void KeyboardMapperWidget::add_map_radio_button(const StringView map_name, const StringView button_text) { + auto& map_radio_button = m_map_group->add<GUI::RadioButton>(button_text); + map_radio_button.set_name(map_name); + map_radio_button.on_checked = [map_name, this](bool){ + set_current_map(map_name); + }; +} + void KeyboardMapperWidget::load_from_file(String filename) { auto result = Keyboard::CharacterMapFile::load_from_file(filename); diff --git a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h index f085955828..b77919d4aa 100644 --- a/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h +++ b/Userland/Applications/KeyboardMapper/KeyboardMapperWidget.h @@ -34,6 +34,7 @@ private: Vector<KeyButton*> m_keys; RefPtr<GUI::Widget> m_map_group; + void add_map_radio_button(const StringView map_name, const StringView button_text); String m_filename; Keyboard::CharacterMapData m_character_map; |