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

View File

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

View File

@ -32,9 +32,11 @@ typedef std::function<void(CBaseButton*)> ButtonCallbackFn_t;
class CBaseButton : public CTextLabel {
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;
void SetCallback(ButtonCallbackFn_t callback);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CCheckbox*, bool)> CheckboxCallbackFn_t;
class CCheckbox : public CBaseWidget {
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);
inline bool Value() { return this->checked; }

View File

@ -28,7 +28,9 @@ typedef std::function<void(CDropdown*, int)> DropdownCallbackFn_t;
class CDropdown : public CBaseButton {
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();
void AddValue(std::string);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CKeyInput*, CatKey)> KeyInputCallbackFn_t;
class CKeyInput : public CBaseWidget {
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();
void SetValue(int value);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CSlider*, float, float)> SliderCallbackFn_t;
class CSlider : public CBaseWidget {
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 SetStep(float step);

View File

@ -27,7 +27,9 @@ typedef std::function<void(CTextInput*, std::string, std::string)> TextInputCall
class CTextInput : public CBaseWidget {
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 Draw(int x, int y);

View File

@ -23,7 +23,9 @@
class CTextLabel : public CBaseWidget {
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);
void SetText(std::string text);

View File

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

View File

@ -23,7 +23,7 @@
#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) {
SetPadding(BUTTON_PADDING_W, BUTTON_PADDING_H);
SetText(text);

View File

@ -23,7 +23,7 @@
#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) {
SetWidth(16);
SetValue(checked);

View File

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

View File

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

View File

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

View File

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

View File

@ -60,7 +60,7 @@ static std::string WordWrap(std::string& in, int max, glez::font& font) {
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) {
this->max_size.first = 50;
this->SetPadding(3, 3);