diff --git a/CHANGELOG.md b/CHANGELOG.md index b0bb3cb86..7072f5150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file. - Warnings are now shown in the online code editor. - `sixtyfps::invoke_from_event_loop` was added to the C++ and Rust APIs, to run a function in the UI thread from any thread. + - `sixtyfps::run_event_loop()` and `sixtyfps::quit_event_loop()` were added to the Rust and C++ APIs to start and quit the main event loop. - `z` property on items. - The type in two-way bindings can now be omitted. - It's possible to declare aliases for callbacks (`callback clicked <=> other.clicked;`) diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index f9877cacc..15a89aecd 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -39,8 +39,8 @@ using cbindgen_private::ItemVTable; using ComponentRef = vtable::VRef; using ItemRef = vtable::VRef; using ItemVisitorRefMut = vtable::VRefMut; -using cbindgen_private::ItemWeak; using cbindgen_private::ComponentRc; +using cbindgen_private::ItemWeak; using cbindgen_private::TraversalOrder; } @@ -636,11 +636,18 @@ struct VersionCheckHelper }; } +/// Enters the main event loop. This is necessary in order to receive +/// events from the windowing system in order to render to the screen +/// and react to user input. inline void run_event_loop() { cbindgen_private::sixtyfps_run_event_loop(); } +/// Schedules the main event loop for termination. This function is meant +/// to be called from callbacks triggered by the UI. After calling the function, +/// it will return immediately and once control is passed back to the event loop, +/// the initial call to sixtyfps::run_event_loop() will return. inline void quit_event_loop() { cbindgen_private::sixtyfps_quit_event_loop(); diff --git a/api/sixtyfps-rs/lib.rs b/api/sixtyfps-rs/lib.rs index 312e83ad2..27f925044 100644 --- a/api/sixtyfps-rs/lib.rs +++ b/api/sixtyfps-rs/lib.rs @@ -263,6 +263,14 @@ pub fn run_event_loop() { .run_event_loop(sixtyfps_corelib::backend::EventLoopQuitBehavior::QuitOnLastWindowClosed); } +/// Schedules the main event loop for termination. This function is meant +/// to be called from callbacks triggered by the UI. After calling the function, +/// it will return immediately and once control is passed back to the event loop, +/// the initial call to [`run_event_loop()`] will return. +pub fn quit_event_loop() { + sixtyfps_rendering_backend_default::backend().quit_event_loop(); +} + /// Adds the specified function to an internal queue, notifies the event loop to wake up. /// Once woken up, any queued up functors will be invoked. ///