Replace use of std::bind with lambdas

This commit is contained in:
Mr-Wiseguy 2025-04-06 15:20:50 -04:00
parent a0bd63f725
commit f1a7a1674b
5 changed files with 25 additions and 24 deletions

View file

@ -82,7 +82,7 @@ namespace recompui {
void Radio::add_option(std::string_view name) { void Radio::add_option(std::string_view name) {
RadioOption *option = get_current_context().create_element<RadioOption>(this, name, uint32_t(options.size())); RadioOption *option = get_current_context().create_element<RadioOption>(this, name, uint32_t(options.size()));
option->set_pressed_callback(std::bind(&Radio::option_selected, this, std::placeholders::_1)); option->set_pressed_callback([this](uint32_t index){ option_selected(index); });
options.emplace_back(option); options.emplace_back(option);
// The first option was added, select it. // The first option was added, select it.

View file

@ -84,8 +84,8 @@ namespace recompui {
bar_element->set_height(2.0f); bar_element->set_height(2.0f);
bar_element->set_margin_top(8.0f); bar_element->set_margin_top(8.0f);
bar_element->set_background_color(Color{ 255, 255, 255, 50 }); bar_element->set_background_color(Color{ 255, 255, 255, 50 });
bar_element->add_pressed_callback(std::bind(&Slider::bar_clicked, this, std::placeholders::_1, std::placeholders::_2)); bar_element->add_pressed_callback([this](float x, float y){ bar_clicked(x, y); });
bar_element->add_dragged_callback(std::bind(&Slider::bar_dragged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); bar_element->add_dragged_callback([this](float x, float y, recompui::DragPhase phase){ bar_dragged(x, y, phase); });
circle_element = context.create_element<Clickable>(slider_element, true); circle_element = context.create_element<Clickable>(slider_element, true);
circle_element->set_position(Position::Relative); circle_element->set_position(Position::Relative);
@ -96,7 +96,7 @@ namespace recompui {
circle_element->set_margin_left(-8.0f); circle_element->set_margin_left(-8.0f);
circle_element->set_background_color(Color{ 204, 204, 204, 255 }); circle_element->set_background_color(Color{ 204, 204, 204, 255 });
circle_element->set_border_radius(8.0f); circle_element->set_border_radius(8.0f);
circle_element->add_dragged_callback(std::bind(&Slider::circle_dragged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); circle_element->add_dragged_callback([this](float x, float y, recompui::DragPhase phase){ circle_dragged(x, y, phase); });
circle_element->set_cursor(Cursor::Pointer); circle_element->set_cursor(Cursor::Pointer);
} }

View file

@ -71,7 +71,7 @@ ConfigOptionSlider::ConfigOptionSlider(Element *parent, double value, double min
slider->set_max_value(max_value); slider->set_max_value(max_value);
slider->set_step_value(step_value); slider->set_step_value(step_value);
slider->set_value(value); slider->set_value(value);
slider->add_value_changed_callback(std::bind(&ConfigOptionSlider::slider_value_changed, this, std::placeholders::_1)); slider->add_value_changed_callback([this](double v){ slider_value_changed(v); });
} }
// ConfigOptionTextInput // ConfigOptionTextInput
@ -85,7 +85,7 @@ ConfigOptionTextInput::ConfigOptionTextInput(Element *parent, std::string_view v
text_input = get_current_context().create_element<TextInput>(this); text_input = get_current_context().create_element<TextInput>(this);
text_input->set_text(value); text_input->set_text(value);
text_input->add_text_changed_callback(std::bind(&ConfigOptionTextInput::text_changed, this, std::placeholders::_1)); text_input->add_text_changed_callback([this](const std::string &text){ text_changed(text); });
} }
// ConfigOptionRadio // ConfigOptionRadio
@ -98,7 +98,7 @@ ConfigOptionRadio::ConfigOptionRadio(Element *parent, uint32_t value, const std:
this->callback = callback; this->callback = callback;
radio = get_current_context().create_element<Radio>(this); radio = get_current_context().create_element<Radio>(this);
radio->add_index_changed_callback(std::bind(&ConfigOptionRadio::index_changed, this, std::placeholders::_1)); radio->add_index_changed_callback([this](uint32_t index){ index_changed(index); });
for (std::string_view option : options) { for (std::string_view option : options) {
radio->add_option(option); radio->add_option(option);
} }
@ -152,7 +152,7 @@ ConfigSubMenu::ConfigSubMenu(Element *parent) : Element(parent) {
{ {
back_button = context.create_element<Button>(header_container, "Back", ButtonStyle::Secondary); back_button = context.create_element<Button>(header_container, "Back", ButtonStyle::Secondary);
back_button->add_pressed_callback(std::bind(&ConfigSubMenu::back_button_pressed, this)); back_button->add_pressed_callback([this](){ back_button_pressed(); });
title_label = context.create_element<Label>(header_container, "Title", LabelStyle::Large); title_label = context.create_element<Label>(header_container, "Title", LabelStyle::Large);
} }
@ -190,7 +190,7 @@ void ConfigSubMenu::add_option(ConfigOptionElement *option, std::string_view id,
option->set_id(id); option->set_id(id);
option->set_name(name); option->set_name(name);
option->set_description(description); option->set_description(description);
option->set_hover_callback(std::bind(&ConfigSubMenu::option_hovered, this, std::placeholders::_1, std::placeholders::_2)); option->set_hover_callback([this](ConfigOptionElement *option, bool active){ option_hovered(option, active); });
config_option_elements.emplace_back(option); config_option_elements.emplace_back(option);
} }

View file

@ -62,13 +62,13 @@ ModDetailsPanel::ModDetailsPanel(Element *parent) : Element(parent) {
enable_container->set_gap(16.0f); enable_container->set_gap(16.0f);
{ {
enable_toggle = context.create_element<Toggle>(enable_container); enable_toggle = context.create_element<Toggle>(enable_container);
enable_toggle->add_checked_callback(std::bind(&ModDetailsPanel::enable_toggle_checked, this, std::placeholders::_1)); enable_toggle->add_checked_callback([this](bool checked){ enable_toggle_checked(checked); });
enable_label = context.create_element<Label>(enable_container, "A currently enabled mod requires this mod", LabelStyle::Annotation); enable_label = context.create_element<Label>(enable_container, "A currently enabled mod requires this mod", LabelStyle::Annotation);
} }
configure_button = context.create_element<Button>(buttons_container, "Configure", recompui::ButtonStyle::Secondary); configure_button = context.create_element<Button>(buttons_container, "Configure", recompui::ButtonStyle::Secondary);
configure_button->add_pressed_callback(std::bind(&ModDetailsPanel::configure_button_pressed, this)); configure_button->add_pressed_callback([this](){ configure_button_pressed(); });
} }
} }

View file

@ -1,4 +1,4 @@
#include "ui_mod_menu.h" #include "ui_mod_menu.h"
#include "recomp_ui.h" #include "recomp_ui.h"
#include "zelda_support.h" #include "zelda_support.h"
@ -380,16 +380,19 @@ void ModMenu::mod_configure_requested() {
switch (option.type) { switch (option.type) {
case recomp::mods::ConfigOptionType::Enum: { case recomp::mods::ConfigOptionType::Enum: {
const recomp::mods::ConfigOptionEnum &option_enum = std::get<recomp::mods::ConfigOptionEnum>(option.variant); const recomp::mods::ConfigOptionEnum &option_enum = std::get<recomp::mods::ConfigOptionEnum>(option.variant);
config_sub_menu->add_radio_option(option.id, option.name, option.description, std::get<uint32_t>(config_value), option_enum.options, std::bind(&ModMenu::mod_enum_option_changed, this, std::placeholders::_1, std::placeholders::_2)); config_sub_menu->add_radio_option(option.id, option.name, option.description, std::get<uint32_t>(config_value), option_enum.options,
[this](const std::string &id, uint32_t value){ mod_enum_option_changed(id, value); });
break; break;
} }
case recomp::mods::ConfigOptionType::Number: { case recomp::mods::ConfigOptionType::Number: {
const recomp::mods::ConfigOptionNumber &option_number = std::get<recomp::mods::ConfigOptionNumber>(option.variant); const recomp::mods::ConfigOptionNumber &option_number = std::get<recomp::mods::ConfigOptionNumber>(option.variant);
config_sub_menu->add_slider_option(option.id, option.name, option.description, std::get<double>(config_value), option_number.min, option_number.max, option_number.step, option_number.percent, std::bind(&ModMenu::mod_number_option_changed, this, std::placeholders::_1, std::placeholders::_2)); config_sub_menu->add_slider_option(option.id, option.name, option.description, std::get<double>(config_value), option_number.min, option_number.max, option_number.step, option_number.percent,
[this](const std::string &id, double value){ mod_number_option_changed(id, value); });
break; break;
} }
case recomp::mods::ConfigOptionType::String: { case recomp::mods::ConfigOptionType::String: {
config_sub_menu->add_text_option(option.id, option.name, option.description, std::get<std::string>(config_value), std::bind(&ModMenu::mod_string_option_changed, this, std::placeholders::_1, std::placeholders::_2)); config_sub_menu->add_text_option(option.id, option.name, option.description, std::get<std::string>(config_value),
[this](const std::string &id, const std::string &value){ mod_string_option_changed(id, value); });
break; break;
} }
default: default:
@ -449,8 +452,8 @@ void ModMenu::create_mod_list() {
mod_entry_spacers.emplace_back(spacer); mod_entry_spacers.emplace_back(spacer);
ModEntryButton *mod_entry = context.create_element<ModEntryButton>(list_scroll_container, mod_index); ModEntryButton *mod_entry = context.create_element<ModEntryButton>(list_scroll_container, mod_index);
mod_entry->set_mod_selected_callback(std::bind(&ModMenu::mod_selected, this, std::placeholders::_1)); mod_entry->set_mod_selected_callback([this](uint32_t mod_index){ mod_selected(mod_index); });
mod_entry->set_mod_drag_callback(std::bind(&ModMenu::mod_dragged, this, std::placeholders::_1, std::placeholders::_2)); mod_entry->set_mod_drag_callback([this](uint32_t mod_index, recompui::EventDrag drag){ mod_dragged(mod_index, drag); });
mod_entry->set_mod_details(mod_details[mod_index]); mod_entry->set_mod_details(mod_details[mod_index]);
mod_entry->set_mod_thumbnail(thumbnail_name); mod_entry->set_mod_thumbnail(thumbnail_name);
mod_entry->set_mod_enabled(is_mod_enabled_or_auto(mod_details[mod_index].mod_id)); mod_entry->set_mod_enabled(is_mod_enabled_or_auto(mod_details[mod_index].mod_id));
@ -521,8 +524,8 @@ ModMenu::ModMenu(Element *parent) : Element(parent) {
} // list_container } // list_container
mod_details_panel = context.create_element<ModDetailsPanel>(body_container); mod_details_panel = context.create_element<ModDetailsPanel>(body_container);
mod_details_panel->set_mod_toggled_callback(std::bind(&ModMenu::mod_toggled, this, std::placeholders::_1)); mod_details_panel->set_mod_toggled_callback([this](bool enabled){ mod_toggled(enabled); });
mod_details_panel->set_mod_configure_pressed_callback(std::bind(&ModMenu::mod_configure_requested, this)); mod_details_panel->set_mod_configure_pressed_callback([this](){ mod_configure_requested(); });
} // body_container } // body_container
body_empty_container = context.create_element<Container>(this, FlexDirection::Column, JustifyContent::SpaceBetween); body_empty_container = context.create_element<Container>(this, FlexDirection::Column, JustifyContent::SpaceBetween);
@ -534,7 +537,7 @@ ModMenu::ModMenu(Element *parent) : Element(parent) {
context.create_element<Element>(body_empty_container); context.create_element<Element>(body_empty_container);
} // body_empty_container } // body_empty_container
footer_container = context.create_element<Container>(this, FlexDirection::Row, JustifyContent::SpaceBetween); footer_container = context.create_element<Container>(this, FlexDirection::Row, JustifyContent::FlexStart);
footer_container->set_width(100.0f, recompui::Unit::Percent); footer_container->set_width(100.0f, recompui::Unit::Percent);
footer_container->set_align_items(recompui::AlignItems::Center); footer_container->set_align_items(recompui::AlignItems::Center);
footer_container->set_background_color(Color{ 0, 0, 0, 89 }); footer_container->set_background_color(Color{ 0, 0, 0, 89 });
@ -545,12 +548,10 @@ ModMenu::ModMenu(Element *parent) : Element(parent) {
footer_container->set_border_bottom_right_radius(16.0f); footer_container->set_border_bottom_right_radius(16.0f);
{ {
refresh_button = context.create_element<Button>(footer_container, "Refresh", recompui::ButtonStyle::Primary); refresh_button = context.create_element<Button>(footer_container, "Refresh", recompui::ButtonStyle::Primary);
refresh_button->add_pressed_callback([this](){ recomp::mods::scan_mods(); this->refresh_mods(); }); refresh_button->add_pressed_callback([this](){ recomp::mods::scan_mods(); refresh_mods(); });
context.create_element<Label>(footer_container, "⚠ UNDER CONSTRUCTION ⚠", LabelStyle::Small);
mods_folder_button = context.create_element<Button>(footer_container, "Open Mods Folder", recompui::ButtonStyle::Primary); mods_folder_button = context.create_element<Button>(footer_container, "Open Mods Folder", recompui::ButtonStyle::Primary);
mods_folder_button->add_pressed_callback(std::bind(&ModMenu::open_mods_folder, this)); mods_folder_button->add_pressed_callback([this](){ open_mods_folder(); });
} // footer_container } // footer_container
} // this } // this