Repository navigation
add_button
Daniel edited this page Oct 1, 2021
·
15 revisions
The add_button function will add a button to the ui handler, add_button does not return the FUI_Element* related to the button.
add_button has two different implementations
add_button(
const std::string& identifier,
const std::string& text,
olc::vi2d position,
olc::vi2d size,
std::function<void()> callback
);
add_button(
const std::string& parent_id,
const std::string& identifier,
const std::string& text,
olc::vi2d position,
olc::vi2d size,
std::function<void()> callback
);Example usage for button with a parent
// create the UI handler
olc::FrostUI ui;
// create a window
ui.create_window("window1", "TITLE HERE", { 10, 10 }, { 300, 200 });
// create button while specifying the parent_id manually
ui.add_button("window1", "button1", "Example button", { 10, 10 }, { 100, 20 }, [&]
{
/*some actions to happen when button is pressed*/
});Example usage for standalone button
// create a button that does not have a parent
ui.add_button("button1", "Example button", { 10, 10 }, { 100, 20 }, [&]
{
/*some actions to happen when button is pressed*/
});We can also access the member functions by making use of find_element(const std::string& id)
// store the FUI_Element* connected with the button
auto button = ui.find_element("button1");
// makes the button toggleable, pass the default state (true/false)
button->make_toggleable(false);Available member functions for buttons
// set the size of the button
void set_size(olc::vi2d s);
// set the position of the button
void set_position(olc::vi2d p);
// set the button text
void set_text(const std::string& txt);
// set the text color of the button
void set_text_color(olc::Pixel color);
// get the group the button is apart of
const std::string get_group();
// set the scaling of the text
void scale_text(olc::vf2d scale);
// will make the button toggleable
void make_toggleable(bool default_state);
// 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);
// will return the button state IF the button is toggleable
const bool get_button_state();