diff --git a/examples/scalable_login_screen/ScalableLoginScreen.cpp b/examples/scalable_login_screen/ScalableLoginScreen.cpp index 960b306a8..53d5638d4 100644 --- a/examples/scalable_login_screen/ScalableLoginScreen.cpp +++ b/examples/scalable_login_screen/ScalableLoginScreen.cpp @@ -29,61 +29,64 @@ import tgui; #include #endif -void login(const tgui::EditBox::Ptr& username, const tgui::EditBox::Ptr& password) +namespace { - std::cout << "Username: " << username->getText() << '\n'; - std::cout << "Password: " << password->getText() << '\n'; -} + void login(const tgui::EditBox::Ptr& username, const tgui::EditBox::Ptr& password) + { + std::cout << "Username: " << username->getText() << '\n'; + std::cout << "Password: " << password->getText() << '\n'; + } -void updateTextSize(tgui::BackendGui& gui) -{ - // Update the text size of all widgets in the gui, based on the current window height - const float windowHeight = gui.getView().getRect().height; - gui.setTextSize(static_cast(0.07f * windowHeight)); // 7% of height -} + void updateTextSize(tgui::BackendGui& gui) + { + // Update the text size of all widgets in the gui, based on the current window height + const float windowHeight = gui.getView().getRect().height; + gui.setTextSize(static_cast(0.07f * windowHeight)); // 7% of height + } -void loadWidgets(tgui::BackendGui& gui) -{ - // Specify an initial text size instead of using the default value - updateTextSize(gui); + void loadWidgets(tgui::BackendGui& gui) + { + // Specify an initial text size instead of using the default value + updateTextSize(gui); - // We want the text size to be updated when the window is resized - gui.onViewChange([&gui] { updateTextSize(gui); }); + // We want the text size to be updated when the window is resized + gui.onViewChange([&gui] { updateTextSize(gui); }); - // Create the background image - // The picture is of type tgui::Picture::Ptr which is just a type alias declaration for std::shared_ptr - // The picture will fit the entire window and will scale with it - auto picture = tgui::Picture::create("xubuntu_bg_aluminium.jpg"); - picture->setSize({"100%", "100%"}); - gui.add(picture); + // Create the background image + // The picture is of type tgui::Picture::Ptr which is just a type alias declaration for std::shared_ptr + // The picture will fit the entire window and will scale with it + auto picture = tgui::Picture::create("xubuntu_bg_aluminium.jpg"); + picture->setSize({"100%", "100%"}); + gui.add(picture); - // Create the username edit box - // Similar to the picture, we set a relative position and size - // In case it isn't obvious, the default text is the text that is displayed when the edit box is empty - auto editBoxUsername = tgui::EditBox::create(); - editBoxUsername->setSize({"66.67%", "12.5%"}); - editBoxUsername->setPosition({"16.67%", "16.67%"}); - editBoxUsername->setDefaultText("Username"); - gui.add(editBoxUsername); + // Create the username edit box + // Similar to the picture, we set a relative position and size + // In case it isn't obvious, the default text is the text that is displayed when the edit box is empty + auto editBoxUsername = tgui::EditBox::create(); + editBoxUsername->setSize({"66.67%", "12.5%"}); + editBoxUsername->setPosition({"16.67%", "16.67%"}); + editBoxUsername->setDefaultText("Username"); + gui.add(editBoxUsername); - // Create the password edit box - // We copy the previous edit box here and keep the same size - auto editBoxPassword = tgui::EditBox::copy(editBoxUsername); - editBoxPassword->setPosition({"16.67%", "41.6%"}); - editBoxPassword->setPasswordCharacter('*'); - editBoxPassword->setDefaultText("Password"); - gui.add(editBoxPassword); + // Create the password edit box + // We copy the previous edit box here and keep the same size + auto editBoxPassword = tgui::EditBox::copy(editBoxUsername); + editBoxPassword->setPosition({"16.67%", "41.6%"}); + editBoxPassword->setPasswordCharacter('*'); + editBoxPassword->setDefaultText("Password"); + gui.add(editBoxPassword); - // Create the login button - auto button = tgui::Button::create("Login"); - button->setSize({"50%", "16.67%"}); - button->setPosition({"25%", "70%"}); - gui.add(button); + // Create the login button + auto button = tgui::Button::create("Login"); + button->setSize({"50%", "16.67%"}); + button->setPosition({"25%", "70%"}); + gui.add(button); - // Call the login function when the button is pressed and pass the edit boxes that we created as parameters - // The "&" in front of "login" can be removed on newer compilers, but is kept here for compatibility with GCC < 8. - button->onPress(&login, editBoxUsername, editBoxPassword); -} + // Call the login function when the button is pressed and pass the edit boxes that we created as parameters + // The "&" in front of "login" can be removed on newer compilers, but is kept here for compatibility with GCC < 8. + button->onPress(&login, editBoxUsername, editBoxPassword); + } +} // namespace bool runExample(tgui::BackendGui& gui) {