Skip to content

Commit

Permalink
docs(events): new events
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 25, 2023
1 parent f1d1f3e commit 5bd3957
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs/getting-started/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import Admonition from '@theme/Admonition';
import close from './events/close.cpp';
import closed from './events/closed.cpp';
import resize from './events/resize.cpp';
import maximize from './events/maximize.cpp';
import minimize from './events/minimize.cpp';
import focus from './events/focus.cpp';

import urlChanged from './events/url-changed.cpp';
import loadFinished from './events/load-finished.cpp';
import loadStarted from './events/load-started.cpp';
Expand Down Expand Up @@ -37,6 +41,18 @@ smartview.on<saucer::window_event::resize>([](int width, int height)
});
```

:::tip
If you only need an event to be called once, you can also use the `once` method.

```cpp title="Example Once Callback (Resize Window)"
smartview.once<saucer::window_event::resize>([](int width, int height)
{
// Fired once, then automatically removed.
});
```

:::

### Remove Callback

As previously mentioned you can unregister callbacks by saving their id.
Expand Down Expand Up @@ -101,6 +117,39 @@ smartview.clear(saucer::window_event::resize);
{close.split('\n').slice(2).join('\n')}
</CodeBlock>
</TabItem>
<TabItem value="maximize" label="Maximize">
Called when the Window is maximized or restored after being maximized.
<br />
<br />
<CodeBlock language="cpp" title="Signature">
{maximize.split('\n')[0]}
</CodeBlock>
<CodeBlock language="cpp" title="Example">
{maximize.split('\n').slice(2).join('\n')}
</CodeBlock>
</TabItem>
<TabItem value="minimize" label="Minimize">
Called when the Window is minimized or restored after being minimized.
<br />
<br />
<CodeBlock language="cpp" title="Signature">
{minimize.split('\n')[0]}
</CodeBlock>
<CodeBlock language="cpp" title="Example">
{minimize.split('\n').slice(2).join('\n')}
</CodeBlock>
</TabItem>
<TabItem value="focus" label="Focus">
Called when the Window gains or loses focus.
<br />
<br />
<CodeBlock language="cpp" title="Signature">
{focus.split('\n')[0]}
</CodeBlock>
<CodeBlock language="cpp" title="Example">
{focus.split('\n').slice(2).join('\n')}
</CodeBlock>
</TabItem>
</Tabs>
</TabItem>
<TabItem value="webview" label="WebView">
Expand Down
6 changes: 6 additions & 0 deletions docs/getting-started/events/focus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
std::function<void(bool)>

smartview.on<saucer::window_event::focus>([](bool focus)
{
std::print("WebView is focused: {}!\n", focus);
});
6 changes: 6 additions & 0 deletions docs/getting-started/events/maximize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
std::function<void(bool)>

smartview.on<saucer::window_event::maximize>([](bool state)
{
std::print("WebView is maximized: {}!\n", state);
});
6 changes: 6 additions & 0 deletions docs/getting-started/events/minimize.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
std::function<void(bool)>

smartview.on<saucer::window_event::minimize>([](bool state)
{
std::print("WebView is minimized: {}!\n", state);
});

0 comments on commit 5bd3957

Please sign in to comment.