Skip to content

Commit b735f18

Browse files
committed
Updated generate documentation.
1 parent 8d21263 commit b735f18

11 files changed

Lines changed: 5740 additions & 3817 deletions

File tree

docs/getting_started/installation_linux.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
- boost
1616
- libcurl
1717

18-
<details><summary>Ubuntu 22.04</summary>
18+
<details>
19+
<summary>Ubuntu 22.04</summary>
1920
<p>
2021

2122
Packages:
@@ -66,7 +67,8 @@ nvm install node
6667
</p>
6768
</details>
6869

69-
<details><summary>Arch Linux</summary>
70+
<details>
71+
<summary>Arch Linux</summary>
7072
<p>
7173

7274
Packages:

docs/getting_started/installation_windows.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Make sure that the python executeable is in PATH
2222
### Install nodejs and npm
2323

2424
Using nvm is the most practical way to install node and npm https://github.com/coreybutler/nvm-windows/releases.
25-
:::caution
25+
:::warning
2626

2727
If you already have node installed, uninstall it first before using nvm.
2828

@@ -35,7 +35,7 @@ If you already have node installed, uninstall it first before using nvm.
3535
Make sure that you have installed the following components for Visual Studio 2022 using the official Visual Studio Installer:
3636
- vcpkg package manager
3737
- C++ CMake tools for Windows
38-
- C++ Clang tools for Windows (<- not automatically included in the Desktop development with C++ Workload setting)
38+
- C++ Clang tools for Windows (\<\- not automatically included in the Desktop development with C++ Workload setting)
3939
- git for Windows, or install it via official downloads: https://gitforwindows.org/
4040

4141
Nui only supports clang and requires clang for WASM compilation.
@@ -152,7 +152,7 @@ You can also use the `-G"MSYS Makefiles"` generator, but this is strongly discou
152152

153153
:::info
154154

155-
Make sure you have installed `mingw-w64-clang-x86_64-ninja` not simply `ninja` and are operating from a
155+
Make sure you have installed `mingw-w64-clang-x86_64-ninja` not simply `ninja` and are operating from a
156156
msys2 clang64 environment terminal.
157157

158158
:::
@@ -357,15 +357,15 @@ Within CLion:
357357

358358
### Error: could not find git for clone of nui in FetchContent
359359

360-
CMake cannot find git in your PATH environment.
360+
CMake cannot find git in your PATH environment.
361361
For Visual Studio install git either using the Visual Studio Installer, or manually via the offical website.
362362
In the msys2 case, install git via the commandline.
363363

364364
### Could not find boost / curl / etc
365365

