How to have a nana::listbox which has a check box for each list item?

How to have a nana::listbox which has a check box for each list item?
edited Oct 4 at 2:30 pm

Thanks Error Flynn, The checkbox option for the listbox is now working, BUT, there is a bug in checkbox:

As you move the mouse up and down the list, the line gets highlighted and if the last line of the listbox is highlighted then the checkbox selection does not work.

Please try it and let me know if you could repeat this bug. Thanks.

#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/gui/widgets/menu.hpp>
#include <nana/gui/filebox.hpp>
#include <nana/gui/place.hpp>
#include <nana/gui/widgets/menubar.hpp>
#include <nana/gui/widgets/toolbar.hpp>
#include <nana/gui/widgets/textbox.hpp>
#include <nana/gui/widgets/group.hpp>
#include <nana/gui/widgets/combox.hpp>
#include <nana/gui/widgets/listbox.hpp>
#include <nana/gui/widgets/checkbox.hpp>
#include <nana/paint/image_process_selector.hpp>

#include <string.h>
#include <vector>
#include <windows.h>

using namespace nana;
using std::string;
using std::vector;

// global variables
struct data
{
    string a, b, c;
};
vector<data> lbData;
data lastSelect = {"","",""};

nana::listbox::iresolver& operator >> (nana::listbox::iresolver &ires, data &d)
{
    ires >> d.a;
    ires >> d.b;
    ires >> d.c;
    return ires;
}

int main()
{
    string a, b, c;
    int i, j;

    // --------------------- create GUI ----------------------
    // create window
    form fm(API::make_center(480, 350), appear::decorate<appear::minimize>());

    // create widgets
    listbox lbTest(fm, rectangle(10, 10, 460, 180));
    lbTest.checkable(true);
    label txtDebugA(fm, rectangle(10, 210, 460, 20));
    label txtDebugB(fm, rectangle(10, 240, 460, 20));
    label txtDebugC(fm, rectangle(10, 270, 460, 20));
    button btExit(fm, rectangle(180, 300, 120, 30));
    fm.caption("Listbox test");

    // listbox test
    lbTest.append_header("column a", 145);
    lbTest.append_header("column b", 145);
    lbTest.append_header("column c", 145);
    lbTest.auto_draw(false);
    // fill the listbox...
    for(i = 0; i < 10; i++)
    {
        if(!(i % 2))
        {
            a = "section ";
            a += char(i/2 + 48);
        }
        b = "b";
        b += char(i + 48);
        c = "c";
        c += char(i + 48);
        lbTest.at(0).append({a,b,c});
    }
    lbTest.auto_draw(true);
    lbTest.events().selected([&](const arg_listbox& arg)
    {
        arg.item.resolve_to(lastSelect);
        // show the resutl
        txtDebugA.caption("lastSelect.a :   " + lastSelect.a);
        txtDebugB.caption("lastSelect.b :   " + lastSelect.b);
        txtDebugC.caption("lastSelect.c :   " + lastSelect.c);
    });

    // button exit
    btExit.caption("Exit");
    btExit.events().click(API::exit_all);
    btExit.events().key_char([fm](const arg_keyboard& arg)
    {
        if(arg.key == keyboard::enter)
            API::exit_all();
    });

    fm.show();
    exec();
}
Thanks Error Flynn, The checkbox option for the listbox is now working, BUT, there is a bug in checkbox: As you move the mouse up and down the list, the line gets highlighted and if the ** last line** of the listbox is highlighted then the checkbox selection does not work. Please try it and let me know if you could repeat this bug. Thanks. ```` #include <nana/gui.hpp> #include <nana/gui/widgets/label.hpp> #include <nana/gui/widgets/button.hpp> #include <nana/gui/widgets/menu.hpp> #include <nana/gui/filebox.hpp> #include <nana/gui/place.hpp> #include <nana/gui/widgets/menubar.hpp> #include <nana/gui/widgets/toolbar.hpp> #include <nana/gui/widgets/textbox.hpp> #include <nana/gui/widgets/group.hpp> #include <nana/gui/widgets/combox.hpp> #include <nana/gui/widgets/listbox.hpp> #include <nana/gui/widgets/checkbox.hpp> #include <nana/paint/image_process_selector.hpp> #include <string.h> #include <vector> #include <windows.h> using namespace nana; using std::string; using std::vector; // global variables struct data { string a, b, c; }; vector<data> lbData; data lastSelect = {"","",""}; nana::listbox::iresolver& operator >> (nana::listbox::iresolver &ires, data &d) { ires >> d.a; ires >> d.b; ires >> d.c; return ires; } int main() { string a, b, c; int i, j; // --------------------- create GUI ---------------------- // create window form fm(API::make_center(480, 350), appear::decorate<appear::minimize>()); // create widgets listbox lbTest(fm, rectangle(10, 10, 460, 180)); lbTest.checkable(true); label txtDebugA(fm, rectangle(10, 210, 460, 20)); label txtDebugB(fm, rectangle(10, 240, 460, 20)); label txtDebugC(fm, rectangle(10, 270, 460, 20)); button btExit(fm, rectangle(180, 300, 120, 30)); fm.caption("Listbox test"); // listbox test lbTest.append_header("column a", 145); lbTest.append_header("column b", 145); lbTest.append_header("column c", 145); lbTest.auto_draw(false); // fill the listbox... for(i = 0; i < 10; i++) { if(!(i % 2)) { a = "section "; a += char(i/2 + 48); } b = "b"; b += char(i + 48); c = "c"; c += char(i + 48); lbTest.at(0).append({a,b,c}); } lbTest.auto_draw(true); lbTest.events().selected([&](const arg_listbox& arg) { arg.item.resolve_to(lastSelect); // show the resutl txtDebugA.caption("lastSelect.a : " + lastSelect.a); txtDebugB.caption("lastSelect.b : " + lastSelect.b); txtDebugC.caption("lastSelect.c : " + lastSelect.c); }); // button exit btExit.caption("Exit"); btExit.events().click(API::exit_all); btExit.events().key_char([fm](const arg_keyboard& arg) { if(arg.key == keyboard::enter) API::exit_all(); }); fm.show(); exec(); } ````
edited Oct 4 at 5:10 pm

I can confirm that there is indeed a bug. If you scroll the list to the bottom, the mouse event "hitbox" for all checkboxes gets displaced downward by about 75% of the checkbox height. So the checkboxes still work, but you have to click on them 75% lower. I don't have time right now, but I will look at the code later, and see if I can find the bug. Very strange!

I can confirm that there is indeed a bug. If you scroll the list to the bottom, the mouse event "hitbox" for all checkboxes gets displaced downward by about 75% of the checkbox height. So the checkboxes still work, but you have to click on them 75% lower. I don't have time right now, but I will look at the code later, and see if I can find the bug. Very strange!

Thank you Error Flynn. Would this fix be in the next version of NANA?

Thank you Error Flynn. Would this fix be in the next version of NANA?

If Jinhao decides to merge my pull request, yes. He has been inactive for the last month though, so I don't know when the next version will be released. I hope he is OK and that he will resume activity on GitHub (and on this forum) soon.

If Jinhao decides to merge my pull request, yes. He has been inactive for the last month though, so I don't know when the next version will be released. I hope he is OK and that he will resume activity on GitHub (and on this forum) soon.

I hope Jinhao is okay and becomes more active in this forum.

BUT, as I have always said, any software development needs a dedicated team and not just rely on one person.

I believe Jinhao should create a team of experts (such as yourself and others) to take responsibility in the development and maintenance of the NANA library such that NANA's future be stable and sure. Otherwise NANA like many other GUI libraries would not survive for long.

I hope Jinhao is okay and becomes more active in this forum. BUT, as I have always said, any software development needs a dedicated team and not just rely on one person. **I believe Jinhao should create a team of experts** (such as yourself and others)** to take responsibility in the development and maintenance of the NANA library** such that NANA's future be stable and sure. Otherwise NANA like many other GUI libraries would not survive for long.
edited Oct 6 at 4:52 pm
50
views
7
replies
2
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft