mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
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. :^)
This commit is contained in:
parent
8eb8949d9c
commit
b2a6c9e5ea
2 changed files with 14 additions and 26 deletions
|
@ -13,7 +13,6 @@
|
||||||
#include <LibGUI/RadioButton.h>
|
#include <LibGUI/RadioButton.h>
|
||||||
#include <LibKeyboard/CharacterMap.h>
|
#include <LibKeyboard/CharacterMap.h>
|
||||||
#include <LibKeyboard/CharacterMapFile.h>
|
#include <LibKeyboard/CharacterMapFile.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
KeyboardMapperWidget::KeyboardMapperWidget()
|
KeyboardMapperWidget::KeyboardMapperWidget()
|
||||||
{
|
{
|
||||||
|
@ -92,35 +91,23 @@ void KeyboardMapperWidget::create_frame()
|
||||||
m_map_group->set_layout<GUI::HorizontalBoxLayout>();
|
m_map_group->set_layout<GUI::HorizontalBoxLayout>();
|
||||||
m_map_group->set_fixed_width(450);
|
m_map_group->set_fixed_width(450);
|
||||||
|
|
||||||
auto& radio_map = m_map_group->add<GUI::RadioButton>("Default");
|
add_map_radio_button("map", "Default");
|
||||||
radio_map.set_name("map");
|
add_map_radio_button("shift_map", "Shift");
|
||||||
radio_map.on_checked = [&](bool) {
|
add_map_radio_button("altgr_map", "AltGr");
|
||||||
set_current_map("map");
|
add_map_radio_button("alt_map", "Alt");
|
||||||
};
|
add_map_radio_button("shift_altgr_map", "Shift+AltGr");
|
||||||
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");
|
|
||||||
};
|
|
||||||
|
|
||||||
bottom_widget.layout()->add_spacer();
|
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)
|
void KeyboardMapperWidget::load_from_file(String filename)
|
||||||
{
|
{
|
||||||
auto result = Keyboard::CharacterMapFile::load_from_file(filename);
|
auto result = Keyboard::CharacterMapFile::load_from_file(filename);
|
||||||
|
|
|
@ -34,6 +34,7 @@ private:
|
||||||
|
|
||||||
Vector<KeyButton*> m_keys;
|
Vector<KeyButton*> m_keys;
|
||||||
RefPtr<GUI::Widget> m_map_group;
|
RefPtr<GUI::Widget> m_map_group;
|
||||||
|
void add_map_radio_button(const StringView map_name, const StringView button_text);
|
||||||
|
|
||||||
String m_filename;
|
String m_filename;
|
||||||
Keyboard::CharacterMapData m_character_map;
|
Keyboard::CharacterMapData m_character_map;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue