From b2a6c9e5ea302760ac24fbac0ec5a9d176793662 Mon Sep 17 00:00:00 2001 From: RasmusNylander <43042651+RasmusNylander@users.noreply.github.com> Date: Wed, 15 Dec 2021 18:44:55 +0100 Subject: 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. :^) --- .../KeyboardMapper/KeyboardMapperWidget.cpp | 39 ++++++++-------------- .../KeyboardMapper/KeyboardMapperWidget.h | 1 + 2 files changed, 14 insertions(+), 26 deletions(-) (limited to 'Userland/Applications') 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 #include #include -#include KeyboardMapperWidget::KeyboardMapperWidget() { @@ -92,35 +91,23 @@ void KeyboardMapperWidget::create_frame() m_map_group->set_layout(); m_map_group->set_fixed_width(450); - auto& radio_map = m_map_group->add("Default"); - radio_map.set_name("map"); - radio_map.on_checked = [&](bool) { - set_current_map("map"); - }; - auto& radio_shift = m_map_group->add("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("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("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("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(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 m_keys; RefPtr m_map_group; + void add_map_radio_button(const StringView map_name, const StringView button_text); String m_filename; Keyboard::CharacterMapData m_character_map; -- cgit v1.2.3