cnjinhao / nana

a modern C++ GUI library
https://nana.acemind.cn
Boost Software License 1.0
2.35k stars 336 forks source link

some examples are out of date #446

Open Xeverous opened 5 years ago

Xeverous commented 5 years ago

Many examples on http://qpcr4vir.github.io/nana-doxy/html/examples.html do not compile (mostly due to renamed classes/includes). Any chance to build them as a part of the project (which would keep them up-to-date)?

qPCR4vir commented 5 years ago

Many examples ...

For example? The source is here: https://github.com/qPCR4vir/nana-demo

Xeverous commented 5 years ago

removing these includes does not help, some classes are missing

main.cpp:8:10: fatal error: nana/gui/layout.hpp: No such file or directory
 #include <nana/gui/layout.hpp>
          ^~~~~~~~~~~~~~~~~~~~~
main.cpp:8:19: fatal error: nana/filesystem/file_iterator.hpp: No such file or directory
#include <nana/filesystem/file_iterator.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

builds and works, just a bunch of warnings

main.cpp: In function 'nana::listbox::iresolver& operator>>(nana::listbox::iresolver&, d_node&)':
main.cpp:67:78: warning: unused parameter 'm' [-Wunused-parameter]
 nana::listbox::iresolver& operator>>(nana::listbox::iresolver& ires, d_node& m)
                                                                      ~~~~~~~~^
main.cpp: In constructor 'explorer::explorer(f_node_title, f_node_children, f_list_items, std::vector<std::pair<std::__cxx11::basic_string<char>, unsigned int> >, nana::rectangle, std::__cxx11::string)':
main.cpp:116:36: warning: unused parameter 'title' [-Wunused-parameter]
                        std::string title={} )
                        ~~~~~~~~~~~~^~~~~~~~
main.cpp: In member function 'void explorer::refresh_path(explorer::t_node&)':
main.cpp:203:36: warning: unused parameter 'sel_node' [-Wunused-parameter]
         void  refresh_path(t_node& sel_node) {};
                            ~~~~~~~~^~~~~~~~
main.cpp: At global scope:
main.cpp:249:58: warning: extra ';' [-Wpedantic]
 std::string            key(/* value_type*/) { return{}; };
                                                          ^
main.cpp:250:60: warning: extra ';' [-Wpedantic]
 std::string            title(/* value_type*/) { return{}; };
                                                            ^
main.cpp:280:112: warning: extra ';' [-Wpedantic]
 std::string            key(const dir_node& dn) { return fs_ext::generic_u8string(dn.value.path().filename()); };
                                                                                                                ^
main.cpp:281:69: warning: extra ';' [-Wpedantic]
 std::string            title(const dir_node& dn) { return key(dn); };
                                                                     ^
main.cpp:282:103: warning: extra ';' [-Wpedantic]
 std::string            key(const dir_it& d) { return fs_ext::generic_u8string(d->path().filename()); };
                                                                                                       ^
main.cpp:283:65: warning: extra ';' [-Wpedantic]
 std::string            title(const dir_it& d) { return key(d); };
                                                                 ^

seems to assume existence of std::experimental::filesystem without including <experimental/filesystem>

main.cpp:216:37: error: 'experimental' in namespace 'std' does not name a type
          using file_iterator = std::experimental::filesystem::directory_iterator; // ::file_iterator file_iterator;
                                     ^~~~~~~~~~~~

only warnings

main.cpp: In lambda function:
main.cpp:12:72: warning: unused parameter 'ip' [-Wunused-parameter]
     mn.at(0).append("open modal window", [&fm](nana::menu::item_proxy& ip)
                                                ~~~~~~~~~~~~~~~~~~~~~~~~^~
main.cpp: In function 'int main(int, char**)':
main.cpp:4:14: warning: unused parameter 'argc' [-Wunused-parameter]
 int main(int argc, char **argv)
          ~~~~^~~~
main.cpp:4:27: warning: unused parameter 'argv' [-Wunused-parameter]
 int main(int argc, char **argv)
                    ~~~~~~~^~~~

404, http://qpcr4vir.github.io/nana-doxy/html/de/ddc/_monti_hall_8cpp-example.html does not exist

the page is empty

the page is empty

does not compile but seems easy to fix

main.cpp: In lambda function:
main.cpp:341:70: warning: unused parameter 'a' [-Wunused-parameter]
                         timer_.elapse([this](const nana::arg_elapse& a)
                                              ~~~~~~~~~~~~~~~~~~~~~~~~^
main.cpp: In member function 'void demo::widget_show::_m_init_progresses()':
main.cpp:354:43: error: no matching function for call to 'nana::timer::interval(int)'
                         timer_.interval(80);
                                           ^
In file included from G:/Files/C++/repos/nana/include/nana/gui/widgets/treebox.hpp:25,
                 from main.cpp:14:
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:57:8: note: candidate: 'void nana::timer::interval(std::chrono::milliseconds)'
   void interval(std::chrono::milliseconds ms);
        ^~~~~~~~
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:57:8: note:   no known conversion for argument 1 from 'int' to 'std::chrono::milliseconds' {aka 'std::chrono::duration<long long int, std::ratio<1, 1000> >'}
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:60:19: note: candidate: 'template<class Duration> Duration nana::timer::interval() const'
   inline Duration interval() const
                   ^~~~~~~~
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:60:19: note:   template argument deduction/substitution failed:
main.cpp:354:43: note:   candidate expects 0 arguments, 1 provided
                         timer_.interval(80);
                                           ^

the same

main.cpp: In lambda function:
main.cpp:315:70: warning: unused parameter 'a' [-Wunused-parameter]
                         timer_.elapse([this](const nana::arg_elapse& a)
                                              ~~~~~~~~~~~~~~~~~~~~~~~~^
main.cpp: In member function 'void demo::widget_show::_m_init_progresses()':
main.cpp:323:43: error: no matching function for call to 'nana::timer::interval(int)'
                         timer_.interval(80);
                                           ^
In file included from G:/Files/C++/repos/nana/include/nana/gui/widgets/treebox.hpp:25,
                 from main.cpp:20:
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:57:8: note: candidate: 'void nana::timer::interval(std::chrono::milliseconds)'
   void interval(std::chrono::milliseconds ms);
        ^~~~~~~~
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:57:8: note:   no known conversion for argument 1 from 'int' to 'std::chrono::milliseconds' {aka 'std::chrono::duration<long long int, std::ratio<1, 1000> >'}
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:60:19: note: candidate: 'template<class Duration> Duration nana::timer::interval() const'
   inline Duration interval() const
                   ^~~~~~~~
G:/Files/C++/repos/nana/include/nana/gui/timer.hpp:60:19: note:   template argument deduction/substitution failed:
main.cpp:323:43: note:   candidate expects 0 arguments, 1 provided
                         timer_.interval(80);
                                           ^

compiles, only warnings

main.cpp:8:13: warning: 'BOOL AddClipboardFormatListener(HWND)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
 BOOL WINAPI AddClipboardFormatListener(
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function 'int WinMain(HINSTANCE, HINSTANCE, char*, int)':
main.cpp:173:14: warning: unused variable 'wd' [-Wunused-variable]
         HWND wd = reinterpret_cast<HWND>(API::root(fm));
              ^~
qPCR4vir commented 5 years ago

WOW !!! Amazing! How did you find that? This is prehistoric! Yes, YES !! That is out of date !!! I have NO IDEA how that landed there. If you see https://github.com/qPCR4vir/nana-demo all is OK. And in the rigth panel of http://qpcr4vir.github.io/nana-doxy/html/examples.html all is OK too. But if you click on the left panel on examples it will show some veeeeery old files, like this: https://searchcode.com/codesearch/view/27847828/ I don't know what searchcode is, But it keep code from codeplex - do you know what it is? Well look at that file:

/*
 *  This is a demo of Nana C++ Library
 *  Author: Jinhao
 *  The demo requires Nana 0.2.5 and C++11 compiler
 *  Screenshot at http://sourceforge.net/projects/stdex
 */

nana 0.9 was on feb-2015. Wait ... wow... i found something here: https://github.com/qPCR4vir/myNana/blob/90319bed2a03c118bb4a0aaf1792df18dc8d2877/demo/widget_show/demo.cpp11.cpp it was commited in jul-2012. This is archaeology !!

Please, go to https://github.com/qPCR4vir/nana-demo, read the readme, and use the provided CMakeLists.txt to buid the demos. Good luck, and thanks for informing us of this. I'll try to fix it, but I have no idea how.

ilAYAli commented 5 years ago

you should really consider using Travis or similar, as your example code does not work well. This is very off-putting when trying out a new library.

I also had problems compiling nana core due to _genericu8string, which I "fixed" with:

diff --git a/include/nana/filesystem/filesystem_ext.hpp b/include/nana/filesystem/filesystem_ext.hpp
index 7bc69f0c..fe901c52 100644
--- a/include/nana/filesystem/filesystem_ext.hpp
+++ b/include/nana/filesystem/filesystem_ext.hpp
@@ -41,7 +41,8 @@ inline std::string generic_u8string(const std::filesystem::path& p)
 #if NANA_USING_BOOST_FILESYSTEM
        return nana::to_utf8(p.generic_wstring());
 #else
-       return p.generic_u8string();
+       return p.string();
+       //return p.generic_u8string();
 #endif
 }

diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp
index 9d0467d0..435f9107 100644
--- a/source/gui/msgbox.cpp
+++ b/source/gui/msgbox.cpp
@@ -1247,7 +1247,8 @@ namespace nana
                        auto files = impl->fbox.show();
                        if(!files.empty())
                        {
-                               impl->value = files.front().u8string();
+                               //impl->value = files.front().u8string();
+                               impl->value = files.front().string();
                                impl->path_edit.caption(impl->value);
                        }
                });

It seems like a lot of examples refer files that does not exist in the latest hotfix branch e.g wvl.hpp (https://github.com/qPCR4vir/nana-docs/wiki/Prevent-GUI-blocking-(updated) etc.

qPCR4vir commented 5 years ago

you should really consider using Travis or similar

Is this similar enough to Travis? https://travis-ci.org/cnjinhao/nana/builds/561369374#L665

Do you have an idea how to update a GitHub wiki automatically? I'm very thankfully to @genenorton for that last update, but as you see... I will be very thankfully to you if you update it. The latest hotfix and master version 1.7.2 is relatively recent for wiki users to update everything manually. Both nana and the std::filesystem are yet under develop, and breaking changes are frequent. While not perfect... changes are welcome. :-) I'm using gcc 9.1 in windows and Travis gcc 8.3 in linux with nana 1.7.2 develop and nana-demo develop. And you?

ilAYAli commented 5 years ago

you should really consider using Travis or similar

Is this similar enough to Travis? https://travis-ci.org/cnjinhao/nana/builds/561369374#L665

Indeed! Travis should be set up to verify that all examples, at least, compile and link.

Do you have an idea how to update a GitHub wiki automatically? I'm very thankfully to @genenorton for that last update, but as you see... I will be very thankfully to you if you update it.

A breaking change should not be part of a release unless all tests pass, which means that associated examples must be updated accordingly (as that is a test requirement). Having an updated wiki is nice, but I consider it even more important that the examples work. Maybe you can make the wiki refer to the examples, so that you don't need to update both?

Both nana and the std::filesystem are yet under develop, and breaking changes are frequent. While not perfect... changes are welcome. :-)

Breaking changes, as in breaking backwards compatibility is OK for a library under heavy development. Not being able to compile the library or the example code is not, as it makes it very hard for non-initiated developers to use the it. Honestly I was just looking for a modern c++ gui library that I can use with my project, not making the gui libary my project ;) However Nana seems very interesting, so I'll send a pull request with the changes I made - if I can get it working within a reasonable time-frame.

I'm using gcc 9.1 in windows and Travis gcc 8.3 in linux with nana 1.7.2 develop and nana-demo develop. And you?

I am using VS2019 at the moment.

qPCR4vir commented 5 years ago

OK, thank. Wait a bit before you waste your time making the PR. It may be some kind of configuration problem and not a code problem? Did you set VS2019 to use the "latest" c++ std? Is that c++17 or c++20? What branchs of nana and nana-demo are you using?

ilAYAli commented 5 years ago

Windows is not my usual development environment, so you might be right regarding std::filestystem and VS2019 default c++ standard. I'll try to explicitly set it to c++20. I used the hotfix-1.72 branch.

qPCR4vir commented 5 years ago

Travis should be set up to verify that all examples, at least, compile and link.

The link shows that we not only compile and link all examples with each push to nana, but run about half of then too, which means CI tests passed. We will find more bugs anyway ! Many people are reporting bugs continuously... thank to all them.

qPCR4vir commented 5 years ago

I used the hotfix-1.72 branch.

Ok, This can be a problem if you used the nana-demo hotfix brach. Only the nana-demo develop was actualized. Give me a minute...

I think, bu not sure, I tested VS2019 std-17 not 20.. But both need to work of course

ilAYAli commented 5 years ago

These are the errors I get when using the vc2019 project file (even after adding /std=c++latest) They disapear if I do as mentioned above, and replace generic_u8string() and u8string() with string(). I have no idea if that has any severe side effects though

Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0312   no suitable user-defined conversion from "std::basic_string<char8_t, std::char_traits<char8_t>, std::allocator<char8_t>>" to "std::string" exists   nana    C:\Users\petter\Dropbox\code\windows\venom\ds2\nana\include\nana\filesystem\filesystem_ext.hpp  44  
Severity    Code    Description Project File    Line    Suppression State
Error   C2440    'return': cannot convert from 'std::basic_string<char8_t,std::char_traits<char8_t>,std::allocator<char8_t>>' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' (compiling source file ..\..\source\filesystem\filesystem.cpp)   nana    C:\Users\petter\Dropbox\code\windows\venom\ds2\nana\include\nana\filesystem\filesystem_ext.hpp  44  
Severity    Code    Description Project File    Line    Suppression State
Error   C2440    'return': cannot convert from 'std::basic_string<char8_t,std::char_traits<char8_t>,std::allocator<char8_t>>' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' (compiling source file ..\..\source\gui\filebox.cpp) nana    C:\Users\petter\Dropbox\code\windows\venom\ds2\nana\include\nana\filesystem\filesystem_ext.hpp  44  
Severity    Code    Description Project File    Line    Suppression State
Error   C2679    binary '=': no operator found which takes a right-hand operand of type 'std::basic_string<char8_t,std::char_traits<char8_t>,std::allocator<char8_t>>' (or there is no acceptable conversion)   nana    C:\Users\petter\Dropbox\code\windows\venom\ds2\nana\source\gui\msgbox.cpp   1250    
Severity    Code    Description Project File    Line    Suppression State
Error   C2440    'return': cannot convert from 'std::basic_string<char8_t,std::char_traits<char8_t>,std::allocator<char8_t>>' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' (compiling source file ..\..\source\paint\image.cpp) nana    C:\Users\petter\Dropbox\code\windows\venom\ds2\nana\include\nana\filesystem\filesystem_ext.hpp  44  
ilAYAli commented 5 years ago

FYI: Nana v.1.7.1 built successfully by upgrading the vc2017 project file using vc2019. This branch contains the missing wvl.hpp file, but the second example here https://github.com/qPCR4vir/nana-docs/wiki/Prevent-GUI-blocking-(updated) does not work, as progressbar.hpp does not exist: #include <nana/gui/widgets/progressbar.hpp> I guess that should be progress.hpp as in the first example. It seems that this example also needs #include <nana/system/platform.hpp>

After adding this header, I got the example to work.

qPCR4vir commented 5 years ago

@ilAYAli thank you for your effort. I will fix the examples but it can take a few days. I merged the update into all samples in branches master, hotfix and develop of nana-demo. It have to work now with nana 1.7.2. Need to be tested in all possible configurations. People don't really like links in the wiki. They like full test. But I will add the links too.

Xeverous commented 5 years ago

Do you have an idea how to update a GitHub wiki automatically? I'm very thankfully to @genenorton for that last update, but as you see... I will be very thankfully to you if you update it.

A breaking change should not be part of a release unless all tests pass, which means that associated examples must be updated accordingly (as that is a test requirement).

The examples should be simply compiled alongside the library.

Having an updated wiki is nice, but I consider it even more important that the examples work. Maybe you can make the wiki refer to the examples, so that you don't need to update both?

@ilAYAli There is a different issue here. Nana has already 1 website doc, 2 wikis and 1 doxygen-generated doc. They have overlapping content and not eveyrthing is up to date. I think @qPCR4vir should either split everything into respective parts (so that no page repeats information) or move everything to max 1-2 places (eg Doxygen for autogenerated API + wiki as a more general higher-level overview).

Both nana and the std::filesystem are yet under develop, and breaking changes are frequent. While not perfect... changes are welcome. :-)

Breaking changes, as in breaking backwards compatibility is OK for a library under heavy development. Not being able to compile the library or the example code is not, as it makes it very hard for non-initiated developers to use the it.

I agree, there are many bugs in nana. So far the library is completely broken for me on Windows (and partially on Linux) - every hello world instantly segfaults, either due to static initialization order issues or strict aliasing violations. Also, only some of build configurations regarding filesystem work and compile correctly.

I have some fixes for singletons (which have some obvious bugs) but so far none of the simplest examples start correctly.

Honestly I was just looking for a modern c++ gui library that I can use with my project, not making the gui libary my project ;) However Nana seems very interesting, so I'll send a pull request with the changes I made - if I can get it working within a reasonable time-frame.