366366
If you are using Visual Studio, you did not setup vcpkg correctly. Retrace the steps outlined above ([Install vcpkg](#install-visual-studio-packages)), alternatively install vcpkg manually: https://vcpkg.io/en/getting-started.html
367367

368-
If you are using msys2, [install the correct packages](#install-msys2-if-you-dont-have-it-installed) for the clang64 subsystem.
368+
If you are using msys2, [install the correct packages](#install-msys2-if-you-dont-have-it-installed) for the clang64 subsystem.
369369

370370
### Other
371371

docs/reference/make_resizeable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Nui::ElementRenderer func()
2525
}
2626
```
2727

28-
:::caution
28+
:::warning
2929

3030
Requires 'nui/make_resizeable' to be imported somewhere in your javascript/typescript files.
3131

docs/reference/text.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ label{}(
2121
// highlight-end
2222
)
2323
```
24-
Text content can also be dynamic using Nui::Observed<std::string>.
24+
Text content can also be dynamic using `Nui::Observed<std::string>`.

docs/reference/window.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int main()
147147
}
148148
```
149149

150-
### Window::bind(std::string const& name, std::function<void(nlohmann::json const&)> const& callback)
150+
### `Window::bind(std::string const& name, std::function<void(nlohmann::json const&)> const& callback)`
151151
Bind a function into the web context. These will be available under globalThis.nui_rpc.backend.NAME
152152
Prefer to use the RpcHub instead.
153153

@@ -164,7 +164,7 @@ int main()
164164
}
165165
```
166166

167-
### Window::unbind(std::string const& name)
167+
### `Window::unbind(std::string const& name)`
168168
Unbinds a function from the web context.
169169

170170
```cpp
@@ -179,7 +179,7 @@ int main()
179179
}
180180
```
181181

182-
### Window::getExecutor()
182+
### `Window::getExecutor()`
183183
Returns the executor of the window.
184184

185185
```cpp
@@ -198,7 +198,7 @@ int main()
198198
}
199199
```
200200

201-
### Window::run()
201+
### `Window::run()`
202202
Runs / Shows the window.
203203

204204
```cpp
@@ -212,7 +212,7 @@ int main()
212212
}
213213
```
214214

215-
### Window::setHtml(std::string_view html, bool fromFilesystem = false)
215+
### `Window::setHtml(std::string_view html, bool fromFilesystem = false)`
216216
Sets the html of the window.
217217
When "fromFilesystem" is true, the file is dumped to a temporary file and loaded from there.
218218

@@ -227,7 +227,7 @@ int main()
227227
}
228228
```
229229

230-
### Window::eval(std::string const& code)
230+
### `Window::eval(std::string const& code)`
231231
Evaluates the given code in the web context.
232232

233233
```cpp
@@ -243,7 +243,7 @@ int main()
243243
}
244244
```
245245

246-
### Window::eval(std::filesystem::path const& file)
246+
### `Window::eval(std::filesystem::path const& file)`
247247
Evaluates the given file in the web context.
248248

249249
```cpp
@@ -259,23 +259,23 @@ int main()
259259
}
260260
```
261261

262-
### Window::init(std::string const& code)
262+
### `Window::init(std::string const& code)`
263263
Places javascript in the window.
264264

265-
### Window::init(std::filesystem::path const& file)
265+
### `Window::init(std::filesystem::path const& file)`
266266
Places javascript in the window from a file.
267267

268-
### void* Window::getNativeWindow()
268+
### `void* Window::getNativeWindow()`
269269
Returns a pointer to the native window.
270270
`HWND` on windows.
271271
`GtkWindow*` on linux.
272272
`id` on macos.
273273

274-
### void* Window::getNativeWebView()
274+
### `void* Window::getNativeWebView()`
275275
Returns a pointer to the native webview.
276276
cast to `ICoreWebView2*` on windows.
277277
cast using `WEBKIT_WEB_VIEW(getNativeWebView())` on linux.
278278
And its an `id` on macos.
279279

280-
### Window::setConsoleOutput(bool enabled)
280+
### `Window::setConsoleOutput(bool enabled)`
281281
Enables or disables console output from the webview on linux systems.

docs/tutorials/attributes.md

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,62 @@ const auto ui = button{
8585
}
8686
}
8787
```
88+
Using "event" for custom events of some ui libraries:
89+
```cpp
90+
const auto ui = button{
91+
"change"_event = [](Nui::val event) {
92+
// The event parameter has the same content as the javascript equivalent would.
93+
}
94+
}
95+
```
96+
8897
The event paramter is a [Val](/docs/reference/val) of type [Mouse Event](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent).
8998

9099
Events always process view updates when the function scope is left. So if you change an `Observed<T>` the view will be automatically updated.
91100

