From 864f99a359c35fdca98f9223bcb32021f044c8e6 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Fri, 23 Aug 2024 16:11:49 +0200 Subject: [PATCH] Rename all member functions from p_ to m_ --- src/UI/UI_button.cpp | 6 ++-- src/UI/UI_button.hpp | 2 +- src/UI/UI_checkbox.cpp | 36 +++++++++++----------- src/UI/UI_checkbox.hpp | 4 +-- src/UI/UI_combobox.cpp | 22 +++++++------- src/UI/UI_combobox.hpp | 4 +-- src/UI/UI_item.cpp | 56 +++++++++++++++++------------------ src/UI/UI_item.hpp | 12 ++++---- src/UI/UI_slider.cpp | 28 +++++++++--------- src/UI/UI_slider.hpp | 8 ++--- src/UI/UI_x_boxes.cpp | 10 +++---- src/UI/UI_x_boxes.hpp | 6 +--- tools/simulator_base.cpp | 20 ++++++------- tools/simulator_base.hpp | 8 ++--- tools/simulators/test_sim.cpp | 20 ++++++------- tools/simulators/test_sim.hpp | 10 +++---- 16 files changed, 124 insertions(+), 128 deletions(-) diff --git a/src/UI/UI_button.cpp b/src/UI/UI_button.cpp index d1fb578..d612d5a 100644 --- a/src/UI/UI_button.cpp +++ b/src/UI/UI_button.cpp @@ -3,7 +3,7 @@ UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color, std::function on_click) : UI_item(id, UI_BUTTON_TYPE, text, 12, fg_color, bg_color) { - this->p_on_click = on_click; + this->m_on_click = on_click; } UI_button::UI_button(const json& j) @@ -25,8 +25,8 @@ json UI_button::to_json() const void UI_button::click() const { - if (p_on_click != nullptr) + if (m_on_click != nullptr) { - p_on_click(p_id); + m_on_click(m_id); } } diff --git a/src/UI/UI_button.hpp b/src/UI/UI_button.hpp index 2696aa9..cff1a57 100644 --- a/src/UI/UI_button.hpp +++ b/src/UI/UI_button.hpp @@ -15,5 +15,5 @@ class UI_button : public UI_item void click() const override; private: - std::function p_on_click = nullptr; + std::function m_on_click = nullptr; }; \ No newline at end of file diff --git a/src/UI/UI_checkbox.cpp b/src/UI/UI_checkbox.cpp index 7cbf80b..d3426fc 100644 --- a/src/UI/UI_checkbox.cpp +++ b/src/UI/UI_checkbox.cpp @@ -1,41 +1,41 @@ #include "UI_checkbox.hpp" UI_checkbox::UI_checkbox() - : UI_x_boxes(UI_CHECKBOX_TYPE), p_selected(), p_on_change(nullptr) + : UI_x_boxes(UI_CHECKBOX_TYPE), m_selected(), m_on_change(nullptr) { } UI_checkbox::UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector options, std::function)> on_change) - : UI_x_boxes(id, UI_CHECKBOX_TYPE, text, fg_color, bg_color, options), p_selected(), p_on_change(on_change) + : UI_x_boxes(id, UI_CHECKBOX_TYPE, text, fg_color, bg_color, options), m_selected(), m_on_change(on_change) { - for (size_t i = 0; i < p_options.size(); i++) + for (size_t i = 0; i < m_options.size(); i++) { - p_selected.push_back(false); + m_selected.push_back(false); } } UI_checkbox::UI_checkbox(const json& j) : -UI_x_boxes(UI_CHECKBOX_TYPE), p_selected(), p_on_change(nullptr) +UI_x_boxes(UI_CHECKBOX_TYPE), m_selected(), m_on_change(nullptr) { from_json(j); } void UI_checkbox::toggle_selected(size_t selected) { - if (selected >= p_options.size()) + if (selected >= m_options.size()) return; - p_selected[selected] = !p_selected[selected]; - if (p_on_change != nullptr) + m_selected[selected] = !m_selected[selected]; + if (m_on_change != nullptr) { - p_on_change(p_id, selected_text()); + m_on_change(m_id, selected_text()); } } void UI_checkbox::toggle_selected(std::string selected) { - for (size_t i = 0; i < p_options.size(); i++) + for (size_t i = 0; i < m_options.size(); i++) { - if (p_options[i] == selected) + if (m_options[i] == selected) { toggle_selected(i); return; @@ -45,17 +45,17 @@ void UI_checkbox::toggle_selected(std::string selected) std::vector UI_checkbox::selected() const { - return p_selected; + return m_selected; } std::vector UI_checkbox::selected_text() const { std::vector selected_text; - for (size_t i = 0; i < p_options.size(); i++) + for (size_t i = 0; i < m_options.size(); i++) { - if (p_selected[i]) + if (m_selected[i]) { - selected_text.push_back(p_options[i]); + selected_text.push_back(m_options[i]); } } return selected_text; @@ -67,10 +67,10 @@ void UI_checkbox::from_json(const json& j) if (j.contains("selected")) { - p_selected.clear(); + m_selected.clear(); for (auto selected : j["selected"]) { - p_selected.push_back(selected); + m_selected.push_back(selected); } } } @@ -78,6 +78,6 @@ void UI_checkbox::from_json(const json& j) json UI_checkbox::to_json() const { json j = UI_x_boxes::to_json(); - j["selected"] = p_selected; + j["selected"] = m_selected; return j; } diff --git a/src/UI/UI_checkbox.hpp b/src/UI/UI_checkbox.hpp index 3e14598..0b84b20 100644 --- a/src/UI/UI_checkbox.hpp +++ b/src/UI/UI_checkbox.hpp @@ -20,7 +20,7 @@ class UI_checkbox : public UI_x_boxes void from_json(const json& j) override; json to_json() const override; private: - std::vector p_selected; + std::vector m_selected; - std::function)> p_on_change; + std::function)> m_on_change; }; \ No newline at end of file diff --git a/src/UI/UI_combobox.cpp b/src/UI/UI_combobox.cpp index 9fbf600..a7bd746 100644 --- a/src/UI/UI_combobox.cpp +++ b/src/UI/UI_combobox.cpp @@ -6,32 +6,32 @@ UI_combobox::UI_combobox() } UI_combobox::UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector options, size_t selected, std::function on_change) - : UI_x_boxes(id, UI_COMBOBOX_TYPE, text, fg_color, bg_color, options), p_selected(selected), p_on_change(on_change) + : UI_x_boxes(id, UI_COMBOBOX_TYPE, text, fg_color, bg_color, options), m_selected(selected), m_on_change(on_change) { } UI_combobox::UI_combobox(const json& j) -: UI_x_boxes(UI_COMBOBOX_TYPE), p_on_change(nullptr) +: UI_x_boxes(UI_COMBOBOX_TYPE), m_on_change(nullptr) { from_json(j); } void UI_combobox::set_selected(size_t selected) { - if (selected == p_selected) + if (selected == m_selected) return; - p_selected = selected; - if (p_on_change != nullptr) + m_selected = selected; + if (m_on_change != nullptr) { - p_on_change(p_id, selected_text()); + m_on_change(m_id, selected_text()); } } void UI_combobox::set_selected(std::string selected) { - for (size_t i = 0; i < p_options.size(); i++) + for (size_t i = 0; i < m_options.size(); i++) { - if (p_options[i] == selected) + if (m_options[i] == selected) { set_selected(i); return; @@ -41,12 +41,12 @@ void UI_combobox::set_selected(std::string selected) size_t UI_combobox::selected() const { - return p_selected; + return m_selected; } std::string UI_combobox::selected_text() const { - return p_options[p_selected]; + return m_options[m_selected]; } void UI_combobox::from_json(const json& j) @@ -57,6 +57,6 @@ void UI_combobox::from_json(const json& j) json UI_combobox::to_json() const { json j = UI_x_boxes::to_json(); - j["selected"] = p_options[p_selected]; + j["selected"] = m_options[m_selected]; return j; } \ No newline at end of file diff --git a/src/UI/UI_combobox.hpp b/src/UI/UI_combobox.hpp index 0e9a76b..07fa4b3 100644 --- a/src/UI/UI_combobox.hpp +++ b/src/UI/UI_combobox.hpp @@ -21,7 +21,7 @@ class UI_combobox : public UI_x_boxes void from_json(const json& j) override; json to_json() const override; private: - size_t p_selected; + size_t m_selected; - std::function p_on_change; + std::function m_on_change; }; \ No newline at end of file diff --git a/src/UI/UI_item.cpp b/src/UI/UI_item.cpp index a9f91bd..a38f221 100644 --- a/src/UI/UI_item.cpp +++ b/src/UI/UI_item.cpp @@ -1,12 +1,12 @@ #include "UI_item.hpp" UI_item::UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color) - : p_id(id), p_type(type), p_text(text), p_text_size(text_size), p_fg_color(fg_color), p_bg_color(bg_color) + : m_id(id), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color), m_bg_color(bg_color) { } UI_item::UI_item(std::string type) - : p_id(""), p_type(type), p_text(""), p_text_size(12), p_fg_color(Color::Black), p_bg_color(Color::White) + : m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black), m_bg_color(Color::White) { } @@ -17,12 +17,12 @@ UI_item::UI_item(const json& j) std::string UI_item::id() const { - return p_id; + return m_id; } std::string UI_item::type() const { - return p_type; + return m_type; } bool UI_item::is_type(json j) @@ -31,59 +31,59 @@ bool UI_item::is_type(json j) { return false; } - return j.at("type") == p_type; + return j.at("type") == m_type; } void UI_item::set_text(std::string text) { - if (this->p_text != text) + if (this->m_text != text) { - this->p_text = text; + this->m_text = text; } } std::string UI_item::text() const { - return p_text; + return m_text; } void UI_item::set_text_size(uint8_t text_size) { - if (this->p_text_size != text_size) + if (this->m_text_size != text_size) { - this->p_text_size = text_size; + this->m_text_size = text_size; } } uint8_t UI_item::text_size() const { - return p_text_size; + return m_text_size; } void UI_item::set_fg_color(Color fg_color) { - if (this->p_fg_color != fg_color) + if (this->m_fg_color != fg_color) { - this->p_fg_color = fg_color; + this->m_fg_color = fg_color; } } Color UI_item::fg_color() const { - return p_fg_color; + return m_fg_color; } void UI_item::set_bg_color(Color bg_color) { - if (this->p_bg_color != bg_color) + if (this->m_bg_color != bg_color) { - this->p_bg_color = bg_color; + this->m_bg_color = bg_color; } } Color UI_item::bg_color() const { - return p_bg_color; + return m_bg_color; } @@ -91,25 +91,25 @@ void UI_item::from_json(const json& j) { if (!is_type(j)) return; - j.at("id").get_to(p_id); - j.at("text").get_to(p_text); - j.at("text_size").get_to(p_text_size); + j.at("id").get_to(m_id); + j.at("text").get_to(m_text); + j.at("text_size").get_to(m_text_size); std::string color; j.at("fg_color").get_to(color); - p_fg_color = Color(color); + m_fg_color = Color(color); color.clear(); j.at("bg_color").get_to(color); - p_bg_color = Color(color); + m_bg_color = Color(color); } json UI_item::to_json() const { json j; - j["id"] = p_id; - j["type"] = p_type; - j["text"] = p_text; - j["text_size"] = p_text_size; - j["fg_color"] = p_fg_color.to_hex(); - j["bg_color"] = p_bg_color.to_hex(); + j["id"] = m_id; + j["type"] = m_type; + j["text"] = m_text; + j["text_size"] = m_text_size; + j["fg_color"] = m_fg_color.to_hex(); + j["bg_color"] = m_bg_color.to_hex(); return j; } \ No newline at end of file diff --git a/src/UI/UI_item.hpp b/src/UI/UI_item.hpp index ae53215..ad8ea8b 100644 --- a/src/UI/UI_item.hpp +++ b/src/UI/UI_item.hpp @@ -39,10 +39,10 @@ class UI_item { virtual void set_value(double value) {UNUSED(value);}; protected: - std::string p_id; - std::string p_type; - std::string p_text; - uint8_t p_text_size; - Color p_fg_color; - Color p_bg_color; + std::string m_id; + std::string m_type; + std::string m_text; + uint8_t m_text_size; + Color m_fg_color; + Color m_bg_color; }; \ No newline at end of file diff --git a/src/UI/UI_slider.cpp b/src/UI/UI_slider.cpp index a35649c..87ed3a7 100644 --- a/src/UI/UI_slider.cpp +++ b/src/UI/UI_slider.cpp @@ -1,9 +1,9 @@ #include "UI_slider.hpp" UI_slider::UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, std::function on_change) - : UI_item(id, UI_SLIDER_TYPE, text, 12, fg_color, bg_color), p_min(min), p_max(max), p_value(value) + : UI_item(id, UI_SLIDER_TYPE, text, 12, fg_color, bg_color), m_min(min), m_max(max), m_value(value) { - this->p_on_change = on_change; + this->m_on_change = on_change; } UI_slider::UI_slider(const json& j) @@ -14,37 +14,37 @@ UI_slider::UI_slider(const json& j) void UI_slider::set_value(double value) { - if (value < p_min || value > p_max) + if (value < m_min || value > m_max) return; - if (value == p_value) + if (value == m_value) return; - if (p_on_change != nullptr) + if (m_on_change != nullptr) { - this->p_value = value; - p_on_change(p_id, value); + this->m_value = value; + m_on_change(m_id, value); } } double UI_slider::value() const { - return p_value; + return m_value; } void UI_slider::from_json(const json& j) { UI_item::from_json(j); - this->p_min = j["min"]; - this->p_max = j["max"]; - this->p_value = j["value"]; + this->m_min = j["min"]; + this->m_max = j["max"]; + this->m_value = j["value"]; } json UI_slider::to_json() const { json j = UI_item::to_json(); - j["min"] = this->p_min; - j["max"] = this->p_max; - j["value"] = this->p_value; + j["min"] = this->m_min; + j["max"] = this->m_max; + j["value"] = this->m_value; return j; } \ No newline at end of file diff --git a/src/UI/UI_slider.hpp b/src/UI/UI_slider.hpp index c36976b..b1e2145 100644 --- a/src/UI/UI_slider.hpp +++ b/src/UI/UI_slider.hpp @@ -15,9 +15,9 @@ class UI_slider : public UI_item void from_json(const json& j) override; json to_json() const override; private: - double p_min; - double p_max; - double p_value; + double m_min; + double m_max; + double m_value; - std::function p_on_change; + std::function m_on_change; }; \ No newline at end of file diff --git a/src/UI/UI_x_boxes.cpp b/src/UI/UI_x_boxes.cpp index 51ad963..4244c4d 100644 --- a/src/UI/UI_x_boxes.cpp +++ b/src/UI/UI_x_boxes.cpp @@ -1,12 +1,12 @@ #include "UI_x_boxes.hpp" UI_x_boxes::UI_x_boxes(std::string type) - : UI_item(type), p_options() + : UI_item(type), m_options() { } UI_x_boxes::UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color, std::vector options) - : UI_item(id, type, text, 12, fg_color, bg_color), p_options(options) + : UI_item(id, type, text, 12, fg_color, bg_color), m_options(options) { } @@ -15,10 +15,10 @@ void UI_x_boxes::from_json(const json& j) UI_item::from_json(j); if (j.contains("options")) { - this->p_options.clear(); + this->m_options.clear(); for (auto option : j["options"]) { - this->p_options.push_back(option); + this->m_options.push_back(option); } } } @@ -26,6 +26,6 @@ void UI_x_boxes::from_json(const json& j) json UI_x_boxes::to_json() const { json j = UI_item::to_json(); - j["options"] = this->p_options; + j["options"] = this->m_options; return j; } \ No newline at end of file diff --git a/src/UI/UI_x_boxes.hpp b/src/UI/UI_x_boxes.hpp index 94c47a4..ccf24c6 100644 --- a/src/UI/UI_x_boxes.hpp +++ b/src/UI/UI_x_boxes.hpp @@ -11,9 +11,5 @@ class UI_x_boxes : public UI_item void from_json(const json& j) override; json to_json() const override; protected: - std::vector p_options; - // std::vector p_selected_multi; - // size_t p_selected; - - // void (*p_on_change) (std::string id, int selected); + std::vector m_options; }; \ No newline at end of file diff --git a/tools/simulator_base.cpp b/tools/simulator_base.cpp index 3a90378..462824d 100644 --- a/tools/simulator_base.cpp +++ b/tools/simulator_base.cpp @@ -1,19 +1,19 @@ #include "simulator_base.hpp" Simulator_base::Simulator_base(std::string name, std::chrono::milliseconds interval) - : p_name(name), p_timer([this]{ timer(); }), m_interval(interval) + : m_name(name), m_timer([this]{ timer(); }), m_interval(interval) { } std::string Simulator_base::name() const { // Get the name of the simulator - return p_name; + return m_name; } bool Simulator_base::is_ui_id_unique(std::string id) const { // Check if the UI name is unique - for (UI_item* item : p_UI_items) { + for (UI_item* item : m_UI_items) { if (item->id() == id) { return false; } @@ -27,15 +27,15 @@ void Simulator_base::add_UI_item(UI_item* item) { if (is_ui_id_unique(item->id()) == false) { throw std::runtime_error("UI item id " + item->id() + " is not unique"); } - p_UI_items_map[item->id()] = item; - p_UI_items.push_back(item); + m_UI_items_map[item->id()] = item; + m_UI_items.push_back(item); } json Simulator_base::get_UI_items() const { // Get the UI items json items; - items["name"] = p_name; - for (UI_item* item : p_UI_items) { + items["name"] = m_name; + for (UI_item* item : m_UI_items) { items["UI_items"].push_back(item->to_json()); } @@ -44,16 +44,16 @@ json Simulator_base::get_UI_items() const { UI_item* Simulator_base::get_UI_item(std::string id) const { // Get a UI item by id - return p_UI_items_map.at(id); + return m_UI_items_map.at(id); } void Simulator_base::run() { // Start the timer - p_timer.setInterval(m_interval); + m_timer.setInterval(m_interval); run_at_startup(); } void Simulator_base::stop() { // Stop the simulator - p_timer.stop(); + m_timer.stop(); } \ No newline at end of file diff --git a/tools/simulator_base.hpp b/tools/simulator_base.hpp index 7204ca4..996f97c 100644 --- a/tools/simulator_base.hpp +++ b/tools/simulator_base.hpp @@ -78,9 +78,9 @@ class Simulator_base { */ virtual void run_at_startup() {}; protected: - std::string p_name; - std::vector p_UI_items; - std::map p_UI_items_map; - Timer p_timer; + std::string m_name; + std::vector m_UI_items; + std::map m_UI_items_map; + Timer m_timer; std::chrono::milliseconds m_interval; }; \ No newline at end of file diff --git a/tools/simulators/test_sim.cpp b/tools/simulators/test_sim.cpp index 4b1a436..8518971 100644 --- a/tools/simulators/test_sim.cpp +++ b/tools/simulators/test_sim.cpp @@ -3,17 +3,17 @@ Test_Sim::Test_Sim() : Simulator_base("Test_Sim"), -p_button("button", "Button", Color(Color::White), Color(Color::Black), [](std::string id) { std::cout << "Button " << id << " clicked" << std::endl; }), -p_combobox("combobox", "Combobox", Color(Color::White), Color(Color::Black), {"Option 1", "Option 2", "Option 3"}, 0, [](std::string id, std::string selected) { std::cout << "Combobox " << id << " selected " << selected << std::endl; }), -p_label("label", "Label", Color(Color::White), Color(Color::Black)), -p_checkbox("checkbox", "Checkbox", Color(Color::White), Color(Color::Black), {"Option 1", "Option 2", "Option 3"}, [](std::string id, std::vector selected) { std::cout << "Checkbox " << id << " selected " << (selected.size() > 0 ? selected[0] : "") << std::endl; }), -p_slider("slider", "Slider", Color(Color::White), Color(Color::Black), 0, 100, 50, [](std::string id, double value) { std::cout << "Slider " << id << " changed to " << value << std::endl; }) +m_button("button", "Button", Color(Color::White), Color(Color::Black), [](std::string id) { std::cout << "Button " << id << " clicked" << std::endl; }), +m_combobox("combobox", "Combobox", Color(Color::White), Color(Color::Black), {"Option 1", "Option 2", "Option 3"}, 0, [](std::string id, std::string selected) { std::cout << "Combobox " << id << " selected " << selected << std::endl; }), +m_label("label", "Label", Color(Color::White), Color(Color::Black)), +m_checkbox("checkbox", "Checkbox", Color(Color::White), Color(Color::Black), {"Option 1", "Option 2", "Option 3"}, [](std::string id, std::vector selected) { std::cout << "Checkbox " << id << " selected " << (selected.size() > 0 ? selected[0] : "") << std::endl; }), +m_slider("slider", "Slider", Color(Color::White), Color(Color::Black), 0, 100, 50, [](std::string id, double value) { std::cout << "Slider " << id << " changed to " << value << std::endl; }) { - this->add_UI_item(&this->p_button); - this->add_UI_item(&this->p_combobox); - this->add_UI_item(&this->p_label); - this->add_UI_item(&this->p_checkbox); - this->add_UI_item(&this->p_slider); + this->add_UI_item(&this->m_button); + this->add_UI_item(&this->m_combobox); + this->add_UI_item(&this->m_label); + this->add_UI_item(&this->m_checkbox); + this->add_UI_item(&this->m_slider); } void Test_Sim::timer() diff --git a/tools/simulators/test_sim.hpp b/tools/simulators/test_sim.hpp index 8b286ca..97dd002 100644 --- a/tools/simulators/test_sim.hpp +++ b/tools/simulators/test_sim.hpp @@ -7,9 +7,9 @@ class Test_Sim : public Simulator_base { void timer() override; void run_at_startup() override; private: - UI_button p_button; - UI_combobox p_combobox; - UI_label p_label; - UI_checkbox p_checkbox; - UI_slider p_slider; + UI_button m_button; + UI_combobox m_combobox; + UI_label m_label; + UI_checkbox m_checkbox; + UI_slider m_slider; };