mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 04:48:27 +00:00
C++ Platform: remove the experimental namespace
This commit is contained in:
parent
a29123a498
commit
116648ffcf
6 changed files with 37 additions and 54 deletions
|
|
@ -54,12 +54,10 @@ using cbindgen_private::TraversalOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(DOXYGEN)
|
#if !defined(DOXYGEN)
|
||||||
namespace experimental {
|
|
||||||
namespace platform {
|
namespace platform {
|
||||||
class SkiaRenderer;
|
class SkiaRenderer;
|
||||||
class SoftwareRenderer;
|
class SoftwareRenderer;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace private_api {
|
namespace private_api {
|
||||||
|
|
@ -278,8 +276,8 @@ public:
|
||||||
const cbindgen_private::WindowAdapterRcOpaque &handle() const { return inner; }
|
const cbindgen_private::WindowAdapterRcOpaque &handle() const { return inner; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class slint::experimental::platform::SkiaRenderer;
|
friend class slint::platform::SkiaRenderer;
|
||||||
friend class slint::experimental::platform::SoftwareRenderer;
|
friend class slint::platform::SoftwareRenderer;
|
||||||
cbindgen_private::WindowAdapterRcOpaque inner;
|
cbindgen_private::WindowAdapterRcOpaque inner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,6 @@ typedef struct objc_object NSWindow;
|
||||||
|
|
||||||
namespace slint {
|
namespace slint {
|
||||||
|
|
||||||
/// This namespace contains experimental API.
|
|
||||||
/// No compatibility across version.
|
|
||||||
///
|
|
||||||
/// \private
|
|
||||||
namespace experimental {
|
|
||||||
|
|
||||||
/// Namespace to be used when you implement your own Platform
|
/// Namespace to be used when you implement your own Platform
|
||||||
namespace platform {
|
namespace platform {
|
||||||
|
|
||||||
|
|
@ -492,7 +486,6 @@ inline std::optional<std::chrono::milliseconds> duration_until_next_timer_update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,10 @@
|
||||||
# include "windowadapter_win.h"
|
# include "windowadapter_win.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace slint_platform = slint::experimental::platform;
|
struct MyPlatform : public slint::platform::Platform
|
||||||
|
|
||||||
struct MyPlatform : public slint_platform::Platform
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<MyWindowAdapter> the_window;
|
std::unique_ptr<MyWindowAdapter> the_window;
|
||||||
std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() override
|
std::unique_ptr<slint::platform::WindowAdapter> create_window_adapter() override
|
||||||
{
|
{
|
||||||
return std::move(the_window);
|
return std::move(the_window);
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +33,7 @@ void AppView::attachToWindow(WINDOW_HANDLE winId)
|
||||||
auto p = std::make_unique<MyPlatform>();
|
auto p = std::make_unique<MyPlatform>();
|
||||||
p->the_window = std::make_unique<MyWindowAdapter>(winId);
|
p->the_window = std::make_unique<MyWindowAdapter>(winId);
|
||||||
myWindow = p->the_window.get();
|
myWindow = p->the_window.get();
|
||||||
slint_platform::set_platform(std::move(p));
|
slint::platform::set_platform(std::move(p));
|
||||||
|
|
||||||
// AppWindow is the auto-generated slint code
|
// AppWindow is the auto-generated slint code
|
||||||
static auto app = AppWindow::create();
|
static auto app = AppWindow::create();
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
namespace slint_platform = slint::experimental::platform;
|
|
||||||
|
|
||||||
struct Geometry
|
struct Geometry
|
||||||
{
|
{
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
|
@ -19,11 +17,11 @@ struct Geometry
|
||||||
uint32_t height = 0;
|
uint32_t height = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MyWindowAdapter : public slint_platform::WindowAdapter
|
struct MyWindowAdapter : public slint::platform::WindowAdapter
|
||||||
{
|
{
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
Geometry geometry = { 0, 0, 600, 300 };
|
Geometry geometry = { 0, 0, 600, 300 };
|
||||||
std::optional<slint_platform::SkiaRenderer> m_renderer;
|
std::optional<slint::platform::SkiaRenderer> m_renderer;
|
||||||
|
|
||||||
MyWindowAdapter(HWND winId)
|
MyWindowAdapter(HWND winId)
|
||||||
{
|
{
|
||||||
|
|
@ -56,13 +54,13 @@ struct MyWindowAdapter : public slint_platform::WindowAdapter
|
||||||
NULL // Additional application data
|
NULL // Additional application data
|
||||||
);
|
);
|
||||||
|
|
||||||
m_renderer.emplace(slint_platform::NativeWindowHandle::from_win32(hwnd, hInstance),
|
m_renderer.emplace(slint::platform::NativeWindowHandle::from_win32(hwnd, hInstance),
|
||||||
slint::PhysicalSize({ 600, 300 }));
|
slint::PhysicalSize({ 600, 300 }));
|
||||||
|
|
||||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)this);
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
slint_platform::AbstractRenderer &renderer() override { return m_renderer.value(); }
|
slint::platform::AbstractRenderer &renderer() override { return m_renderer.value(); }
|
||||||
|
|
||||||
slint::PhysicalSize physical_size() const override
|
slint::PhysicalSize physical_size() const override
|
||||||
{
|
{
|
||||||
|
|
@ -146,7 +144,7 @@ struct MyWindowAdapter : public slint_platform::WindowAdapter
|
||||||
case WM_PAINT: {
|
case WM_PAINT: {
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
BeginPaint(hwnd, &ps);
|
BeginPaint(hwnd, &ps);
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
self->render();
|
self->render();
|
||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -163,7 +161,7 @@ struct MyWindowAdapter : public slint_platform::WindowAdapter
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
self->mouse_event(uMsg, lParam);
|
self->mouse_event(uMsg, lParam);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,12 @@
|
||||||
|
|
||||||
#include "appwindow.h"
|
#include "appwindow.h"
|
||||||
|
|
||||||
#include "slint_platform.h"
|
#include <slint_platform.h>
|
||||||
|
|
||||||
#include <QtGui/QtGui>
|
#include <QtGui/QtGui>
|
||||||
#include <QtGui/qpa/qplatformnativeinterface.h>
|
#include <QtGui/qpa/qplatformnativeinterface.h>
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
namespace slint_platform = slint::experimental::platform;
|
|
||||||
|
|
||||||
slint::PointerEventButton convert_button(Qt::MouseButtons b)
|
slint::PointerEventButton convert_button(Qt::MouseButtons b)
|
||||||
{
|
{
|
||||||
switch (b) {
|
switch (b) {
|
||||||
|
|
@ -25,7 +23,7 @@ slint::PointerEventButton convert_button(Qt::MouseButtons b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static slint_platform::NativeWindowHandle window_handle_for_qt_window(QWindow *window)
|
static slint::platform::NativeWindowHandle window_handle_for_qt_window(QWindow *window)
|
||||||
{
|
{
|
||||||
// Ensure that the native window surface exists
|
// Ensure that the native window surface exists
|
||||||
window->create();
|
window->create();
|
||||||
|
|
@ -35,10 +33,10 @@ static slint_platform::NativeWindowHandle window_handle_for_qt_window(QWindow *w
|
||||||
native->nativeResourceForWindow(QByteArray("nsview"), window));
|
native->nativeResourceForWindow(QByteArray("nsview"), window));
|
||||||
NSWindow *nswindow = reinterpret_cast<NSWindow *>(
|
NSWindow *nswindow = reinterpret_cast<NSWindow *>(
|
||||||
native->nativeResourceForWindow(QByteArray("nswindow"), window));
|
native->nativeResourceForWindow(QByteArray("nswindow"), window));
|
||||||
return slint_platform::NativeWindowHandle::from_appkit(nsview, nswindow);
|
return slint::platform::NativeWindowHandle::from_appkit(nsview, nswindow);
|
||||||
#elif defined Q_OS_WIN
|
#elif defined Q_OS_WIN
|
||||||
auto wid = Qt::HANDLE(window->winId());
|
auto wid = Qt::HANDLE(window->winId());
|
||||||
return slint_platform::NativeWindowHandle::from_win32(wid, GetModuleHandle(nullptr));
|
return slint::platform::NativeWindowHandle::from_win32(wid, GetModuleHandle(nullptr));
|
||||||
#else
|
#else
|
||||||
// Try Wayland first, then XLib, then Xcb
|
// Try Wayland first, then XLib, then Xcb
|
||||||
auto wid = window->winId();
|
auto wid = window->winId();
|
||||||
|
|
@ -49,21 +47,21 @@ static slint_platform::NativeWindowHandle window_handle_for_qt_window(QWindow *w
|
||||||
native->nativeResourceForIntegration(QByteArray("wl_display")))) {
|
native->nativeResourceForIntegration(QByteArray("wl_display")))) {
|
||||||
auto *wayland_surface = reinterpret_cast<wl_surface *>(
|
auto *wayland_surface = reinterpret_cast<wl_surface *>(
|
||||||
native->nativeResourceForWindow(QByteArray("surface"), window));
|
native->nativeResourceForWindow(QByteArray("surface"), window));
|
||||||
return slint_platform::NativeWindowHandle::from_wayland(wayland_surface, wayland_display);
|
return slint::platform::NativeWindowHandle::from_wayland(wayland_surface, wayland_display);
|
||||||
} else if (auto *x11_display = native->nativeResourceForWindow(QByteArray("display"), window)) {
|
} else if (auto *x11_display = native->nativeResourceForWindow(QByteArray("display"), window)) {
|
||||||
return slint_platform::NativeWindowHandle::from_x11_xlib(wid, wid, x11_display, screen);
|
return slint::platform::NativeWindowHandle::from_x11_xlib(wid, wid, x11_display, screen);
|
||||||
} else if (auto *xcb_connection = reinterpret_cast<xcb_connection_t *>(
|
} else if (auto *xcb_connection = reinterpret_cast<xcb_connection_t *>(
|
||||||
native->nativeResourceForWindow(QByteArray("connection"), window))) {
|
native->nativeResourceForWindow(QByteArray("connection"), window))) {
|
||||||
return slint_platform::NativeWindowHandle::from_x11_xcb(wid, wid, xcb_connection, screen);
|
return slint::platform::NativeWindowHandle::from_x11_xcb(wid, wid, xcb_connection, screen);
|
||||||
} else {
|
} else {
|
||||||
throw "Unsupported windowing system (tried waylamd, xlib, and xcb)";
|
throw "Unsupported windowing system (tried waylamd, xlib, and xcb)";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyWindow : public QWindow, public slint_platform::WindowAdapter
|
class MyWindow : public QWindow, public slint::platform::WindowAdapter
|
||||||
{
|
{
|
||||||
std::optional<slint_platform::SkiaRenderer> m_renderer;
|
std::optional<slint::platform::SkiaRenderer> m_renderer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MyWindow(QWindow *parentWindow = nullptr) : QWindow(parentWindow)
|
MyWindow(QWindow *parentWindow = nullptr) : QWindow(parentWindow)
|
||||||
|
|
@ -72,7 +70,7 @@ public:
|
||||||
m_renderer.emplace(window_handle_for_qt_window(this), physical_size());
|
m_renderer.emplace(window_handle_for_qt_window(this), physical_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
slint_platform::AbstractRenderer &renderer() override { return m_renderer.value(); }
|
slint::platform::AbstractRenderer &renderer() override { return m_renderer.value(); }
|
||||||
|
|
||||||
/*void keyEvent(QKeyEvent *event) override
|
/*void keyEvent(QKeyEvent *event) override
|
||||||
{
|
{
|
||||||
|
|
@ -81,7 +79,7 @@ public:
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *ev) override
|
void paintEvent(QPaintEvent *ev) override
|
||||||
{
|
{
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
|
|
||||||
m_renderer->render();
|
m_renderer->render();
|
||||||
|
|
||||||
|
|
@ -127,32 +125,32 @@ public:
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent *event) override
|
void mousePressEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
window().dispatch_pointer_press_event(
|
window().dispatch_pointer_press_event(
|
||||||
slint::LogicalPosition({ float(event->pos().x()), float(event->pos().y()) }),
|
slint::LogicalPosition({ float(event->pos().x()), float(event->pos().y()) }),
|
||||||
convert_button(event->button()));
|
convert_button(event->button()));
|
||||||
}
|
}
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override
|
void mouseReleaseEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
window().dispatch_pointer_release_event(
|
window().dispatch_pointer_release_event(
|
||||||
slint::LogicalPosition({ float(event->pos().x()), float(event->pos().y()) }),
|
slint::LogicalPosition({ float(event->pos().x()), float(event->pos().y()) }),
|
||||||
convert_button(event->button()));
|
convert_button(event->button()));
|
||||||
}
|
}
|
||||||
void mouseMoveEvent(QMouseEvent *event) override
|
void mouseMoveEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
window().dispatch_pointer_move_event(
|
window().dispatch_pointer_move_event(
|
||||||
slint::LogicalPosition({ float(event->pos().x()), float(event->pos().y()) }));
|
slint::LogicalPosition({ float(event->pos().x()), float(event->pos().y()) }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MyPlatform : public slint_platform::Platform
|
struct MyPlatform : public slint::platform::Platform
|
||||||
{
|
{
|
||||||
|
|
||||||
std::unique_ptr<QWindow> parentWindow;
|
std::unique_ptr<QWindow> parentWindow;
|
||||||
|
|
||||||
std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() override
|
std::unique_ptr<slint::platform::WindowAdapter> create_window_adapter() override
|
||||||
{
|
{
|
||||||
return std::make_unique<MyWindow>(parentWindow.get());
|
return std::make_unique<MyWindow>(parentWindow.get());
|
||||||
}
|
}
|
||||||
|
|
@ -165,11 +163,11 @@ int main(int argc, char **argv)
|
||||||
static MyPlatform *plarform = [] {
|
static MyPlatform *plarform = [] {
|
||||||
auto platform = std::make_unique<MyPlatform>();
|
auto platform = std::make_unique<MyPlatform>();
|
||||||
auto p2 = platform.get();
|
auto p2 = platform.get();
|
||||||
slint_platform::set_platform(std::move(platform));
|
slint::platform::set_platform(std::move(platform));
|
||||||
return p2;
|
return p2;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
|
|
||||||
auto my_ui = App::create();
|
auto my_ui = App::create();
|
||||||
// mu_ui->set_property(....);
|
// mu_ui->set_property(....);
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,16 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace slint_platform = slint::experimental::platform;
|
struct TestPlatform : slint::platform::Platform
|
||||||
|
|
||||||
struct TestPlatform : slint_platform::Platform
|
|
||||||
{
|
{
|
||||||
std::mutex the_mutex;
|
std::mutex the_mutex;
|
||||||
std::deque<slint_platform::Platform::Task> queue;
|
std::deque<slint::platform::Platform::Task> queue;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
std::chrono::time_point<std::chrono::steady_clock> start = std::chrono::steady_clock::now();
|
std::chrono::time_point<std::chrono::steady_clock> start = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
/// Returns a new WindowAdapter
|
/// Returns a new WindowAdapter
|
||||||
virtual std::unique_ptr<slint_platform::WindowAdapter> create_window_adapter() override
|
virtual std::unique_ptr<slint::platform::WindowAdapter> create_window_adapter() override
|
||||||
{
|
{
|
||||||
assert(!"creating window in this test");
|
assert(!"creating window in this test");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -33,8 +31,8 @@ struct TestPlatform : slint_platform::Platform
|
||||||
virtual void run_event_loop() override
|
virtual void run_event_loop() override
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
slint_platform::update_timers_and_animations();
|
slint::platform::update_timers_and_animations();
|
||||||
std::optional<slint_platform::Platform::Task> event;
|
std::optional<slint::platform::Platform::Task> event;
|
||||||
{
|
{
|
||||||
std::unique_lock lock(the_mutex);
|
std::unique_lock lock(the_mutex);
|
||||||
if (queue.empty()) {
|
if (queue.empty()) {
|
||||||
|
|
@ -42,7 +40,7 @@ struct TestPlatform : slint_platform::Platform
|
||||||
quit = false;
|
quit = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (auto duration = slint_platform::duration_until_next_timer_update()) {
|
if (auto duration = slint::platform::duration_until_next_timer_update()) {
|
||||||
cv.wait_for(lock, *duration);
|
cv.wait_for(lock, *duration);
|
||||||
} else {
|
} else {
|
||||||
cv.wait(lock);
|
cv.wait(lock);
|
||||||
|
|
@ -67,7 +65,7 @@ struct TestPlatform : slint_platform::Platform
|
||||||
cv.notify_all();
|
cv.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void run_in_event_loop(slint_platform::Platform::Task event) override
|
virtual void run_in_event_loop(slint::platform::Platform::Task event) override
|
||||||
{
|
{
|
||||||
const std::unique_lock lock(the_mutex);
|
const std::unique_lock lock(the_mutex);
|
||||||
queue.push_back(std::move(event));
|
queue.push_back(std::move(event));
|
||||||
|
|
@ -83,7 +81,7 @@ struct TestPlatform : slint_platform::Platform
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
bool init_platform = (slint_platform::set_platform(std::make_unique<TestPlatform>()), true);
|
bool init_platform = (slint::platform::set_platform(std::make_unique<TestPlatform>()), true);
|
||||||
|
|
||||||
TEST_CASE("C++ Singleshot Timers")
|
TEST_CASE("C++ Singleshot Timers")
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue