I write code, over and over again, that looks like this:

fm.events().some_event([&](const nana::some_arg&arg)
{
    // do some work in response to event
    ...

    nana::API::refresh_window( fm );

});

Why????

nana::API::refresh_window() is not documented. I have been told that it is not documented because it should not be needed. But without it the display does not get updated.

I think the window widget base class should wrap the API call, so that I can write fm.refresh() just like I would in any other GUI framework.

I write code, over and over again, that looks like this: fm.events().some_event([&](const nana::some_arg&arg) { // do some work in response to event ... nana::API::refresh_window( fm ); }); Why???? nana::API::refresh_window() is not documented. I have been told that it is not documented because it should not be needed. But without it the display does not get updated. I think the window widget base class should wrap the API call, so that I can write fm.refresh() just like I would in any other GUI framework.

Hi, could you please provide a code to reproduce the issue?

Hi, could you please provide a code to reproduce the issue?

Are you using class drawing in some_event to draw something on the fm?

Are you using class `drawing` in some_event to draw something on the `fm`?

Hi, could you please provide a code to reproduce the issue?

Please take a look at

https://github.com/JamesBremner/DXF_Viewer/blob/master/src/nana.cpp

If I remove the line:

https://github.com/JamesBremner/DXF_Viewer/blob/a9079b2045a1c2d5dd5dccee824ee3dd2e1dcf87/src/nana.cpp#L70

the display will not pan when the mouse is dragged.

>Hi, could you please provide a code to reproduce the issue? Please take a look at https://github.com/JamesBremner/DXF_Viewer/blob/master/src/nana.cpp If I remove the line: https://github.com/JamesBremner/DXF_Viewer/blob/a9079b2045a1c2d5dd5dccee824ee3dd2e1dcf87/src/nana.cpp#L70 the display will not pan when the mouse is dragged.

Hi, I read your code. It requires nana::API::refresh_window to redraw in mouse_move event. The reason is that the mouse_move of form(internal handler, not the hander you provide) doesn't draw anything on the form, and the handler you provide doesn't draw anything too(dxf->myBoundingRectangle.Pan() just modifies the position). When existing mouse_move handler, Nana doesn't refresh the graphics(because of no change).

Hi, I read your code. It requires `nana::API::refresh_window` to redraw in mouse_move event. The reason is that the `mouse_move` of form(internal handler, not the hander you provide) doesn't draw anything on the form, and the handler you provide doesn't draw anything too(`dxf->myBoundingRectangle.Pan()` just modifies the position). When existing `mouse_move` handler, Nana doesn't refresh the graphics(because of no change).

Yes.

So, can you add a documented refresh method to the window widgets that can force a refresh in these case - they occurr frequently.

This would be simple and familiar for anyone who has used other GUI frameworks.

I just added yet another

    nana::menu& mv = mb.push_back("View");
    mv.append("Fit",[&](nana::menu::item_proxy& ip)
    {
        // rescale and pan so all entities fit in the window
        dxf->myBoundingRectangle.Fit();

        // refresh
        nana::API::refresh_window( fm );
    });
Yes. So, can you add a documented refresh method to the window widgets that can force a refresh in these case - they occurr frequently. This would be simple and familiar for anyone who has used other GUI frameworks. I just added yet another ```` nana::menu& mv = mb.push_back("View"); mv.append("Fit",[&](nana::menu::item_proxy& ip) { // rescale and pan so all entities fit in the window dxf->myBoundingRectangle.Fit(); // refresh nana::API::refresh_window( fm ); }); ````

... the handler you provide doesn't draw anything too ...

After some though, I believe I get the point you are making here.

I would be happy to add calls to the entity drawing methods from the individual event handlers. It would actually make the main code cleaner!

However, the drawing codes need access to the device context of the window ( nana::paint::graphics ). How do I get that from inside an event handler?

> ... the handler you provide doesn't draw anything too ... After some though, I believe I get the point you are making here. I would be happy to add calls to the entity drawing methods from the individual event handlers. It would actually make the main code cleaner! However, the drawing codes need access to the device context of the window ( nana::paint::graphics ). How do I get that from inside an event handler?

Got it!

Instead of calling the undocumented API refresh function, I can call nana::drawing::update() from within the event handlers.

Something like this:

    // register drawing function
    nana::drawing drawing{fm};
    dw.draw([&dxf](nana::paint::graphics& graph)
    {
         ...

fm.events().some_event([&](const nana::some_arg&arg)
{
    // do some work in response to event
    ...

    drawing.update();

});

This is clean and documented.

I do suggest that an example of this technique be added to the events page, for the sake of noobies who are familiar with calling refresh on the widget rather than on the drawing function registered on the widget.

FYI I have commited this technique to https://github.com/JamesBremner/DXF_Viewer/blob/master/src/nana.cpp

Got it! Instead of calling the undocumented API refresh function, I can call nana::drawing::update() from within the event handlers. Something like this: ```` // register drawing function nana::drawing drawing{fm}; dw.draw([&dxf](nana::paint::graphics& graph) { ... fm.events().some_event([&](const nana::some_arg&arg) { // do some work in response to event ... drawing.update(); }); ```` This is clean and documented. I do suggest that an example of this technique be added to the events page, for the sake of noobies who are familiar with calling refresh on the widget rather than on the drawing function registered on the widget. FYI I have commited this technique to https://github.com/JamesBremner/DXF_Viewer/blob/master/src/nana.cpp
edited Aug 15 at 2:48 pm

I do suggest that an example of this technique be added to the events page, for the sake of noobies who are familiar with calling refresh on the widget rather than on the drawing function registered on the widget.

I could really use that example, because I honestly don't undestand this. Why should I have to register a drawing function with the form, just so I can refresh widgets? How is that preferable to calling API::refresh_window?

Also, I don't understand how that would work. Can someone explain how to get the following listbox to refresh when the button is clicked, without calling nana::API::refresh_window(lb);?

#include <nana/gui.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/gui/widgets/listbox.hpp>

int main()
{
    nana::form fm {nana::API::make_center(300, 234)};
    fm.div("vert margin=15 <listbox><weight=15><button weight=30>");

    nana::listbox lb {fm};
    fm["listbox"] << lb;
    lb.append_header("col0");
    for(int n(0); n<10; n++)
        lb.at(0).append("item #" + std::to_string(n));

    nana::button btn {fm, "Button"};
    fm["button"] << btn;
    btn.events().click([&]
    {
        lb.sort_col(0, true);
        //nana::API::refresh_window(lb);
    });

    fm.collocate();
    fm.show();
    nana::exec();
}

Edit: Are you saying that if there's a need to call API::refresh_window, that's only because of a bug in the library? Because in that case, there's a bug in listbox::sort_col.

>I do suggest that an example of this technique be added to the events page, for the sake of noobies who are familiar with calling refresh on the widget rather than on the drawing function registered on the widget. I could really use that example, because I honestly don't undestand this. Why should I have to register a drawing function with the form, just so I can refresh widgets? How is that preferable to calling `API::refresh_window`? Also, I don't understand how that would work. Can someone explain how to get the following listbox to refresh when the button is clicked, without calling `nana::API::refresh_window(lb);`? ```` #include <nana/gui.hpp> #include <nana/gui/widgets/button.hpp> #include <nana/gui/widgets/listbox.hpp> int main() { nana::form fm {nana::API::make_center(300, 234)}; fm.div("vert margin=15 <listbox><weight=15><button weight=30>"); nana::listbox lb {fm}; fm["listbox"] << lb; lb.append_header("col0"); for(int n(0); n<10; n++) lb.at(0).append("item #" + std::to_string(n)); nana::button btn {fm, "Button"}; fm["button"] << btn; btn.events().click([&] { lb.sort_col(0, true); //nana::API::refresh_window(lb); }); fm.collocate(); fm.show(); nana::exec(); } ```` Edit: Are you saying that if there's a need to call `API::refresh_window`, that's only because of a bug in the library? Because in that case, there's a bug in `listbox::sort_col`.
edited Aug 15 at 7:39 pm

in that case, there's a bug in listbox::sort_col.

Maybe so. Worth trying, as a possible workaround, call

 listbox::auto_draw( true );

If that does not work, you will have to call another modifier that does trigger a redraw, arranging it so that the "change" has no significant effect except to force a redraw.

>in that case, there's a bug in listbox::sort_col. Maybe so. Worth trying, as a possible workaround, call ```` listbox::auto_draw( true ); ```` If that does not work, you will have to call another modifier that does trigger a redraw, arranging it so that the "change" has no significant effect except to force a redraw.
edited Aug 15 at 8:44 pm

Why should I have to register a drawing function with the form, just so I can refresh widgets?

You do not have to.

But, if you do use a drawing function, then you have to find some way to trigger it in any event handlers that modify the model but none of the widgets. You can call API::refresh_window() but that is ugly, undocumented and deprecated and hard to find. drawing::update() is the way to go in these cases.

> Why should I have to register a drawing function with the form, just so I can refresh widgets? You do not _have_ to. But, if you do use a drawing function, then you have to find some way to trigger it in any event handlers that modify the model but none of the widgets. You can call API::refresh_window() but that is ugly, undocumented and deprecated and hard to find. drawing::update() is the way to go in these cases.
45
views
10
replies
3
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