101+
### Nui::val wrappers for events
102+
103+
Some events already have wrapper classes that give easier access to the underlying val.
104+
105+
```cpp
106+
#include <nui/frontend/api/mouse_event.hpp>
107+
108+
const auto ui = button{
109+
onClick = [](Nui::WebApi::MouseEvent event){
110+
std::cout << "click event clientX: " << event.clientX();
111+
}
112+
}
113+
```
114+
115+
You can create your own wrapper if it takes a val for construction:
116+
```cpp
117+
#include <nui/frontend/val_wrapper.hpp>
118+
119+
// using ValWrapper is entirely optional:
120+
class MyWrapper : public Nui::ValWrapper
121+
{
122+
public:
123+
MyWrapper(Nui::val val)
124+
: Nui::ValWrapper{std::move(val)}
125+
{}
126+
127+
std::string myProperty() const
128+
{
129+
return val_["myProperty"].as<std::string>();
130+
// or:
131+
// return val()["myProperty"].as<std::string>();
132+
}
133+
};
134+
135+
// Use it later now:
136+
137+
const auto ui = button{
138+
onClick = [](MyWrapper event){
139+
std::cout << "myProperty: " << event.myProperty();
140+
}
141+
}
142+
```
143+
92144
## Observed Value Generator
93145
94146
Sometimes you want to process observed values before rendering.
@@ -100,34 +152,42 @@ Nui::Observed<int> spanSubclass = 0;
100152
101153
const auto ui = span{
102154
// Observe changes on the passed Nui::Observed<T> and generate a class from that
103-
class_ = observe(spanClasses, spanSubclass).generate([&spanClasses, &spanSubclass](){
155+
class_ = observe(spanClasses, spanSubclass).generate([](std::vector<std::string> const& spanClasses, int spanSubclass){
104156
// use .value to access the underlying wrapped value of a Nui::Observed:
105157
auto classes = std::accumulate(
106-
std::begin(spanClasses.value()),
107-
std::end(spanClasses.value()),
158+
std::begin(spanClasses),
159+
std::end(spanClasses),
108160
std::string{},
109161
[](auto accum, auto const& elem){
110162
accum = std::move(accum) + " " + elem;
111163
}
112164
);
113165
if (!accum.empty())
114166
accum.erase(accum.begin());
115-
accum += " spanSubclass" + std::to_string(spanSubclass.value());
167+
accum += " spanSubclass" + std::to_string(spanSubclass);
116168
return accum;
117169
})
118170
}();
119171
```
172+
The passed function to "generate" may also take no arguments.
173+
174+
Sometimes you dont want to set attributes on an element, but object properties.
175+
This is used by some ui frameworks for their parameters, like ui5 webcomponents:
120176
For properties this looks as follows:
121177
```cpp
122178
Nui::Observed<int> num{3};
179+
// for prop:
180+
using namespace Nui::Attributes::Literals;
123181

124182
input{
125-
checked = observe(num).generateProperty([&num](){
126-
return num.value() % 2;
183+
"checked"_prop = observe(num).generate([](int num){
184+
return num % 2;
127185
})
128186

129187
// Or:
130-
// "checked"_prop = observe(num).generate(/*...*/)
188+
// checked = observe(num).generateProperty([](int num){
189+
// return num % 2;
190+
// })
131191
}()
132192
```
133193

docs/tutorials/observed_rendering.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ This is possible through this syntax:
1010
Nui::Observed<std::string> str{"test"};
1111
Nui::Observed<int> number{0};
1212

13+
const auto ui = div{}(
14+
observe(str, number),
15+
// This function is recalled and regenerates its respective elements,
16+
// when 'str' or 'number' changes.
17+
[](std::string const& str, int number) -> Nui::ElementRenderer {
18+
const auto result = str + std::to_string(number);
19+
return span{}(result);
20+
}
21+
)
22+
```
23+
Alternatively (generate function takes no arguments):
24+
```cpp
25+
Nui::Observed<std::string> str{"test"};
26+
Nui::Observed<int> number{0};
27+
1328
const auto ui = div{}(
1429
observe(str, number),
1530
// This function is recalled and regenerates its respective elements,

docs/tutorials/range_rendering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ auto foo() {
135135
```
136136

137137
## Notes about the Optimization
138-
The ranges optimization that is applied to Observed<std::vector> and Observed<std::deque> makes it so that only the changed/inserted elements are rerendered and only erased elements are removed and nothing else is rerendered.
138+
The ranges optimization that is applied to `Nui::Observed<std::vector>` and `Nui::Observed<std::deque>` makes it so that only the changed/inserted elements are rerendered and only erased elements are removed and nothing else is rerendered.
139139
This is done by tracking the changes using some algorithms on an interval tree.
140140

141141
Insertions, modifications and erasures are only ever tracked alone, so if you switch from inserting elements to modifying elements a rerender is forced.

docs/tutorials/rpc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Frontend <-> Backend Communication
1+
# Frontend \<\-\> Backend Communication
22

33
Nui provides a way to communicate between frontend and the main process running the WebView.
44
This intentionally does not use async in the frontend, because using Asyncify comes with a considerable

0 commit comments

Comments
 (0)