Repository navigation
Automated aspects of FrostUI
Daniel edited this page Sep 27, 2021
·
1 revision
In this part we'll go over some general steps to build a GUI with FrostUI
// create the handler
olc::FrostUI ui;
// if we have a window we can set that window to be the default parent until we change default parent
auto window = ui.create_window("id1", "Test window", { 10, 10 }, { 300, 200 });
// everything after the following line will have the window "id1" as parent
ui.set_active_window("id1");
// position of this button is now relative to the parents position
ui.add_button("btn1", "Test button", { 10, 10 }, { 100, 10 }, [] {});
// we now release the active window, after this line there won't be a default parent
ui.clear_active_window();Now you know a little about setting default parents, this will make it easier for you since you don't have to add a parent id manually for every element, this also allows for procedural building of a GUI where you can build 1 window at a time and simply change the active window to switch parent.
We can do the same with groups assuming we want to render different items for different scenarios / tabs
// create the handler
olc::FrostUI ui;
// create the window
ui.create_window("window1", "Testing tabs", { 10, 10 }, { 310, 200 });
// this will be the default parent for all elements added in this example (does not affect groups)
ui.set_active_window("window1");
// add 3 different groups, this function takes string window_id and string group_id
// window_id can be left empty if you don't have a window to add the groups to
ui.add_group("window1", "tab1");
ui.add_group("window1", "tab2");
ui.add_group("window1", "tab3");
// before we set any active group we add all the buttons that will act as tab changers
// these buttons will have the window1 as parents as we set the default parent a few lines above
ui.add_button("btn1", "Tab 1", { 0, 0 }, { 100, 20 }, [&] { ui.set_active_group("tab1"); });
ui.add_button("btn2", "Tab 2", { 100, 0 }, { 100, 20 }, [&] { ui.set_active_group("tab2"); });
ui.add_button("btn3", "Tab 3", { 200, 0 }, { 100, 20 }, [&] { ui.set_active_group("tab3"); });
// here we set the active group each element will be added to
ui.set_active_group("tab1");
// create elements relating to tab1 here
ui.add_label("label1", "We're in tab 1", { 50, 50 });
ui.set_active_group("tab2");
// create elements relating to tab2 here
ui.add_label("label2", "We're in tab 2", { 50, 50 });
ui.set_active_group("tab3");
// create elements relating to tab3 here
ui.add_label("label3", "We're in tab 3", { 50, 50 });
// not required if you aren't adding more to your gui but lets clear the active window
ui.clear_active_window();
// the active group will be used as the thing deciding which group should be rendered
// so we should set the active group here to decide which tab is the default
// in this case we want tab1 to be drawn when we start the program
ui.set_active_group("tab1");These were 2 small examples on how you can utilize the autonomous workflow FrostUI has to offer when it comes to parents and grouping of elements