slint/api/cpp/tests/manual/platform_native/appview.cpp
Simon Hausmann baba30370a Simplify C++ WindowAdapter <> Renderer interface further
Instead of the WindowAdapter being a template for a concept, let's just
use an abstract base class for the renderer. Since we provide the
renderers, this simplifies two things:

- Ownership becomes clear to the user by creating the renderer instance
in a field of theirs.
- All template use goes away on the user side.
2023-05-21 14:40:43 +02:00

43 lines
1.1 KiB
C++

// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
#ifndef UNICODE
# define UNICODE
#endif
#include "appwindow.h"
#include <slint_platform.h>
#if defined(_WIN32) || defined(_WIN64)
# include "windowadapter_win.h"
#endif
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
{
return std::move(the_window);
}
};
AppView::AppView() { }
void AppView::setGeometry(int x, int y, int width, int height)
{
myWindow->setGeometry(x, y, width, height);
}
void AppView::attachToWindow(WINDOW_HANDLE winId)
{
auto p = std::make_unique<MyPlatform>();
p->the_window = std::make_unique<MyWindowAdapter>(winId);
myWindow = p->the_window.get();
slint_platform::Platform::register_platform(std::move(p));
// AppWindow is the auto-generated slint code
static auto app = AppWindow::create();
app->show();
}