diff --git a/include/libpdraw/gui/widgets/keyvalues.hpp b/include/libpdraw/gui/widgets/keyvalues.hpp index e31378c..b479b35 100644 --- a/include/libpdraw/gui/widgets/keyvalues.hpp +++ b/include/libpdraw/gui/widgets/keyvalues.hpp @@ -39,11 +39,11 @@ public: [[deprecated]] void SetInt(const std::string& s, int v) { this->stored_ints[s] = v; } [[deprecated]] float GetFloat(const std::string& s) { return this->stored_floats.at(s); } [[deprecated]] void SetFloat(const std::string& s, float v) { this->stored_floats[s] = v; } - std::string GetString(const std::string& s) { return this->stored_strings.at(s); } - void SetString(const std::string& s, const std::string& v) { this->stored_strings[s] = v; } - glez::rgba GetColor(const std::string& s) { return this->stored_colors.at(s); } - void SetColor(const std::string& s, glez::rgba v) { this->stored_colors[s] = v; } - bool FindKey(const std::string& s) { + [[deprecated]] std::string GetString(const std::string& s) { return this->stored_strings.at(s); } + [[deprecated]] void SetString(const std::string& s, const std::string& v) { this->stored_strings[s] = v; } + [[deprecated]] glez::rgba GetColor(const std::string& s) { return this->stored_colors.at(s); } + [[deprecated]] void SetColor(const std::string& s, glez::rgba v) { this->stored_colors[s] = v; } + [[deprecated]] bool FindKey(const std::string& s) { { auto find = stored_bools.find(s); if (find != stored_bools.end()) @@ -71,7 +71,34 @@ public: } return false; } - bool IsEmpty(const std::string& s) { - return !this->FindKey(s); + [[deprecated]] bool IsEmpty(const std::string& s) { + return ![this](const std::string& s) { + { + auto find = stored_bools.find(s); + if (find != stored_bools.end()) + return true; + } + { + auto find = stored_ints.find(s); + if (find != stored_ints.end()) + return true; + } + { + auto find = stored_floats.find(s); + if (find != stored_floats.end()) + return true; + } + { + auto find = stored_strings.find(s); + if (find != stored_strings.end()) + return true; + } + { + auto find = stored_colors.find(s); + if (find != stored_colors.end()) + return true; + } + return false; + }(s); } }; diff --git a/include/libpdraw/gui/widgets/textinput.hpp b/include/libpdraw/gui/widgets/textinput.hpp index 73ed756..fab772f 100644 --- a/include/libpdraw/gui/widgets/textinput.hpp +++ b/include/libpdraw/gui/widgets/textinput.hpp @@ -41,4 +41,5 @@ public: void SetValue(std::string value); TextInputCallbackFn_t m_pCallback; + std::string value; }; diff --git a/include/libpdraw/gui/widgets/textlabel.hpp b/include/libpdraw/gui/widgets/textlabel.hpp index b22be56..909cbb5 100644 --- a/include/libpdraw/gui/widgets/textlabel.hpp +++ b/include/libpdraw/gui/widgets/textlabel.hpp @@ -37,4 +37,5 @@ private: bool autosize; bool centered; std::pair padding; + std::string text; }; diff --git a/src/gui/tabbedmenu/menulist.cpp b/src/gui/tabbedmenu/menulist.cpp index 866c509..0f79304 100644 --- a/src/gui/tabbedmenu/menulist.cpp +++ b/src/gui/tabbedmenu/menulist.cpp @@ -31,9 +31,9 @@ CMenuList::CMenuList(std::string name, CMenuWindow* parent) void CMenuList::AddEntry(std::string id, std::string name) { CMenuListEntry* entry = new CMenuListEntry("entry_" + id, this, id); entry->SetText(name); - entry->SetCallback([this](CBaseButton* thisptr) { + entry->SetCallback([entry](CBaseButton* thisptr) { CMenuWindow* window = dynamic_cast(thisptr->GetParent()->GetParent()); - window->SelectTab(thisptr->Props()->GetString("entry")); + window->SelectTab(entry->entry); }); AddChild(entry); } diff --git a/src/gui/tabbedmenu/menulistentry.cpp b/src/gui/tabbedmenu/menulistentry.cpp index c05214d..fb914d0 100644 --- a/src/gui/tabbedmenu/menulistentry.cpp +++ b/src/gui/tabbedmenu/menulistentry.cpp @@ -26,7 +26,7 @@ CMenuListEntry::CMenuListEntry(std::string name, CMenuList* parent, std::string entry) : CBaseButton(name, parent, entry) { - Props()->SetString("entry", entry.c_str()); + this->entry = entry; } void CMenuListEntry::SetMaxSize(int x, int y) { diff --git a/src/gui/tabbedmenu/menulistentry.hpp b/src/gui/tabbedmenu/menulistentry.hpp index 17b4a77..d134d1e 100644 --- a/src/gui/tabbedmenu/menulistentry.hpp +++ b/src/gui/tabbedmenu/menulistentry.hpp @@ -31,4 +31,7 @@ public: virtual void SetMaxSize(int x, int y) override; virtual void Draw(int x, int y) override; + +public: + std::string entry; }; diff --git a/src/gui/widgets/textinput.cpp b/src/gui/widgets/textinput.cpp index 5b7fd80..aac569d 100644 --- a/src/gui/widgets/textinput.cpp +++ b/src/gui/widgets/textinput.cpp @@ -26,7 +26,7 @@ CTextInput::CTextInput(std::string name, IWidget* parent) : CBaseWidget(name, parent) { - this->Props()->SetString("value", ""); + this->value = ""; this->focus = false; this->SetMaxWidth(8); } @@ -42,14 +42,14 @@ void CTextInput::SetMaxWidth(int width) { } std::string CTextInput::Value() { - return std::string(Props()->GetString("value")); + return this->value; } void CTextInput::SetValue(std::string value) { std::string oldv = Value(); if (m_pCallback) m_pCallback(this, oldv, value); - Props()->SetString("value", value.c_str()); + this->value = value; } void CTextInput::Draw(int x, int y) { diff --git a/src/gui/widgets/textlabel.cpp b/src/gui/widgets/textlabel.cpp index df5b2b6..ae753a1 100644 --- a/src/gui/widgets/textlabel.cpp +++ b/src/gui/widgets/textlabel.cpp @@ -88,7 +88,7 @@ void CTextLabel::SetPadding(int x, int y) { void CTextLabel::SetText(std::string text) { // unsigned long font_handle = Props()->GetInt("font", fonts::MENU); - Props()->SetString("text", text.c_str()); + this->text = text; std::pair size; g_pGUI->GetRootWindow()->GetFont().stringSize(text, &size.first, &size.second); if (this->autosize) { @@ -102,14 +102,14 @@ void CTextLabel::SetText(std::string text) { std::pair size2; g_pGUI->GetRootWindow()->GetFont().stringSize(txt, &size2.first, &size2.second); SetSize(size2.first + padding.first * 2, size2.second + padding.second * 2); - Props()->SetString("text", txt); + this->text = txt; } } } std::string CTextLabel::GetText() { // return std::string(Props()->GetString("text", "")); - return std::string(Props()->GetString("text")); + return this->text; } void CTextLabel::Draw(int x, int y) {