Rename all member functions from p_ to m_

This commit is contained in:
2024-08-23 16:11:49 +02:00
parent b0b3855c6b
commit 864f99a359
16 changed files with 124 additions and 128 deletions
+3 -3
View File
@@ -3,7 +3,7 @@
UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color, std::function<void(std::string)> on_click) UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color, std::function<void(std::string)> on_click)
: UI_item(id, UI_BUTTON_TYPE, text, 12, fg_color, bg_color) : 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) UI_button::UI_button(const json& j)
@@ -25,8 +25,8 @@ json UI_button::to_json() const
void UI_button::click() 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);
} }
} }
+1 -1
View File
@@ -15,5 +15,5 @@ class UI_button : public UI_item
void click() const override; void click() const override;
private: private:
std::function<void(std::string)> p_on_click = nullptr; std::function<void(std::string)> m_on_click = nullptr;
}; };
+18 -18
View File
@@ -1,41 +1,41 @@
#include "UI_checkbox.hpp" #include "UI_checkbox.hpp"
UI_checkbox::UI_checkbox() 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<std::string> options, std::function<void(std::string, std::vector<std::string>)> on_change) UI_checkbox::UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options, std::function<void(std::string, std::vector<std::string>)> 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_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); from_json(j);
} }
void UI_checkbox::toggle_selected(size_t selected) void UI_checkbox::toggle_selected(size_t selected)
{ {
if (selected >= p_options.size()) if (selected >= m_options.size())
return; return;
p_selected[selected] = !p_selected[selected]; m_selected[selected] = !m_selected[selected];
if (p_on_change != nullptr) 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) 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); toggle_selected(i);
return; return;
@@ -45,17 +45,17 @@ void UI_checkbox::toggle_selected(std::string selected)
std::vector<bool> UI_checkbox::selected() const std::vector<bool> UI_checkbox::selected() const
{ {
return p_selected; return m_selected;
} }
std::vector<std::string> UI_checkbox::selected_text() const std::vector<std::string> UI_checkbox::selected_text() const
{ {
std::vector<std::string> selected_text; std::vector<std::string> 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; return selected_text;
@@ -67,10 +67,10 @@ void UI_checkbox::from_json(const json& j)
if (j.contains("selected")) if (j.contains("selected"))
{ {
p_selected.clear(); m_selected.clear();
for (auto selected : j["selected"]) 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 UI_checkbox::to_json() const
{ {
json j = UI_x_boxes::to_json(); json j = UI_x_boxes::to_json();
j["selected"] = p_selected; j["selected"] = m_selected;
return j; return j;
} }
+2 -2
View File
@@ -20,7 +20,7 @@ class UI_checkbox : public UI_x_boxes
void from_json(const json& j) override; void from_json(const json& j) override;
json to_json() const override; json to_json() const override;
private: private:
std::vector<bool> p_selected; std::vector<bool> m_selected;
std::function<void(std::string, std::vector<std::string>)> p_on_change; std::function<void(std::string, std::vector<std::string>)> m_on_change;
}; };
+11 -11
View File
@@ -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<std::string> options, size_t selected, std::function<void(std::string, std::string)> on_change) UI_combobox::UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected, std::function<void(std::string, std::string)> 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_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); from_json(j);
} }
void UI_combobox::set_selected(size_t selected) void UI_combobox::set_selected(size_t selected)
{ {
if (selected == p_selected) if (selected == m_selected)
return; return;
p_selected = selected; m_selected = selected;
if (p_on_change != nullptr) 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) 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); set_selected(i);
return; return;
@@ -41,12 +41,12 @@ void UI_combobox::set_selected(std::string selected)
size_t UI_combobox::selected() const size_t UI_combobox::selected() const
{ {
return p_selected; return m_selected;
} }
std::string UI_combobox::selected_text() const 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) 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 UI_combobox::to_json() const
{ {
json j = UI_x_boxes::to_json(); json j = UI_x_boxes::to_json();
j["selected"] = p_options[p_selected]; j["selected"] = m_options[m_selected];
return j; return j;
} }
+2 -2
View File
@@ -21,7 +21,7 @@ class UI_combobox : public UI_x_boxes
void from_json(const json& j) override; void from_json(const json& j) override;
json to_json() const override; json to_json() const override;
private: private:
size_t p_selected; size_t m_selected;
std::function<void(std::string, std::string)> p_on_change; std::function<void(std::string, std::string)> m_on_change;
}; };
+28 -28
View File
@@ -1,12 +1,12 @@
#include "UI_item.hpp" #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) 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) 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 std::string UI_item::id() const
{ {
return p_id; return m_id;
} }
std::string UI_item::type() const std::string UI_item::type() const
{ {
return p_type; return m_type;
} }
bool UI_item::is_type(json j) bool UI_item::is_type(json j)
@@ -31,59 +31,59 @@ bool UI_item::is_type(json j)
{ {
return false; return false;
} }
return j.at("type") == p_type; return j.at("type") == m_type;
} }
void UI_item::set_text(std::string text) 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 std::string UI_item::text() const
{ {
return p_text; return m_text;
} }
void UI_item::set_text_size(uint8_t text_size) 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 uint8_t UI_item::text_size() const
{ {
return p_text_size; return m_text_size;
} }
void UI_item::set_fg_color(Color fg_color) 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 Color UI_item::fg_color() const
{ {
return p_fg_color; return m_fg_color;
} }
void UI_item::set_bg_color(Color bg_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 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)) if (!is_type(j))
return; return;
j.at("id").get_to(p_id); j.at("id").get_to(m_id);
j.at("text").get_to(p_text); j.at("text").get_to(m_text);
j.at("text_size").get_to(p_text_size); j.at("text_size").get_to(m_text_size);
std::string color; std::string color;
j.at("fg_color").get_to(color); j.at("fg_color").get_to(color);
p_fg_color = Color(color); m_fg_color = Color(color);
color.clear(); color.clear();
j.at("bg_color").get_to(color); j.at("bg_color").get_to(color);
p_bg_color = Color(color); m_bg_color = Color(color);
} }
json UI_item::to_json() const json UI_item::to_json() const
{ {
json j; json j;
j["id"] = p_id; j["id"] = m_id;
j["type"] = p_type; j["type"] = m_type;
j["text"] = p_text; j["text"] = m_text;
j["text_size"] = p_text_size; j["text_size"] = m_text_size;
j["fg_color"] = p_fg_color.to_hex(); j["fg_color"] = m_fg_color.to_hex();
j["bg_color"] = p_bg_color.to_hex(); j["bg_color"] = m_bg_color.to_hex();
return j; return j;
} }
+6 -6
View File
@@ -39,10 +39,10 @@ class UI_item {
virtual void set_value(double value) {UNUSED(value);}; virtual void set_value(double value) {UNUSED(value);};
protected: protected:
std::string p_id; std::string m_id;
std::string p_type; std::string m_type;
std::string p_text; std::string m_text;
uint8_t p_text_size; uint8_t m_text_size;
Color p_fg_color; Color m_fg_color;
Color p_bg_color; Color m_bg_color;
}; };
+14 -14
View File
@@ -1,9 +1,9 @@
#include "UI_slider.hpp" #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<void(std::string, double)> on_change) UI_slider::UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, std::function<void(std::string, double)> 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) 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) void UI_slider::set_value(double value)
{ {
if (value < p_min || value > p_max) if (value < m_min || value > m_max)
return; return;
if (value == p_value) if (value == m_value)
return; return;
if (p_on_change != nullptr) if (m_on_change != nullptr)
{ {
this->p_value = value; this->m_value = value;
p_on_change(p_id, value); m_on_change(m_id, value);
} }
} }
double UI_slider::value() const double UI_slider::value() const
{ {
return p_value; return m_value;
} }
void UI_slider::from_json(const json& j) void UI_slider::from_json(const json& j)
{ {
UI_item::from_json(j); UI_item::from_json(j);
this->p_min = j["min"]; this->m_min = j["min"];
this->p_max = j["max"]; this->m_max = j["max"];
this->p_value = j["value"]; this->m_value = j["value"];
} }
json UI_slider::to_json() const json UI_slider::to_json() const
{ {
json j = UI_item::to_json(); json j = UI_item::to_json();
j["min"] = this->p_min; j["min"] = this->m_min;
j["max"] = this->p_max; j["max"] = this->m_max;
j["value"] = this->p_value; j["value"] = this->m_value;
return j; return j;
} }
+4 -4
View File
@@ -15,9 +15,9 @@ class UI_slider : public UI_item
void from_json(const json& j) override; void from_json(const json& j) override;
json to_json() const override; json to_json() const override;
private: private:
double p_min; double m_min;
double p_max; double m_max;
double p_value; double m_value;
std::function<void(std::string, double)> p_on_change; std::function<void(std::string, double)> m_on_change;
}; };
+5 -5
View File
@@ -1,12 +1,12 @@
#include "UI_x_boxes.hpp" #include "UI_x_boxes.hpp"
UI_x_boxes::UI_x_boxes(std::string type) 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<std::string> options) UI_x_boxes::UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color, std::vector<std::string> 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); UI_item::from_json(j);
if (j.contains("options")) if (j.contains("options"))
{ {
this->p_options.clear(); this->m_options.clear();
for (auto option : j["options"]) 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 UI_x_boxes::to_json() const
{ {
json j = UI_item::to_json(); json j = UI_item::to_json();
j["options"] = this->p_options; j["options"] = this->m_options;
return j; return j;
} }
+1 -5
View File
@@ -11,9 +11,5 @@ class UI_x_boxes : public UI_item
void from_json(const json& j) override; void from_json(const json& j) override;
json to_json() const override; json to_json() const override;
protected: protected:
std::vector<std::string> p_options; std::vector<std::string> m_options;
// std::vector<size_t> p_selected_multi;
// size_t p_selected;
// void (*p_on_change) (std::string id, int selected);
}; };
+10 -10
View File
@@ -1,19 +1,19 @@
#include "simulator_base.hpp" #include "simulator_base.hpp"
Simulator_base::Simulator_base(std::string name, std::chrono::milliseconds interval) 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 { std::string Simulator_base::name() const {
// Get the name of the simulator // Get the name of the simulator
return p_name; return m_name;
} }
bool Simulator_base::is_ui_id_unique(std::string id) const { bool Simulator_base::is_ui_id_unique(std::string id) const {
// Check if the UI name is unique // 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) { if (item->id() == id) {
return false; return false;
} }
@@ -27,15 +27,15 @@ void Simulator_base::add_UI_item(UI_item* item) {
if (is_ui_id_unique(item->id()) == false) { if (is_ui_id_unique(item->id()) == false) {
throw std::runtime_error("UI item id " + item->id() + " is not unique"); throw std::runtime_error("UI item id " + item->id() + " is not unique");
} }
p_UI_items_map[item->id()] = item; m_UI_items_map[item->id()] = item;
p_UI_items.push_back(item); m_UI_items.push_back(item);
} }
json Simulator_base::get_UI_items() const { json Simulator_base::get_UI_items() const {
// Get the UI items // Get the UI items
json items; json items;
items["name"] = p_name; items["name"] = m_name;
for (UI_item* item : p_UI_items) { for (UI_item* item : m_UI_items) {
items["UI_items"].push_back(item->to_json()); 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 { UI_item* Simulator_base::get_UI_item(std::string id) const {
// Get a UI item by id // Get a UI item by id
return p_UI_items_map.at(id); return m_UI_items_map.at(id);
} }
void Simulator_base::run() { void Simulator_base::run() {
// Start the timer // Start the timer
p_timer.setInterval(m_interval); m_timer.setInterval(m_interval);
run_at_startup(); run_at_startup();
} }
void Simulator_base::stop() { void Simulator_base::stop() {
// Stop the simulator // Stop the simulator
p_timer.stop(); m_timer.stop();
} }
+4 -4
View File
@@ -78,9 +78,9 @@ class Simulator_base {
*/ */
virtual void run_at_startup() {}; virtual void run_at_startup() {};
protected: protected:
std::string p_name; std::string m_name;
std::vector<UI_item*> p_UI_items; std::vector<UI_item*> m_UI_items;
std::map<std::string, UI_item*> p_UI_items_map; std::map<std::string, UI_item*> m_UI_items_map;
Timer p_timer; Timer m_timer;
std::chrono::milliseconds m_interval; std::chrono::milliseconds m_interval;
}; };
+10 -10
View File
@@ -3,17 +3,17 @@
Test_Sim::Test_Sim() : Test_Sim::Test_Sim() :
Simulator_base("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; }), m_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; }), 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; }),
p_label("label", "Label", Color(Color::White), Color(Color::Black)), m_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<std::string> selected) { std::cout << "Checkbox " << id << " selected " << (selected.size() > 0 ? selected[0] : "") << std::endl; }), m_checkbox("checkbox", "Checkbox", Color(Color::White), Color(Color::Black), {"Option 1", "Option 2", "Option 3"}, [](std::string id, std::vector<std::string> 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_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->m_button);
this->add_UI_item(&this->p_combobox); this->add_UI_item(&this->m_combobox);
this->add_UI_item(&this->p_label); this->add_UI_item(&this->m_label);
this->add_UI_item(&this->p_checkbox); this->add_UI_item(&this->m_checkbox);
this->add_UI_item(&this->p_slider); this->add_UI_item(&this->m_slider);
} }
void Test_Sim::timer() void Test_Sim::timer()
+5 -5
View File
@@ -7,9 +7,9 @@ class Test_Sim : public Simulator_base {
void timer() override; void timer() override;
void run_at_startup() override; void run_at_startup() override;
private: private:
UI_button p_button; UI_button m_button;
UI_combobox p_combobox; UI_combobox m_combobox;
UI_label p_label; UI_label m_label;
UI_checkbox p_checkbox; UI_checkbox m_checkbox;
UI_slider p_slider; UI_slider m_slider;
}; };