That was also my intention but while I may help with nana I think it's too immature to be used. The only other library which has similar modern C++ aims is Boost.UI which seems dead but I have some plan to revive it.

qPCR4vir commented 5 years ago

Well, @Xeverous is testing some very exotic build configuration, a corner case. It will be good to know what other complex libraries can be compiled with those configurations. I found users reporting that those optimizations are very buggy. The optimizator introduce errors by ignoring constructors with side effects, which is explicitally prohibited by the standard. Anyway, it will be interesting to see the results of such investigations, especially if it will bring less errors that what nana have now. I recompiled my soft today for nana 1.7.2 in windows 10, with minimal changes and it works OK. And many others are using nana in windows too, with no major problems (including compiling and running all the demos and examples in nana-demo). I think using and improving nana (like here ;-)) is largely more productive than "reviving Boost.UI" with its large number of dependencies, but it is just my (immature) opinion.

Xeverous commented 5 years ago

The commit you linked was definitely good, less questionable casts is definitely better and safer.

Well, @Xeverous is testing some very exotic build configuration, a corner case.

Exotic? I just spotted that not all filesystem options work on Windows when you try to compile with GCC. Will need to investigate more and refresh it, CMake files have changed many times since.

I found users reporting that those optimizations are very buggy. The optimizator introduce errors by ignoring constructors with side effects, which is explicitally prohibited by the standard.

Ignoring constructors is not allowed but the compiler may delay the construction untill:

So if you have files A and B, and want to guuarantee that a static object from B is constructed when doing something in A, you need to call some function from B.

See https://stackoverflow.com/a/56633997/4818802

I have a PR which patially solves this issue, but I'm still experiencing crashes. Need more testing.

"reviving Boost.UI" with its large number of dependencies, but it is just my (immature) opinion.

Boost.UI has only 2 dependencies: Boost and wxWidgets. Boost dependency might be removed (it was not used that much I think) and wxWidgets are old but definitely more stable and mature than nana.

We will see where it goes but competition is always good.

qPCR4vir commented 5 years ago

I just spotted that not all filesystem options work on Windows

That is COMPLETELY normal, because as you know the implementations of filesystem provided by "vendors" are changing constantly. Even the std is changing. But you also know that nana provides a partial implementation that can be used when your vendor provides not what was expected at some point. No error here. Please, just report or fix the issue and move on.

qPCR4vir commented 5 years ago

OK. As always, nana code can be improved. Specially implementation details. We will see. By now, what we need to make clear is that if you use (from your own initiative, not from any nana file or document) advanced optimizations like -flto -fno-fat-lto-objects you need to also set -Wl,--whole-archive, at least as a "temporary" workaround. OK? Can you test this?

Xeverous commented 5 years ago

IIRC CMake already adds -Wl--whole-archive, GCC knows that global objects must be created but it likes to delay their construction. If the compiler does not see any dependency (eg use of any function from the file where global object exists) it will ignore that file anyway.

I have fixed the crash on Windows (can post a PR) but after the fix the program still crashes for me :/. But now the crash seems to be caused by something different.

qPCR4vir commented 5 years ago

Hi @cnjinhao, I updated https://github.com/qPCR4vir/nana-docs/wiki/Prevent-GUI-blocking, but I think it runs not very well, specially the first: https://github.com/qPCR4vir/nana-demo/blob/prevent_blocking/Examples/prevent_blocking.cpp

and the last: https://github.com/qPCR4vir/nana-demo/blob/prevent_blocking/Examples/prevent_blocking_uncancel.cpp

You can just test branch prevent_blocking of https://github.com/qPCR4vir/nana-demo/

qPCR4vir commented 4 years ago

Fixed?

Xeverous commented 4 years ago

I'm currently working on a different project, don't have much time/will for nana right now, close this if you think examples are fixed.

qPCR4vir commented 4 years ago

in nana-demo all is OK execpt FreeMe (I will try last time to update, but probably deprecate/delete it) and the "new" prevent_blocking.cpp and prevent_blocking_uncancel.cpp which I need to test again. This means about 50 examples and demos compiling and RUNNING in CI travis-Ububtu. We will need to add more compilation variants to that (gcc 6/c++11, clang 6 and 8, macos, etc.). We may also improve the "automatic" testing of some examples. See for example how good it is for the calculator. I have updated most of the doxigen docs in nana-docs. As for the rest of examples in wikis and blogs, what we need is to make explicit reference on EACH such document of the nana and c++ std version used. It is impossible to updated all old examples in blogs/discussions/wikis.