Repository navigation
add_dropdown
Daniel edited this page Oct 1, 2021
·
7 revisions
The add_dropdown function will add a dropdown list to the ui handler, add_dropdown does not return the FUI_Element* related to the dropdown.
add_dropdown has two different implementations
add_dropdown(
const std::string& identifier,
const std::string& text,
olc::vi2d position,
olc::vi2d size
);
add_dropdown(
const std::string& parent_id,
const std::string& identifier,
const std::string& text,
olc::vi2d position,
olc::vi2d size
);Example usage for dropdown with a parent
// create the UI handler
olc::FrostUI ui;
// create a window
ui.create_window("window1", "TITLE HERE", { 10, 10 }, { 300, 200 });
// create dropdown while specifying the parent_id manually
ui.add_dropdown("window1", "dropdown1", "Example Dropdown", { 10, 10 }, { 100, 20 });
// a dropdown list doesn't have any parameter to add items. You have to use member functions of the element
auto dropdown = ui.find_element("dropdown1");
// once you have the element of said dropdown you can run the add_item function
// the second parameter is text scale, it's defaulted to 1.0f, 1.0f. You do NOT have to pass this
dropdown->add_item("item name", { 1.0f, 1.0f });Example usage for standalone dropdown
// create a dropdown that does not have a parent
ui.add_dropdown("dropdown1", "Example dropdown", { 10, 10 }, { 100, 20 });We can also access the member functions by making use of find_element(const std::string& id)
// store the FUI_Element* connected with the dropdown
auto dropdown = ui.find_element("dropdown1");
// add an item, this item will be stored with index 0 as it is our first item
dropdown->add_item("Item 1");
// Set the default item, index in the list works like any array, 0 = first item, items_amt - 1 = last item
dropdown->set_default_item(0);Available member functions for buttons
// set the size of the dropdown element
void set_size(olc::vi2d s);
// set the position of the dropdown
void set_position(olc::vi2d p);
// set the dropdown text
void set_text(const std::string& txt);
// set the text color of the dropdown
void set_text_color(olc::Pixel color);
// get the group the dropdown is apart of
const std::string get_group();
// set the scaling of the text
void scale_text(olc::vf2d scale);
// will return the position of the button
const olc::vi2d get_position();
// will return the text size of the element
olc::vi2d get_text_size(olc::PixelGameEngine* pge);
// set the default displayed item
void set_default_item(const int& index);
// set the max items to be displayed when dropdown is open
// This will enable scrolling if max items is > displayed items
void set_max_display_items(const int amount);
// this will set the animation speed of which the dropdown list opens
void set_animation_speed(float speed);
// get the index of the current selected item
const int get_selected_item();