diff --git a/docs/reference/window.md b/docs/reference/window.md index cacf7e9..71c6674 100644 --- a/docs/reference/window.md +++ b/docs/reference/window.md @@ -15,10 +15,13 @@ int main() Nui::Window wnd1{}; std::unique_ptr wnd2{}; - wnd.bind("myFunction", [&wnd2](nlohmann::json const&) { - wnd2 = std::make_unique(); - wnd2->setSize(800, 600); - wnd2->setHtml("

Hello World!

"); + wnd.bind("myFunction", [&wnd2, &wnd1](nlohmann::json const&) { + // required on windows to spawn the second window not from within this thread: + wnd1.dispatch([](){ + wnd2 = std::make_unique(); + wnd2->setSize(800, 600); + wnd2->setHtml("

Hello World!

"); + }); }); wnd.run(); diff --git a/docs/tutorials/rpc.md b/docs/tutorials/rpc.md index be19814..b0bed8a 100644 --- a/docs/tutorials/rpc.md +++ b/docs/tutorials/rpc.md @@ -36,7 +36,7 @@ All are disabled by default for security reasons. ### Usage -#### Backend +#### Backend Registering a function that is callable from the frontend: ```cpp #include @@ -56,7 +56,7 @@ int main() // highlight-start hub.registerFunction( - "functionName", + "functionName", // Parameters can either be be converted from json by nlohmann::json.get>... [&hub](std::string const& responseId, int param2){ // ... @@ -65,7 +65,7 @@ int main() ); hub.registerFunction( - "functionName", + "functionName", // ...or a nlohmann::json and you can dissect it yourself: [](nlohmann::json const& args){ // ... @@ -118,7 +118,7 @@ void foo() // Useful RAII unregister (also available in backend): { - auto unregisterWhenThisFallsOutOfScope = + auto unregisterWhenThisFallsOutOfScope = Nui::RpcClient::autoRegisterFunction("asdf", [](){}); } // asdf no longer exists here. @@ -165,7 +165,7 @@ void foo() Example: ```cpp -#include +#include void foo() { @@ -287,7 +287,7 @@ Nui::ThrottledFunction throttled; void foo() { throttle( - 200 /*ms*/, + 200 /*ms*/, [](){ std::cout << "Not printed faster than 200ms after the last call."; }, @@ -319,7 +319,7 @@ Nui::TimerHandle timer; void foo() { Nui::setInterval( - 500 /*ms*/, + 500 /*ms*/, // Called every 500ms [](){std::cout << "Hello!\n";}, [&timer](Nui::TimerHandle&& t){