You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
since many people ask for it and most of the sources released here are not proper, i thought i would share what i made for myself.
i've commented the code so if anyone doesnt understand they can learn hopefully. there's a little "anti paste" the function get_pos() but if you have enough brain you should figure what it does
combobox:
void gui::combobox(std::string text, int x, int y, int w, int h, unsigned long font, const std::vector<std::string> elements, int* current) {
static bool open = false; // if we dont use "static" it wont stay opened.
if (get_pos(x, y, w, h)) // figure this yourself
open = !open; // flip the bool.
std::size_t size = elements.size(); // get the array size, so we can loop thru it
render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt); // increasing the h if its opened, we could also do the same with Y and render more rectangles but nah
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color); // increasing the h if its opened, we could also do the same with Y and render more rectangles but nah
render::text(x + ( w / 2 ), y + 2, font, elements[*current], true, text_color); // render the item selected.
render::text(x + w + 10, y + 1, font, text, false, text_color); // the label
if (open) {
for (int i = 0; i < size; i++) { // loop thru the array
if (get_pos(x, y, w, h + 15 + (i * 15))) { // figure get_pos yourself.
*current = i; // set the current item to i, basically the element u click.
return;
}
render::text(x + ( w / 2 ), y + 15 + (i * 15), font, elements[i], true, i == *current ? active : idle); // render all the elements
}
}
multicombobox (also has a little add on feature)
void gui::multi_combobox(std::string text, int x, int y, int w, int h, unsigned long font, const std::vector<std::string> elements, bool* item) {
static bool open = false; // if we dont use "static" it wont stay opened.
if (get_pos(x, y, w, h)) // figure this yourself
open = !open; // flip the bool.
std::size_t size = elements.size();// get the array size, so we can loop thru it
render::draw_filled_rect(x + 2, y - 1, w, open ? 15 + (size * 15) : h, groupbox_background_alt); // draw some stuff, as usual we use the height and no the y cuz yes
render::draw_outline(x + 2, y - 1, w, open ? 15 + (size * 15) : h, outline_color); // draw some stuff, as usual we use the height and no the y cuz yes
// nice little feature i thought of, feel free to use it lol
std::string display;
for (int i = 0; i < size; i++) {
if (item[i]) {
if (!(render::get_text_size(font, display).x > w / 1.5))
display += elements[i] + "; ";
else
display = elements[i] + "; ...";
}
}
// text rendering
render::text(x + (w / 2), y + 2, font, display.empty() ? "nothing" : display, true, text_color); // if the display string is empty, render "nothing" else render display.
render::text(x + w + 10, y + 1, font, text, false, text_color); // label
if (open) {
for (int i = 0; i < size; i++) { // loop thru the array
if (get_pos(x, y, w, h + 15 + (i * 15))) // figure get_pos yourself
item[i] = !item[i]; // since we use a bool array, we just flip the corresponding bool in that array
render::text(x + (w / 2), y + 15 + (i * 15), font, elements[i], true, item[i] == true ? active : idle); // render the elements
}
}
since many people ask for it and most of the sources released here are not proper, i thought i would share what i made for myself.
i've commented the code so if anyone doesnt understand they can learn hopefully.
there's a little "anti paste" the function get_pos() but if you have enough brain you should figure what it does
combobox:
multicombobox (also has a little add on feature)
example use of it:
inline int main_combo{0}; inline bool test[3] = { false, false, false };
gui::combobox("cadua is awesome", variables::menu::x + 15, variables::menu::y + 110, 120, 20, render::fonts::menu_font, { "yess", "noo" }, &main_combo); gui::multi_combobox("tommy i love you", variables::menu::x + 15, variables::menu::y + 160, 120, 20, render::fonts::menu_font, { "what de fok", "no what", "wait" }, test);
screenshots:
The text was updated successfully, but these errors were encountered: