Switched example over to CBaseContainer::Add<>()

This commit is contained in:
Rebekah 2022-04-12 13:08:55 -04:00
parent 06c82b2de7
commit 31aba367f2
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
17 changed files with 59 additions and 55 deletions

View File

@ -60,44 +60,36 @@ public:
: CBaseWindow(parent, "root_test") { : CBaseWindow(parent, "root_test") {
this->always_visible = false; this->always_visible = false;
this->hover = false; this->hover = false;
SetMaxSize(1270, 1000); this->SetMaxSize(1270, 1000);
SetPositionMode(PositionMode::FLOATING); this->SetPositionMode(PositionMode::FLOATING);
auto* titlebar = new CTitleBar(this, "Test uwu~"); this->Add<CTitleBar>("Test uwu~");
AddChild(titlebar);
// this->visible = true; // this->visible = true;
AddChild(new CTextLabel("button_label", this, "Button widget:")); this->Add<CTextLabel>("button_label", "Button widget:");
AddChild(new CBaseButton("button", this, "I'm Clickable!", [this](CBaseButton*) { this->Add<CBaseButton>("button", "I'm Clickable!", [this](CBaseButton*) {
std::cout << "Hey hey I was pressed!" << std::endl; std::cout << "Hey hey I was pressed!" << std::endl;
this->button_clicked = !this->button_clicked; this->button_clicked = !this->button_clicked;
})); });
AddChild(new CTextLabel("checkbox_label", this, "Checkbox widget:")); this->Add<CTextLabel>("checkbox_label", "Checkbox widget:");
AddChild(new CCheckbox("checkbox", this, false)); this->Add<CCheckbox>("checkbox", false);
AddChild(new CTextLabel("slider_label", this, "Slider widget:")); this->Add<CTextLabel>("slider_label", "Slider widget:");
auto* slider = new CSlider("slider", this); this->Add<CSlider>("slider")->SetStep(0.1f);
slider->SetStep(0.1f);
AddChild(slider);
AddChild(new CTextLabel("dropdown_label", this, "Dropdown widget:")); this->Add<CTextLabel>("dropdown_label", "Dropdown widget:");
auto dropdown = new CDropdown("dropdown", this); auto* dropdown = this->Add<CDropdown>("dropdown");
dropdown->AddValue("Im the cutest princess!"); dropdown->AddValue("Im the cutest princess!");
dropdown->AddValue("No I am, hmp!"); dropdown->AddValue("No I am, hmp!");
dropdown->AddValue("*doomguy noises*"); dropdown->AddValue("*doomguy noises*");
dropdown->SetSize(150, 16); dropdown->SetSize(150, 16);
AddChild(dropdown);
AddChild(new CTextLabel("text_input_label", this, "Text input widget:")); this->Add<CTextLabel>("text_input_label", "Text input widget:");
auto* text_input = new CTextInput("text_input", this); this->Add<CTextInput>("text_input")->SetValue("You can edit me!");
text_input->SetValue("You can edit me!");
AddChild(text_input);
AddChild(new CTextLabel("key_input_label", this, "Key widget:")); this->Add<CTextLabel>("key_input_label", "Key widget:");
auto key_input = new CKeyInput("key_input"); this->Add<CKeyInput>("key_input")->SetSize(78, 10);
key_input->SetSize(78, 10);
AddChild(key_input);
} }
virtual void Update() override { virtual void Update() override {
this->CBaseWindow::Update(); this->CBaseWindow::Update();
@ -149,10 +141,9 @@ int main() {
glez::end(); glez::end();
xoverlay_draw_end(); xoverlay_draw_end();
} }
auto bounds = input::GetBounds();
auto test_window = new TestWindow(canvas); auto test_window = canvas->Add<TestWindow>();
canvas->AddChild(test_window);
using namespace menu::ncc; using namespace menu::ncc;
// auto* list_menu = List::FromString(menu_list); // auto* list_menu = List::FromString(menu_list);
@ -167,29 +158,26 @@ int main() {
list_menu->SetMaxSize(1000, 1000); list_menu->SetMaxSize(1000, 1000);
list_menu->Show(); list_menu->Show();
canvas->AddChild(list_menu); canvas->AddChild(list_menu);
list_menu->SetOffset((bounds.first - 912) / 4, (bounds.second - 410) / 3);
auto* tabbedmenu = new CMenuWindow("menu_window", canvas); auto* tabbedmenu = canvas->Add<CMenuWindow>("menu_window");
tabbedmenu->SetMaxSize(912, 410); tabbedmenu->SetMaxSize(912, 410);
tabbedmenu->AddTab("aimbot", "Main"); tabbedmenu->AddTab("aimbot", "Main");
CMenuContainer* tab = tabbedmenu->GetTab("aimbot"); CMenuContainer* tab = tabbedmenu->GetTab("aimbot");
tab->AddChild(new CTextLabel("label", tab, "This is a bool!", true)); tab->Add<CTextLabel>("label", "This is a bool!", true);
tab->AddChild(new CCVarContainer(tab, &text)); tab->Add<CCVarContainer>(&text);
tabbedmenu->AddTab("esp", "Sub"); tabbedmenu->AddTab("esp", "Sub");
tabbedmenu->AddTab("esp2", "Sub2"); tabbedmenu->AddTab("esp2", "Sub2");
tabbedmenu->AddTab("esp3", "Sub3"); tabbedmenu->AddTab("esp3", "Sub3");
tabbedmenu->SetOffset((bounds.first - 912) / 2, (bounds.second - 410) / 2);
// tabbedmenu->SetOffset((draw::width - 912) / 2, (draw::height - 410) / 2); canvas->Add<ncc::Logo>()->SetOffset(500, 25);
canvas->AddChild(tabbedmenu);
auto* logo = new ncc::Logo(canvas);
logo->SetOffset(500, 25);
canvas->AddChild(logo);
canvas->AddChild(new ncc::Background()); canvas->AddChild(new ncc::Background());
for (auto& i : ui::BaseVar::GetList()) /*for (auto& i : ui::BaseVar::GetList())
printf("ui::BaseVar: %s\n", i->command_name.c_str()); printf("ui::BaseVar: %s\n", i->command_name.c_str());*/
xoverlay_show(); xoverlay_show();
while (1) { while (1) {
input::RefreshInput(); input::RefreshInput();

View File

@ -27,7 +27,9 @@ class CTitleBar;
class CMenuWindow : public CBaseWindow { class CMenuWindow : public CBaseWindow {
public: public:
CMenuWindow(std::string name, IWidget* parent); CMenuWindow(IWidget* parent, std::string name);
CMenuWindow(std::string name, IWidget* parent)
: CMenuWindow(parent, name) { }
void AddElements(); void AddElements();

View File

@ -32,9 +32,11 @@ typedef std::function<void(CBaseButton*)> ButtonCallbackFn_t;
class CBaseButton : public CTextLabel { class CBaseButton : public CTextLabel {
public: public:
CBaseButton(std::string name = "unnamed", IWidget* parent = nullptr, std::string text = "", ButtonCallbackFn_t callback = nullptr); CBaseButton(IWidget* parent, std::string name = "unnamed", std::string text = "", ButtonCallbackFn_t callback = nullptr);
CBaseButton(std::string name = "unnamed", IWidget* parent = nullptr, std::string text = "", ButtonCallbackFn_t callback = nullptr)
: CBaseButton(parent, name, text, callback) { }
virtual void Draw(int x, int y); virtual void Draw(int x, int y) override;
virtual void OnMousePress() override; virtual void OnMousePress() override;
void SetCallback(ButtonCallbackFn_t callback); void SetCallback(ButtonCallbackFn_t callback);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CCheckbox*, bool)> CheckboxCallbackFn_t;
class CCheckbox : public CBaseWidget { class CCheckbox : public CBaseWidget {
public: public:
CCheckbox(std::string name = "unnamed", IWidget* parent = nullptr, bool checked = false); CCheckbox(IWidget* parent, std::string name = "unnamed", bool checked = false);
CCheckbox(std::string name = "unnamed", IWidget* parent = nullptr, bool checked = false)
: CCheckbox(parent, name, checked) { }
void SetWidth(int width); void SetWidth(int width);
inline bool Value() { return this->checked; } inline bool Value() { return this->checked; }

View File

@ -28,7 +28,9 @@ typedef std::function<void(CDropdown*, int)> DropdownCallbackFn_t;
class CDropdown : public CBaseButton { class CDropdown : public CBaseButton {
public: public:
CDropdown(std::string name = "unnamed", IWidget* parent = nullptr); CDropdown(IWidget* parent = nullptr, std::string name = "unnamed");
CDropdown(std::string name = "unnamed", IWidget* parent = nullptr)
: CDropdown(parent, name) { }
~CDropdown(); ~CDropdown();
void AddValue(std::string); void AddValue(std::string);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CKeyInput*, CatKey)> KeyInputCallbackFn_t;
class CKeyInput : public CBaseWidget { class CKeyInput : public CBaseWidget {
public: public:
CKeyInput(std::string name = "unnamed", IWidget* parent = nullptr); CKeyInput(IWidget* parent, std::string name = "unnamed");
CKeyInput(std::string name = "unnamed", IWidget* parent = nullptr)
: CKeyInput(parent, name) { }
CatKey Value(); CatKey Value();
void SetValue(int value); void SetValue(int value);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CSlider*, float, float)> SliderCallbackFn_t;
class CSlider : public CBaseWidget { class CSlider : public CBaseWidget {
public: public:
CSlider(std::string name = "", IWidget* parent = nullptr); CSlider(IWidget* parent, std::string name = "");
CSlider(std::string name = "", IWidget* parent = nullptr)
: CSlider(parent, name) { }
void Setup(float min, float max); void Setup(float min, float max);
void SetStep(float step); void SetStep(float step);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CTextInput*, std::string, std::string)> TextInputCall
class CTextInput : public CBaseWidget { class CTextInput : public CBaseWidget {
public: public:
CTextInput(std::string name = "unnamed", IWidget* parent = nullptr); CTextInput(IWidget* parent, std::string name = "unnamed");
CTextInput(std::string name = "unnamed", IWidget* parent = nullptr)
: CTextInput(parent, name) { }
virtual void OnKeyPress(CatKey key, bool repeat); virtual void OnKeyPress(CatKey key, bool repeat);
virtual void Draw(int x, int y); virtual void Draw(int x, int y);

View File

@ -23,7 +23,9 @@
class CTextLabel : public CBaseWidget { class CTextLabel : public CBaseWidget {
public: public:
CTextLabel(std::string name, IWidget* parent, std::string text = "", bool centered = false); CTextLabel(IWidget* parent, std::string name, std::string text = "", bool centered = false);
CTextLabel(std::string name, IWidget* parent, std::string text = "", bool centered = false)
: CTextLabel(parent, name, text, centered) { }
CTextLabel(std::string name = "unnamed", bool centered = false); CTextLabel(std::string name = "unnamed", bool centered = false);
void SetText(std::string text); void SetText(std::string text);

View File

@ -14,7 +14,7 @@
#include "gui/widgets/titlebar.hpp" #include "gui/widgets/titlebar.hpp"
CMenuWindow::CMenuWindow(std::string name, IWidget* parent) CMenuWindow::CMenuWindow(IWidget* parent, std::string name)
: CBaseWindow(parent, name) { : CBaseWindow(parent, name) {
m_pList = new CMenuList("list", this); m_pList = new CMenuList("list", this);
AddChild(m_pList); AddChild(m_pList);

View File

@ -23,7 +23,7 @@
#include "gui/canvas.hpp" #include "gui/canvas.hpp"
CBaseButton::CBaseButton(std::string name, IWidget* parent, std::string text, ButtonCallbackFn_t callback) CBaseButton::CBaseButton(IWidget* parent, std::string name, std::string text, ButtonCallbackFn_t callback)
: CTextLabel(name, parent, text) { : CTextLabel(name, parent, text) {
SetPadding(BUTTON_PADDING_W, BUTTON_PADDING_H); SetPadding(BUTTON_PADDING_W, BUTTON_PADDING_H);
SetText(text); SetText(text);

View File

@ -23,7 +23,7 @@
#include "gui/widgets/checkbox.hpp" #include "gui/widgets/checkbox.hpp"
CCheckbox::CCheckbox(std::string name, IWidget* parent, bool checked) CCheckbox::CCheckbox(IWidget* parent, std::string name, bool checked)
: CBaseWidget(name, parent) { : CBaseWidget(name, parent) {
SetWidth(16); SetWidth(16);
SetValue(checked); SetValue(checked);

View File

@ -23,7 +23,7 @@
#include "gui/widgets/dropdown.hpp" #include "gui/widgets/dropdown.hpp"
#include "gui/widgets/dropdownlist.hpp" #include "gui/widgets/dropdownlist.hpp"
CDropdown::CDropdown(std::string name, IWidget* parent) CDropdown::CDropdown(IWidget* parent, std::string name)
: CBaseButton(name, parent) { : CBaseButton(name, parent) {
list = new CDropdownList(name + "_list", this); list = new CDropdownList(name + "_list", this);
this->GetCanvas()->AddChild(list); this->GetCanvas()->AddChild(list);

View File

@ -23,7 +23,7 @@
#include "gui/widgets/keyinput.hpp" #include "gui/widgets/keyinput.hpp"
CKeyInput::CKeyInput(std::string name, IWidget* parent) CKeyInput::CKeyInput(IWidget* parent, std::string name)
: CBaseWidget(name, parent) { : CBaseWidget(name, parent) {
this->value = 0; this->value = 0;
this->capturing = false; this->capturing = false;

View File

@ -24,7 +24,7 @@
#include "gui/widgets/slider.hpp" #include "gui/widgets/slider.hpp"
CSlider::CSlider(std::string name, IWidget* parent) CSlider::CSlider(IWidget* parent, std::string name)
: CBaseWidget(name, parent) { : CBaseWidget(name, parent) {
Setup(0.0f, 1.0f); Setup(0.0f, 1.0f);
SetSize(80, 16); SetSize(80, 16);

View File

@ -23,7 +23,7 @@
#include "gui/widgets/textinput.hpp" #include "gui/widgets/textinput.hpp"
CTextInput::CTextInput(std::string name, IWidget* parent) CTextInput::CTextInput(IWidget* parent, std::string name)
: CBaseWidget(name, parent) { : CBaseWidget(name, parent) {
this->value = ""; this->value = "";
this->focus = false; this->focus = false;

View File

@ -60,7 +60,7 @@ static std::string WordWrap(std::string& in, int max, glez::font& font) {
return result.str(); return result.str();
} }
CTextLabel::CTextLabel(std::string name, IWidget* parent, std::string text, bool centered) CTextLabel::CTextLabel(IWidget* parent, std::string name, std::string text, bool centered)
: CBaseWidget(name, parent) { : CBaseWidget(name, parent) {
this->max_size.first = 50; this->max_size.first = 50;
this->SetPadding(3, 3); this->SetPadding(3, 3);