Search code examples
c++macostoolbarsfmlmenubar

How to create a menubar in SFML application?


I'm trying to write an SFML 2.5.1 program, but I have faced an issue, I can't find in the internet how to create working program menubar, which is located upper window (or upper screen in Mac OS), something like this:

menubar

All I have found in the internet is a Titlebar, only first two options in menubar: File and Edit, and they are don't work for some reason, don't reacting on clicking, I can't find out why.

Help me please


Solution

  • You can hide the original title bar and make your own using classes (button or titlebar_button, call it as u want) which is just a rectangle shape with the on_Click function.

    https://en.sfml-dev.org/forums/index.php?topic=24051.0 - Answer

    https://www.sfml-dev.org/documentation/1.6/namespacesf_1_1Style.php - Style documentation (I couldn't find one for 2.5.1, but it isn't that deprecated, in new versions, there is also a Style::Deafult)

    Example:

    sf::Window my_Window(sf::VideoMode(640U,480U),"w",sf::Style::None)
    

    However, you have to keep in mind, that your window won't have any border and thus won't be resizeable nor closeable until you implement this.