MouseSettings: Update "switch buttons" icon to reflect checkbox state

Using an additional "right button" variant of the graphic, it now
updates the icon based on the user's preference of primary button.
This commit is contained in:
Ravi J 2022-12-30 02:05:38 -05:00 committed by Tim Flynn
parent 2ba66a9941
commit 3a31f37b3d
6 changed files with 15 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 B

View file

@ -178,7 +178,7 @@
@GUI::Label {
fixed_width: 32
fixed_height: 32
icon: "/res/graphics/switch-mouse-buttons.png"
name: "switch_buttons_image_label"
}
@GUI::CheckBox {

View file

@ -51,9 +51,11 @@ MouseWidget::MouseWidget()
set_modified(true);
};
m_switch_buttons_image_label = *find_descendant_of_type_named<GUI::Label>("switch_buttons_image_label");
m_switch_buttons_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("switch_buttons_checkbox");
m_switch_buttons_checkbox->set_checked(GUI::ConnectionToWindowServer::the().are_mouse_buttons_switched(), GUI::AllowCallback::No);
m_switch_buttons_checkbox->on_checked = [&](auto) {
update_switch_buttons_image_label();
set_modified(true);
};
@ -65,6 +67,7 @@ MouseWidget::MouseWidget()
update_speed_label();
update_double_click_speed_label();
update_switch_buttons_image_label();
m_double_click_arrow_widget->set_double_click_speed(m_double_click_speed_slider->value());
}
@ -96,3 +99,12 @@ void MouseWidget::update_double_click_speed_label()
{
m_double_click_speed_label->set_text(DeprecatedString::formatted("{} ms", m_double_click_speed_slider->value()));
}
void MouseWidget::update_switch_buttons_image_label()
{
if (m_switch_buttons_checkbox->is_checked()) {
m_switch_buttons_image_label->set_icon_from_path("/res/graphics/mouse-button-right.png");
} else {
m_switch_buttons_image_label->set_icon_from_path("/res/graphics/mouse-button-left.png");
}
}

View file

@ -24,6 +24,7 @@ private:
void update_speed_label();
void update_double_click_speed_label();
void update_switch_buttons_image_label();
RefPtr<GUI::HorizontalSlider> m_speed_slider;
RefPtr<GUI::Label> m_speed_label;
@ -31,6 +32,7 @@ private:
RefPtr<GUI::HorizontalSlider> m_double_click_speed_slider;
RefPtr<GUI::Label> m_double_click_speed_label;
RefPtr<GUI::CheckBox> m_switch_buttons_checkbox;
RefPtr<GUI::Label> m_switch_buttons_image_label;
RefPtr<GUI::CheckBox> m_natural_scroll_checkbox;
RefPtr<MouseSettings::DoubleClickArrowWidget> m_double_click_arrow_widget;
};