Skip to content
James Bremner edited this page Apr 5, 2019 · 1 revision

slider

Doxygen description of slider

Usage

#include <nana/gui.hpp>
#include <nana/gui/widgets/slider.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/gui/widgets/label.hpp>

int main()
{
    nana::form fm;

    // construct widgets to display on fm
    nana::slider sl( fm );
    nana::button btn( fm );
    nana::label status( fm );

    // move widgets to their locations in fm
    sl.move( {20,20, 200, 25 });
    btn.move( { 50, 50, 50,50 });
    status.move( { 20, 130, 200, 25 });

    // specify range of 0 to 100 ( including 0 and 100 )
    // Note negative values are not supported!
    sl.maximum( 100 );

    /* button press to display value selected by slider

    It is best not to use the slider events since they will be numerous and can overwhelm your GUI.

    You can read the slider value when
    - user presses a button ( as here )
    - a timer fires, maybe several times a second to make the GUI seem responsive to slides
    - the mouse leaves the slider widget
    */
    btn.caption("Save");
    btn.events().click([&]
    {
        status.caption("Value is "+std::to_string( sl.value() ));
    });

    fm.show();

    nana::exec();
}
Clone this wiki locally