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_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);
}
}
+1 -1
View File
@@ -15,5 +15,5 @@ class UI_button : public UI_item
void click() const override;
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"
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_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<bool> UI_checkbox::selected() const
{
return p_selected;
return m_selected;
}
std::vector<std::string> UI_checkbox::selected_text() const
{
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;
@@ -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;
}
+2 -2
View File
@@ -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<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_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;
}
+2 -2
View File
@@ -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<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"
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;
}
+6 -6
View File
@@ -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;
};
+14 -14
View File
@@ -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<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)
@@ -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;
}
+4 -4
View File
@@ -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<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"
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_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;
}
+1 -5
View File
@@ -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<std::string> p_options;
// std::vector<size_t> p_selected_multi;
// size_t p_selected;
// void (*p_on_change) (std::string id, int selected);
std::vector<std::string> m_options;
};