Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combobox #108

Open
GLadiator279 opened this issue Jul 10, 2021 · 4 comments
Open

Combobox #108

GLadiator279 opened this issue Jul 10, 2021 · 4 comments

Comments

@GLadiator279
Copy link

GLadiator279 commented Jul 10, 2021

I saw a post here that a person cannot make a combobox. I decided to try to do it, and I succeeded.
I am far from being a pro, so yes, semi-pasted from xy0.

I have put the code on pastebin as at the moment the code paste on github is broken.

framework.cpp
https://pastebin.com/ucsgxWxC

framework.hpp
https://pastebin.com/79evBbjS

How to use

Create a string array and an integer variable in variables.hpp
inline std::vector<std::string> box_type_name { "Custom color", "White color" }; inline int box_type = 0;
Add the item to menu.cpp.
menu_framework::combo_box(x + 120, y + 150, x + 260, watermark_font, "Box type", variables::visuals::esp::box_type_name, &variables::visuals::esp::box_type);

Don't swear if the code isn't very good, thanks.

@GLadiator279
Copy link
Author

You do not need to create a string variable, you can write the names in the element call, for example, like this:
menu_framework::combo_box(x + 120, y + 165, x + 260, watermark_font, "Box type", { "1", "2", "3" }, &variables::visuals::esp::box_type);

@judahmane
Copy link

penis fart

@st3ph4nnn
Copy link

st3ph4nnn commented Aug 9, 2021

Sorry for being late.
If u atleast paste it try to optimize it.
Your whole code can be shortened to 20 lines and have it work the same way.

bool open = false;
static bool selected_opened = false;
static bool rest;
static std::string name_selected;

if ((cursor.x > position) && (cursor.x < position + w) && (cursor.y > y) && (cursor.y < y + h) && GetAsyncKeyState(VK_LBUTTON) & 1) {
	name_selected = string;
	if (!rest)
		selected_opened = !selected_opened;
	rest = true;
}
else
	rest = false;

if (name_selected == string)
	open = selected_opened;

this can be 3 lines and work the same, literally.
` static bool open = false;

if (get_pos(x, y, w, h))
	open = !open;`

only my preference but this can be out of this if statement
if (open) { render::draw_filled_rect(position + 2, y - 1, w, 15 + (size * 15), color(36, 36, 36, 255));

This can also be shortened to 1 line and much optimized.
if (i == *values) { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white()); } else { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white(100)); }

render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);

Look, i just made it better for you all

    static bool open = false;

if (get_pos(x, y, w, h))
	open = !open;

std::size_t size = elements.size();

render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt);
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color);
render::text(x + ( w / 2 ), y + 2, font, elements[*current], true, text_color);
render::text(x + w + 10, y + 1, font, text, false, text_color);

if (open) {
	for (int i = 0; i < size; i++) {
		if (get_pos(x, y, w, h + 15 + (i * 15))) {
			*current = i;
			return;
		}

		render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);
	}
}

@GLadiator279
Copy link
Author

Sorry for being late.
If u atleast paste it try to optimize it.
Your whole code can be shortened to 20 lines and have it work the same way.

bool open = false;
static bool selected_opened = false;
static bool rest;
static std::string name_selected;

if ((cursor.x > position) && (cursor.x < position + w) && (cursor.y > y) && (cursor.y < y + h) && GetAsyncKeyState(VK_LBUTTON) & 1) {
	name_selected = string;
	if (!rest)
		selected_opened = !selected_opened;
	rest = true;
}
else
	rest = false;

if (name_selected == string)
	open = selected_opened;

this can be 3 lines and work the same, literally.
` static bool open = false;

if (get_pos(x, y, w, h))
	open = !open;`

only my preference but this can be out of this if statement
if (open) { render::draw_filled_rect(position + 2, y - 1, w, 15 + (size * 15), color(36, 36, 36, 255));

This can also be shortened to 1 line and much optimized.
if (i == *values) { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white()); } else { render::text(position + 7, (y - 1) + 15 + (i * 15), font, elements[i].c_str(), false, color::white(100)); }

render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);

Look, i just made it better for you all

    static bool open = false;

if (get_pos(x, y, w, h))
	open = !open;

std::size_t size = elements.size();

render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt);
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color);
render::text(x + ( w / 2 ), y + 2, font, elements[*current], true, text_color);
render::text(x + w + 10, y + 1, font, text, false, text_color);

if (open) {
	for (int i = 0; i < size; i++) {
		if (get_pos(x, y, w, h + 15 + (i * 15))) {
			*current = i;
			return;
		}

		render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle);
	}
}

Good job, thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants