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

Description

A categorize widget is used for representing the architecture of categories and what category is chosen. The categorize widget can be used for representing a path of a directory or the order of hierarchy.

Model of

Widget Window 

Public base classes

class widget_object<widget_tag, DrawerTrigger>: public widget

Template Parameter

T The value type of categorize, the type of object that stored in categorize.

Typedefs

value_type  The type of object, T, stored in categorize.
ext_event_type The methods for extra events.(See Note 1)
renderer The interface for user-defined renderer.

Members

categorize() The default construction.
categorize(window wd, bool visible) The constructor for creating a categorize in a specified window.
categorize(window wd, const nana::string& title, bool visible = true) Ditto.
categorize(window wd, const nana::char_t* title, bool visible = true) Ditto.
categorize(window wd, const rectangle& r = rectangle(), bool visible = true) Ditto.
ext_event_type& ext_event() const Refers to the object of extra events
categorize& insert(const nana::string& name, const value_type&) Insert a new category with a specified name and the object of value type. The new category would be inserted as a child in current category, and after inserting, the new category is replaced of the current category as a new current one.
categorize& childset(const nana::string& name, const value_type&) Inserts a child category into current category.
categorize& childset_erase(const nana::string& name) Erases a child category with a specified name from current category.
categorize& splitstr(const nana::string&) Sets the splitter string
nana::string splitstr() const Retrieves the splitter string.
value_type& value() const Retrieves the reference of the current category's value type object. If current category is empty, it throws a exception of std::runtime_error.


Demo

#include <iostream>
#include <nana/gui/wvl.hpp>
#include <nana/gui/widgets/categorize.hpp>

void selected(nana::gui::categorize<int> & categ, int&)
{
    nana::gui::msgbox mb(categ, STR("categorize"));
    mb.icon(mb.icon_information);
    mb<<STR("The value of selected is ")<<categ.value()<<STR(", caption is \"")
      <<categ.caption()<<STR("\"");    //caption() method, see Note 3.
    mb();
}

int main()
{
    using namespace nana::gui;
    form fm;
    categorize<int> categ(fm, 10, 10, 200, 24);

    categ.childset(STR("Invalid Category"), 0);
    //Invalid category because of empty current category.

    categ.insert(STR("First"), 0);
    //Insert a category and now it is the current category.

    categ.insert(STR("Second"), 1);
    //Insert a category as a child of "First" category, and then
    //the "Second" is the current category.

    categ.childset(STR("Third"), 2);
    //Insert a category as a child of "Second".

    categ.childset(STR("Another Child"), 2);
    //childset() always insert categories into current category, and
    //it does not displace the current category, and therefore "Another Child"
    //is a child of "Second".

    categ.ext_event().selected = selected;
    //This may crash in VC2012-RC due to compiler bug.
    //Please refer to compatibility-issue for more details

    fm.show();
    exec();
}

Snapshot of categorize
Screenshot of categorize.

File

nana/gui/widgets/categorize.hpp

Notes

1. The definition of ext_event_type

    struct ext_event_type
    {
        typedef Implementation-Specified categorize_type;
        typedef typename categorize_type::value_type value_type;

        nana::fn_group<void(categorize_type&, value_type&)> selected; //Selects a category
    };

2. Definition of renderer

    class renderer
    {
    public:
        typedef nana::paint::graphics & graph_reference;

        enum state_t{state_normal, state_over, state_pressed};

        struct ui_element
        {
            enum t
            {
                none, //Out of the widget
                somewhere, item_root, item_name, item_arrow
            };

            static const size_t npos = static_cast<size_t>(-1);
            t what;
            size_t index;

            ui_element();
        };

        virtual ~renderer() = 0;
        virtual void background(graph_reference, window, const nana::rectangle&, const ui_element&) = 0;
        virtual void root_arrow(graph_reference, const nana::rectangle&, state_t) = 0;
        virtual void item(graph_reference, const nana::rectangle&, size_t index,
                          const nana::string& name, unsigned text_height,
                          bool has_child, state_t) = 0;
        virtual void border(graph_reference) = 0;
    };

3. The caption() methods of the categorize widget is used for retrieving and setting the category.

See also

None.


Move to The Nana Programmer's Guide Main Page