Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed navigation bar not being entirely hidden on Android #1554

Merged
merged 1 commit into from Sep 3, 2019

Conversation

acsbendi
Copy link
Contributor

@acsbendi acsbendi commented Feb 10, 2019

Description

In full-screen mode on Android, the navigation bar was not entirely hidden which I tested on multiple devices. After changing a flag, the navigation bar started to behave as expected.

Also refer to the official sample about immersive mode.

Tasks

  • Tested on Linux
  • Tested on Windows
  • Tested on macOS
  • Tested on iOS
  • Tested on Android

How to test this PR?

#include <SFML/Graphics.hpp>

using std::string;
using sf::Font;
using sf::Sprite;
using sf::Texture;

int main(int argc, char *argv[])
{
    sf::VideoMode screen(sf::VideoMode::getDesktopMode());

    sf::RenderWindow window(screen, "", sf::Style::Fullscreen);
    window.setFramerateLimit(30);

    sf::Texture texture;
    if(!texture.loadFromFile("image.png"))
        return EXIT_FAILURE;

    sf::Sprite image(texture);
    image.setPosition(screen.width / 2, screen.height / 2);
    image.setOrigin(texture.getSize().x/2, texture.getSize().y/2);

    sf::Font font;
    if (!font.loadFromFile("sansation.ttf"))
        return EXIT_FAILURE;

    sf::Text text("Tap anywhere to move the logo.", font, 64);
    text.setFillColor(sf::Color::Blue);
    text.setPosition(10, 10);

    // Loading canary.wav fails for me for now; haven't had time to test why

    /*sf::Music music;
    if(!music.openFromFile("canary.wav"))
        return EXIT_FAILURE;
    music.play();*/

    sf::View view = window.getDefaultView();

    sf::Color background = sf::Color::Black;

    // We shouldn't try drawing to the screen while in background
    // so we'll have to track that. You can do minor background
    // work, but keep battery life in mind.
    bool active = true;

    while (window.isOpen())
    {
        sf::Event event;

        while (active ? window.pollEvent(event) : window.waitEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::Escape)
                        window.close();
                    break;
                case sf::Event::Resized:
                    view.setSize(event.size.width, event.size.height);
                    view.setCenter(event.size.width/2, event.size.height/2);
                    window.setView(view);
                    break;
                case sf::Event::LostFocus:
                    background = sf::Color::White;
                    break;
                case sf::Event::GainedFocus:
                    background = sf::Color::Black;
                    break;

                    // On Android MouseLeft/MouseEntered are (for now) triggered,
                    // whenever the app loses or gains focus.
                case sf::Event::MouseLeft:
                    active = false;
                    break;
                case sf::Event::MouseEntered:
                    active = true;
                    break;
                case sf::Event::TouchBegan:
                    if (event.touch.finger == 0)
                    {
                        image.setPosition(event.touch.x, event.touch.y);
                    }
                    break;
                default:
                    break;
            }
        }

        if (active)
        {
            window.clear(background);
            window.draw(image);
            window.draw(text);
            window.display();
        }
        else {
            sf::sleep(sf::milliseconds(100));
        }
    }
}

@eXpl0it3r
Copy link
Member

Just realized we had a similar PR open #1538 but the author didn't provide an updated one. Looking at the two changes, what's the difference between yours and the other one: https://github.com/SFML/SFML/pull/1538/files#diff-a9064007c5b52fa9f173fdd52d3f0dc3R177 ?

@acsbendi
Copy link
Contributor Author

acsbendi commented Feb 12, 2019

@eXpl0it3r Apart from the other files changed in that PR, mine removes setting the other flag (SYSTEM_UI_FLAG_LOW_PROFILE) which doesn't have any effect after setting SYSTEM_UI_FLAG_HIDE_NAVIGATION and is therefore unnecessary.

@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Feb 13, 2019
@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Feb 13, 2019
@eXpl0it3r eXpl0it3r moved this from Discussion to Review & Testing in SFML 2.6.0 Feb 13, 2019
Copy link
Member

@eXpl0it3r eXpl0it3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there are different options some comment from @MarioLiebisch or someone else might be useful, but I'm happy to get this merged regardless.

@eXpl0it3r eXpl0it3r moved this from Review & Testing to Ready in SFML 2.6.0 Jul 1, 2019
@eXpl0it3r eXpl0it3r merged commit ea71dd2 into SFML:master Sep 3, 2019
SFML 2.6.0 automation moved this from Ready to Done Sep 3, 2019
Android Backlog automation moved this from Backlog to Done Sep 3, 2019
@SFML SFML deleted a comment from eXpl0it3r Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
SFML 2.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants