Nana ++ Library  
An open-source C++ framework project
The Nana Programmer's Guide 
nana::gui::combox

Description

This widget is a combo box which consists of a list box combined with a textbox, the list box should drop down when the user selects thr drop-down arrow next to the control.

#include <nana/gui/wvl.hpp>
#include <nana/gui/widgets/combox.hpp>

int main()
{
    using namespace nana::gui;

    //No Minimize button, no maximize button and sizable frame.
    form fm(API::make_center(240, 100), appear::decorate<>());
    fm.caption(STR("Nana C++ Library - Example"));

    combox child(form, nana::rectangle(20, 3, 150, 30));

    child.push_back(STR("Item 1"));
    child.push_back(STR("Item 2"));
    child.push_back(STR("Item 3"));
    child.push_back(STR("Item 4"));
    child.push_back(STR("Item 5"));

    //The function will be called after changing the combox text by selecting a text from drop-down list.
    child.ext_event().selected = []{ std::cout<<"selected a new text"<<std::endl; };

    fm.show();
    exec();
}


nana::gui::combox

Model of

Widget Window 

Public base classes

class widget_object<widget_tag, DrawerTrigger>: public widget

Typedefs

ext_event_type This class provides the methods for extra event. (See Note 1)
item_renderer A super class for user defined item renderer.(See Note 2)



Members

combox() The default construction.
combox(window wd, bool visible) Creates a combox.
combox(window wd, const nana::string& title, bool visible = true) Ditto.
combox(window wd, const nana::char_t* title, bool visible = true) Ditto.
combox(window wd, const rectangle& r = rectangle(), bool visible = true) Ditto.
template<typename T>
void anyobj(std::size_t index, const T&)
Binds an object with the specified item.
template<typename T>
T * anyobj(std::size_t index) const
Retrieves the binded object with the specified item. It returns a null ptr if a object is not binded or the type is mismatched or the item is out of range.
void clear() Clears all items.
bool editable() const Returns true if the combox is editable mode.
void editable(bool) Set the combox editable mode.
ext_event_type& ext_event() const Retrieves the ext_event object.
void image(std::size_t i, const nana::paint::image&) Sets an image for a specified item.
nana::paint::image image(std::size_t) const Retrieves the image of a specified item.
void image_pixels(unsigned pixels) Sets the width of image area. Defaulty is 16 pixels.
combox& push_back(const nana::string& text) Insert a text string to the listbox.
std::size_t option() const Get the index of item which is selected from drop-down list last time.
void option(std::size_t index) Set text that specifed by index.
nana::string text(std::size_t) const Retrieves the text of item in drop list.
std::size_t the_number_of_options() const Retrieves the number of options.
void renderer(item_renderer*) Set user-defined item renderer object. It is a address therefore user should not destroy the renderer object after it set to the combox. Passing null_ptr cancels the user-defined renderer object.

File

nana/gui/widgets/combox.hpp

Notes

1, The class ext_event is coming with the combox, its definition is

struct ext_event_type
{
    nana::functor_group<void(nana::gui::combox&)> selected; //Selects a new item.
};

This class provides a method to implement that a program may respond to the combox special event or state. It seems like the events registered by make_event member function. But the answering registered by make_event is used for general-purpose, such as mouse_down, mouse_move, click and so on, the combox ext_event_type is used for the own providing event.

2, Refer nana::gui::float_listbox for details of item_renderer.

See also

None.


Move to The Nana Programmer's Guide Main Page