mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 02:39:28 +00:00
C++: some changes to the Platform API
This commit is contained in:
parent
c05ee8b87d
commit
42bb2bf705
4 changed files with 15 additions and 7 deletions
|
@ -172,12 +172,14 @@ public:
|
|||
Platform() = default;
|
||||
|
||||
/// Returns a new WindowAdapter
|
||||
virtual std::unique_ptr<WindowAdapter> create_window_adapter() const = 0;
|
||||
virtual std::unique_ptr<WindowAdapter> create_window_adapter() = 0;
|
||||
|
||||
# ifndef SLINT_FEATURE_STD
|
||||
/// Returns the amount of milliseconds since start of the application.
|
||||
///
|
||||
/// This function should only be implemented if the runtime is compiled with no_std
|
||||
virtual std::chrono::milliseconds duration_since_start() const { return {}; }
|
||||
# endif
|
||||
|
||||
/// Spins an event loop and renders the visible windows.
|
||||
virtual void run_event_loop() { }
|
||||
|
@ -244,12 +246,16 @@ public:
|
|||
cbindgen_private::slint_platform_register(
|
||||
platform.release(), [](void *p) { delete reinterpret_cast<const Platform *>(p); },
|
||||
[](void *p, cbindgen_private::WindowAdapterRcOpaque *out) {
|
||||
auto w = reinterpret_cast<const Platform *>(p)->create_window_adapter();
|
||||
auto w = reinterpret_cast<Platform *>(p)->create_window_adapter();
|
||||
*out = w->initialize();
|
||||
(void)w.release();
|
||||
},
|
||||
[](void *p) -> uint64_t {
|
||||
[]([[maybe_unused]] void *p) -> uint64_t {
|
||||
# ifdef SLINT_FEATURE_STD
|
||||
return 0;
|
||||
# else
|
||||
return reinterpret_cast<const Platform *>(p)->duration_since_start().count();
|
||||
# endif
|
||||
},
|
||||
[](void *p) { return reinterpret_cast<Platform *>(p)->run_event_loop(); },
|
||||
[](void *p) { return reinterpret_cast<Platform *>(p)->quit_event_loop(); },
|
||||
|
|
|
@ -16,8 +16,8 @@ namespace slint_platform = slint::experimental::platform;
|
|||
|
||||
struct MyPlatform : public slint_platform::Platform
|
||||
{
|
||||
mutable std::unique_ptr<MyWindowAdapter> the_window;
|
||||
std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() const override
|
||||
std::unique_ptr<MyWindowAdapter> the_window;
|
||||
std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() override
|
||||
{
|
||||
return std::move(the_window);
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ struct MyPlatform : public slint_platform::Platform
|
|||
|
||||
std::unique_ptr<QWindow> parentWindow;
|
||||
|
||||
std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() const override
|
||||
std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() override
|
||||
{
|
||||
return std::make_unique<MyWindow>(parentWindow.get());
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ struct TestPlatform : slint_platform::Platform
|
|||
std::chrono::time_point<std::chrono::steady_clock> start = std::chrono::steady_clock::now();
|
||||
|
||||
/// Returns a new WindowAdapter
|
||||
virtual std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() const override
|
||||
virtual std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() override
|
||||
{
|
||||
assert(!"creating window in this test");
|
||||
return nullptr;
|
||||
|
@ -74,11 +74,13 @@ struct TestPlatform : slint_platform::Platform
|
|||
cv.notify_all();
|
||||
}
|
||||
|
||||
#ifndef SLINT_FEATURE_STD
|
||||
virtual std::chrono::milliseconds duration_since_start() const override
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - start);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
bool init_platform = (TestPlatform::register_platform(std::make_unique<TestPlatform>()), true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue