From 5bd3957c1300d928e7f2280ed737f943724076d1 Mon Sep 17 00:00:00 2001 From: Curve Date: Wed, 25 Oct 2023 23:25:09 +0200 Subject: [PATCH] docs(events): new events --- docs/getting-started/events.mdx | 49 ++++++++++++++++++++++++ docs/getting-started/events/focus.cpp | 6 +++ docs/getting-started/events/maximize.cpp | 6 +++ docs/getting-started/events/minimize.cpp | 6 +++ 4 files changed, 67 insertions(+) create mode 100644 docs/getting-started/events/focus.cpp create mode 100644 docs/getting-started/events/maximize.cpp create mode 100644 docs/getting-started/events/minimize.cpp diff --git a/docs/getting-started/events.mdx b/docs/getting-started/events.mdx index 73279f1..53aa589 100644 --- a/docs/getting-started/events.mdx +++ b/docs/getting-started/events.mdx @@ -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'; @@ -37,6 +41,18 @@ smartview.on([](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([](int width, int height) +{ + // Fired once, then automatically removed. +}); +``` + +::: + ### Remove Callback As previously mentioned you can unregister callbacks by saving their id. @@ -101,6 +117,39 @@ smartview.clear(saucer::window_event::resize); {close.split('\n').slice(2).join('\n')} + + Called when the Window is maximized or restored after being maximized. +
+
+ + {maximize.split('\n')[0]} + + + {maximize.split('\n').slice(2).join('\n')} + +
+ + Called when the Window is minimized or restored after being minimized. +
+
+ + {minimize.split('\n')[0]} + + + {minimize.split('\n').slice(2).join('\n')} + +
+ + Called when the Window gains or loses focus. +
+
+ + {focus.split('\n')[0]} + + + {focus.split('\n').slice(2).join('\n')} + +
diff --git a/docs/getting-started/events/focus.cpp b/docs/getting-started/events/focus.cpp new file mode 100644 index 0000000..decd583 --- /dev/null +++ b/docs/getting-started/events/focus.cpp @@ -0,0 +1,6 @@ +std::function + +smartview.on([](bool focus) +{ + std::print("WebView is focused: {}!\n", focus); +}); \ No newline at end of file diff --git a/docs/getting-started/events/maximize.cpp b/docs/getting-started/events/maximize.cpp new file mode 100644 index 0000000..3051982 --- /dev/null +++ b/docs/getting-started/events/maximize.cpp @@ -0,0 +1,6 @@ +std::function + +smartview.on([](bool state) +{ + std::print("WebView is maximized: {}!\n", state); +}); \ No newline at end of file diff --git a/docs/getting-started/events/minimize.cpp b/docs/getting-started/events/minimize.cpp new file mode 100644 index 0000000..cf2b95e --- /dev/null +++ b/docs/getting-started/events/minimize.cpp @@ -0,0 +1,6 @@ +std::function + +smartview.on([](bool state) +{ + std::print("WebView is minimized: {}!\n", state); +}); \ No newline at end of file