Deprecared keyvalue ints pt2
This commit is contained in:
parent
20b344c3b6
commit
17ccd88881
@ -64,6 +64,9 @@ public:
|
||||
bool got_mouse { false };
|
||||
List* open_sublist { nullptr };
|
||||
std::string title;
|
||||
|
||||
private:
|
||||
int items;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -30,4 +30,5 @@ public:
|
||||
virtual inline void SortByZIndex() override {};
|
||||
virtual void MoveChildren() override;
|
||||
virtual void Draw(int x, int y) override;
|
||||
int columns;
|
||||
};
|
||||
|
@ -40,4 +40,5 @@ public:
|
||||
void SetCallback(ButtonCallbackFn_t callback);
|
||||
|
||||
ButtonCallbackFn_t m_pCallback;
|
||||
std::pair<int, int> padding;
|
||||
};
|
||||
|
@ -96,8 +96,8 @@ public:
|
||||
|
||||
inline virtual std::string GetTooltip() { return this->tooltip; }
|
||||
|
||||
inline virtual PositionMode GetPositionMode() { return (PositionMode)m_KeyValues->GetInt("positionmode"); }
|
||||
inline virtual void SetPositionMode(PositionMode mode) { m_KeyValues->SetInt("positionmode", mode); };
|
||||
inline virtual PositionMode GetPositionMode() { return this->positionmode; }
|
||||
inline virtual void SetPositionMode(PositionMode mode) { this->positionmode = mode; };
|
||||
|
||||
inline virtual IWidget* GetParent() { return m_pParent; }
|
||||
inline virtual void SetParent(IWidget* parent) { m_pParent = parent; }
|
||||
@ -120,6 +120,7 @@ public:
|
||||
std::string tooltip;
|
||||
std::optional<glez::rgba> bounds_color;
|
||||
int zindex;
|
||||
PositionMode positionmode;
|
||||
bool visible;
|
||||
bool always_visible;
|
||||
|
||||
|
@ -47,4 +47,6 @@ public:
|
||||
DropdownCallbackFn_t m_pDropdownCallback;
|
||||
CDropdownList* list;
|
||||
std::vector<std::string> m_values;
|
||||
int value;
|
||||
int offset;
|
||||
};
|
||||
|
@ -41,4 +41,5 @@ public:
|
||||
virtual void OnFocusLose() override;
|
||||
virtual bool ConsumesKey(CatKey key) override;
|
||||
bool capturing;
|
||||
int value;
|
||||
};
|
||||
|
@ -35,8 +35,8 @@ public:
|
||||
std::unordered_map<std::string, glez::rgba> stored_colors;
|
||||
[[deprecated]] bool GetBool(const std::string& s) { return this->stored_bools.at(s); }
|
||||
[[deprecated]] void SetBool(const std::string& s, int v) { this->stored_bools[s] = v; }
|
||||
int GetInt(const std::string& s) { return this->stored_ints.at(s); }
|
||||
void SetInt(const std::string& s, int v) { this->stored_ints[s] = v; }
|
||||
[[deprecated]] int GetInt(const std::string& s) { return this->stored_ints.at(s); }
|
||||
[[deprecated]] void SetInt(const std::string& s, int v) { this->stored_ints[s] = v; }
|
||||
float GetFloat(const std::string& s) { return this->stored_floats.at(s); }
|
||||
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); }
|
||||
|
@ -36,4 +36,5 @@ public:
|
||||
private:
|
||||
bool autosize;
|
||||
bool centered;
|
||||
std::pair<int, int> padding;
|
||||
};
|
||||
|
@ -233,8 +233,8 @@ void List::OnMouseLeave() {
|
||||
|
||||
void List::Draw(int x, int y) {
|
||||
// const auto& size = GetSize();
|
||||
glez::draw::rect_outline(x, y, 2 + Item::size_x, Props()->GetInt("items") * Item::size_y + 2, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
for (int i = 1; i < Props()->GetInt("items"); i++) {
|
||||
glez::draw::rect_outline(x, y, 2 + Item::size_x, this->items * Item::size_y + 2, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
for (int i = 1; i < this->items; i++) {
|
||||
glez::draw::line(x + 1, y + Item::size_y * i, Item::size_x, 0, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
}
|
||||
// CBaseContainer::Draw(x, y);
|
||||
@ -290,7 +290,7 @@ void List::MoveChildren() {
|
||||
accy += Item::size_y;
|
||||
j++;
|
||||
}
|
||||
Props()->SetInt("items", j);
|
||||
this->items = j;
|
||||
List* list = dynamic_cast<List*>(open_sublist);
|
||||
if (list) {
|
||||
const auto& size = list->GetSize();
|
||||
|
@ -54,7 +54,7 @@ CCVarContainer::CCVarContainer(IWidget* parent, ui::BaseVar* var)
|
||||
dd->SetCallback([this](CDropdown*, int value) {
|
||||
*static_cast<ui::Var<ui::Enum>*>(m_pVar) = value;
|
||||
});
|
||||
dd->Props()->SetInt("offset", 0 /*var->enum_type->Minimum()*/);
|
||||
dd->offset = 0 /*var->enum_type->Minimum()*/;
|
||||
m_pControl = dd;
|
||||
} break;
|
||||
case ui::BaseVar::Type::kFloat: {
|
||||
|
@ -34,12 +34,12 @@ void CMenuContainer::MoveChildren() {
|
||||
c->SetMaxSize(column_size, -1);
|
||||
y += c->GetSize().second + 2;
|
||||
}
|
||||
Props()->SetInt("columns", columns);
|
||||
this->columns = columns;
|
||||
}
|
||||
|
||||
void CMenuContainer::Draw(int x, int y) {
|
||||
CBaseContainer::Draw(x, y);
|
||||
for (int i = 0; i < Props()->GetInt("columns"); i++) {
|
||||
for (int i = 0; i < this->columns; i++) {
|
||||
glez::draw::line(x + (350 + 3) * (i + 1), y, 0, GetMaxSize().second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ void Tooltip::Draw(int x, int y) {
|
||||
static auto fgcolor = glez::rgba(200, 200, 190, 255);
|
||||
glez::draw::rect(x, y, size.first, size.second, bgcolor);
|
||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
glez::draw::string(x + Props()->GetInt("padding_x"), y + Props()->GetInt("padding_y"), GetText(), g_pGUI->GetRootWindow()->GetFont(), fgcolor, nullptr, nullptr);
|
||||
glez::draw::string(x + this->padding.first, y + this->padding.second, GetText(), g_pGUI->GetRootWindow()->GetFont(), fgcolor, nullptr, nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
virtual void Draw(int x, int y) override;
|
||||
virtual void HandleCustomEvent(std::string_view event) override;
|
||||
inline virtual PositionMode GetPositionMode() override { return PositionMode::FLOATING; }
|
||||
std::pair<int, int> padding;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ void CBaseButton::Draw(int x, int y) {
|
||||
textcolor = glez::color::white;
|
||||
}
|
||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
glez::draw::string(x + Props()->GetInt("padding_x"), y + Props()->GetInt("padding_y"), GetText().c_str(), g_pGUI->GetRootWindow()->GetFont(), textcolor, nullptr, nullptr);
|
||||
glez::draw::string(x + this->padding.first, y + this->padding.second, GetText().c_str(), g_pGUI->GetRootWindow()->GetFont(), textcolor, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void CBaseButton::OnMousePress() {
|
||||
|
@ -34,8 +34,8 @@ CDropdown::CDropdown(std::string name, IWidget* parent)
|
||||
CBaseButton::SetCallback([this](CBaseButton*) -> void {
|
||||
ShowList();
|
||||
});
|
||||
this->Props()->SetInt("value", 0);
|
||||
this->Props()->SetInt("offset", 0);
|
||||
this->value = 0;
|
||||
this->offset = 0;
|
||||
}
|
||||
|
||||
CDropdown::~CDropdown() {
|
||||
@ -60,10 +60,10 @@ std::string CDropdown::ValueName(int idx) {
|
||||
void CDropdown::Draw(int x, int y) {
|
||||
auto size = GetSize();
|
||||
std::pair<float, float> ssize;
|
||||
g_pGUI->GetRootWindow()->GetFont().stringSize(ValueName(Value() - Props()->GetInt("offset")), &ssize.first, &ssize.second);
|
||||
g_pGUI->GetRootWindow()->GetFont().stringSize(ValueName(Value() - this->offset), &ssize.first, &ssize.second);
|
||||
glez::draw::rect(x, y, size.first, size.second, Transparent(glez::color::black));
|
||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
glez::draw::string(x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, ValueName(Value() - Props()->GetInt("offset")), g_pGUI->GetRootWindow()->GetFont(), g_pGUI->GetRootWindow()->GetColor(), nullptr, nullptr);
|
||||
glez::draw::string(x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, ValueName(Value() - this->offset), g_pGUI->GetRootWindow()->GetFont(), g_pGUI->GetRootWindow()->GetColor(), nullptr, nullptr);
|
||||
std::pair<float, float> asize;
|
||||
g_pGUI->GetRootWindow()->GetFont().stringSize(">", &asize.first, &asize.second);
|
||||
glez::draw::string(x + size.first - asize.first - 2, y + (size.second - asize.second) / 2, ">", g_pGUI->GetRootWindow()->GetFont(), g_pGUI->GetRootWindow()->GetColor(), nullptr, nullptr);
|
||||
@ -74,13 +74,13 @@ void CDropdown::OnFocusLose() {
|
||||
}
|
||||
|
||||
void CDropdown::SetValueInternal(int value) {
|
||||
Props()->SetInt("value", value + Props()->GetInt("offset"));
|
||||
this->value = value + this->offset;
|
||||
if (m_pDropdownCallback)
|
||||
m_pDropdownCallback(this, value + Props()->GetInt("offset"));
|
||||
m_pDropdownCallback(this, value + this->offset);
|
||||
}
|
||||
|
||||
void CDropdown::SetValue(int value) {
|
||||
Props()->SetInt("value", value);
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
void CDropdown::ShowList() {
|
||||
@ -91,7 +91,7 @@ void CDropdown::ShowList() {
|
||||
}
|
||||
|
||||
int CDropdown::Value() {
|
||||
return Props()->GetInt("value");
|
||||
return this->value;
|
||||
}
|
||||
|
||||
int CDropdown::ValueCount() {
|
||||
|
@ -23,14 +23,14 @@
|
||||
|
||||
#include "dropdownentry.hpp"
|
||||
|
||||
CDropdownEntry::CDropdownEntry(std::string name, CDropdownList* parent, std::string text, int value)
|
||||
CDropdownEntry::CDropdownEntry(std::string name, CDropdownList* parent, std::string text, int _value)
|
||||
: CBaseButton(name, parent, text) {
|
||||
Props()->SetInt("value", value);
|
||||
this->value = _value;
|
||||
SetCallback([this](CBaseButton*) -> void {
|
||||
CDropdownList* parent = dynamic_cast<CDropdownList*>(GetParent());
|
||||
if (!parent)
|
||||
return;
|
||||
parent->SetValue(Props()->GetInt("value"));
|
||||
parent->SetValue(this->value);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
~CDropdownEntry();
|
||||
|
||||
virtual void Draw(int x, int y);
|
||||
int value;
|
||||
};
|
||||
|
||||
#endif /* CDROPDOWNENTRY_H_ */
|
||||
|
@ -25,17 +25,17 @@
|
||||
|
||||
CKeyInput::CKeyInput(std::string name, IWidget* parent)
|
||||
: CBaseWidget(name, parent) {
|
||||
Props()->SetInt("value", 0);
|
||||
this->value = 0;
|
||||
this->capturing = false;
|
||||
this->focus = false;
|
||||
}
|
||||
|
||||
CatKey CKeyInput::Value() {
|
||||
return (CatKey)Props()->GetInt("value");
|
||||
return (CatKey)this->value;
|
||||
}
|
||||
|
||||
void CKeyInput::SetValue(int value) {
|
||||
Props()->SetInt("value", value);
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
void CKeyInput::Draw(int x, int y) {
|
||||
|
@ -83,14 +83,12 @@ void CTextLabel::SetCentered(bool _centered) {
|
||||
}
|
||||
|
||||
void CTextLabel::SetPadding(int x, int y) {
|
||||
Props()->SetInt("padding_x", x);
|
||||
Props()->SetInt("padding_y", y);
|
||||
this->padding = { x, y };
|
||||
}
|
||||
|
||||
void CTextLabel::SetText(std::string text) {
|
||||
// unsigned long font_handle = Props()->GetInt("font", fonts::MENU);
|
||||
Props()->SetString("text", text.c_str());
|
||||
auto padding = std::make_pair(Props()->GetInt("padding_x"), Props()->GetInt("padding_y"));
|
||||
std::pair<float, float> size;
|
||||
g_pGUI->GetRootWindow()->GetFont().stringSize(text, &size.first, &size.second);
|
||||
if (this->autosize) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user