API cleanup: Rename PlatformWindow to WindowAdapter

This commit is contained in:
Tobias Hunger 2022-08-29 12:17:41 +02:00 committed by Tobias Hunger
parent 344f5c437b
commit 1e6ffeaa0f
50 changed files with 600 additions and 604 deletions

View file

@ -135,7 +135,7 @@ fn gen_corelib(
config.export.include = [
"ComponentVTable",
"Slice",
"PlatformWindowRcOpaque",
"WindowAdapterRcOpaque",
"PropertyAnimation",
"EasingCurve",
"TextHorizontalAlignment",
@ -189,7 +189,7 @@ fn gen_corelib(
"slint_property_listener_scope_is_dirty",
"PropertyTrackerOpaque",
"CallbackOpaque",
"PlatformWindowRc",
"WindowAdapterRc",
"VoidArg",
"KeyEventArg",
"PointerEventArg",
@ -453,9 +453,9 @@ fn gen_corelib(
.with_after_include(
r"
namespace slint {
namespace private_api { class PlatformWindowRc; }
namespace private_api { class WindowAdapterRc; }
namespace cbindgen_private {
using slint::private_api::PlatformWindowRc;
using slint::private_api::WindowAdapterRc;
using namespace vtable;
struct KeyEvent; struct PointerEvent;
using private_api::Property;

View file

@ -83,23 +83,23 @@ inline void assert_main_thread()
#endif
}
class PlatformWindowRc
class WindowAdapterRc
{
public:
explicit PlatformWindowRc(cbindgen_private::PlatformWindowRcOpaque adopted_inner)
explicit WindowAdapterRc(cbindgen_private::WindowAdapterRcOpaque adopted_inner)
: inner(adopted_inner)
{
}
PlatformWindowRc() { cbindgen_private::slint_windowrc_init(&inner); }
~PlatformWindowRc() { cbindgen_private::slint_windowrc_drop(&inner); }
PlatformWindowRc(const PlatformWindowRc &other)
WindowAdapterRc() { cbindgen_private::slint_windowrc_init(&inner); }
~WindowAdapterRc() { cbindgen_private::slint_windowrc_drop(&inner); }
WindowAdapterRc(const WindowAdapterRc &other)
{
assert_main_thread();
cbindgen_private::slint_windowrc_clone(&other.inner, &inner);
}
PlatformWindowRc(PlatformWindowRc &&) = delete;
PlatformWindowRc &operator=(PlatformWindowRc &&) = delete;
PlatformWindowRc &operator=(const PlatformWindowRc &other)
WindowAdapterRc(WindowAdapterRc &&) = delete;
WindowAdapterRc &operator=(WindowAdapterRc &&) = delete;
WindowAdapterRc &operator=(const WindowAdapterRc &other)
{
assert_main_thread();
if (this != &other) {
@ -226,7 +226,7 @@ public:
}
private:
cbindgen_private::PlatformWindowRcOpaque inner;
cbindgen_private::WindowAdapterRcOpaque inner;
};
constexpr inline ItemTreeNode make_item_node(uint32_t child_count, uint32_t child_index,
@ -374,7 +374,7 @@ public:
/// \private
/// Internal function used by the generated code to construct a new instance of this
/// public API wrapper.
explicit Window(const private_api::PlatformWindowRc &windowrc) : inner(windowrc) { }
explicit Window(const private_api::WindowAdapterRc &windowrc) : inner(windowrc) { }
Window(const Window &other) = delete;
Window &operator=(const Window &other) = delete;
Window(Window &&other) = delete;
@ -432,12 +432,12 @@ public:
void set_size(const slint::Size<unsigned int> &size) { inner.set_size(size); }
/// \private
private_api::PlatformWindowRc &window_handle() { return inner; }
private_api::WindowAdapterRc &window_handle() { return inner; }
/// \private
const private_api::PlatformWindowRc &window_handle() const { return inner; }
const private_api::WindowAdapterRc &window_handle() const { return inner; }
private:
private_api::PlatformWindowRc inner;
private_api::WindowAdapterRc inner;
};
/// A Timer that can call a callback at repeated interval

View file

@ -564,7 +564,7 @@ public:
/// such as the position on the screen.
const slint::Window &window()
{
const cbindgen_private::PlatformWindowRcOpaque *win_ptr = nullptr;
const cbindgen_private::WindowAdapterRcOpaque *win_ptr = nullptr;
cbindgen_private::slint_interpreter_component_instance_window(inner(), &win_ptr);
return *reinterpret_cast<const slint::Window *>(win_ptr);
}
@ -582,10 +582,10 @@ public:
/// it may return nullptr if the Qt backend is not used at runtime.
QWidget *qwidget() const
{
const cbindgen_private::PlatformWindowRcOpaque *win_ptr = nullptr;
const cbindgen_private::WindowAdapterRcOpaque *win_ptr = nullptr;
cbindgen_private::slint_interpreter_component_instance_window(inner(), &win_ptr);
auto wid = reinterpret_cast<QWidget *>(cbindgen_private::slint_qt_get_widget(
reinterpret_cast<const cbindgen_private::PlatformWindowRc *>(win_ptr)));
reinterpret_cast<const cbindgen_private::WindowAdapterRc *>(win_ptr)));
return wid;
}
#endif
@ -1010,10 +1010,10 @@ inline void send_keyboard_string_sequence(const slint::interpreter::ComponentIns
const slint::SharedString &str,
KeyboardModifiers modifiers = {})
{
const cbindgen_private::PlatformWindowRcOpaque *win_ptr = nullptr;
const cbindgen_private::WindowAdapterRcOpaque *win_ptr = nullptr;
cbindgen_private::slint_interpreter_component_instance_window(
reinterpret_cast<const cbindgen_private::ErasedComponentBox *>(component), &win_ptr);
cbindgen_private::send_keyboard_string_sequence(
&str, modifiers, reinterpret_cast<const cbindgen_private::PlatformWindowRc *>(win_ptr));
&str, modifiers, reinterpret_cast<const cbindgen_private::WindowAdapterRc *>(win_ptr));
}
}

View file

@ -4,7 +4,7 @@
/*! This crate just expose the function used by the C++ integration */
use core::ffi::c_void;
use i_slint_core::window::{ffi::PlatformWindowRcOpaque, PlatformWindow};
use i_slint_core::window::{ffi::WindowAdapterRcOpaque, WindowAdapter};
use std::rc::Rc;
#[doc(hidden)]
@ -17,13 +17,13 @@ pub fn use_modules() -> usize {
}
#[no_mangle]
pub unsafe extern "C" fn slint_windowrc_init(out: *mut PlatformWindowRcOpaque) {
pub unsafe extern "C" fn slint_windowrc_init(out: *mut WindowAdapterRcOpaque) {
assert_eq!(
core::mem::size_of::<Rc<dyn PlatformWindow>>(),
core::mem::size_of::<PlatformWindowRcOpaque>()
core::mem::size_of::<Rc<dyn WindowAdapter>>(),
core::mem::size_of::<WindowAdapterRcOpaque>()
);
let win = i_slint_backend_selector::with_platform_abstraction(|b| b.create_window());
core::ptr::write(out as *mut Rc<dyn PlatformWindow>, win);
core::ptr::write(out as *mut Rc<dyn WindowAdapter>, win);
}
#[no_mangle]
@ -67,16 +67,14 @@ pub unsafe extern "C" fn slint_quit_event_loop() {
#[no_mangle]
pub unsafe extern "C" fn slint_register_font_from_path(
win: *const PlatformWindowRcOpaque,
win: *const WindowAdapterRcOpaque,
path: &i_slint_core::SharedString,
error_str: *mut i_slint_core::SharedString,
) {
let platform_window = &*(win as *const Rc<dyn PlatformWindow>);
let window_adapter = &*(win as *const Rc<dyn WindowAdapter>);
core::ptr::write(
error_str,
match platform_window
.renderer()
.register_font_from_path(std::path::Path::new(path.as_str()))
match window_adapter.renderer().register_font_from_path(std::path::Path::new(path.as_str()))
{
Ok(()) => Default::default(),
Err(err) => err.to_string().into(),
@ -86,14 +84,14 @@ pub unsafe extern "C" fn slint_register_font_from_path(
#[no_mangle]
pub unsafe extern "C" fn slint_register_font_from_data(
win: *const PlatformWindowRcOpaque,
win: *const WindowAdapterRcOpaque,
data: i_slint_core::slice::Slice<'static, u8>,
error_str: *mut i_slint_core::SharedString,
) {
let platform_window = &*(win as *const Rc<dyn PlatformWindow>);
let window_adapter = &*(win as *const Rc<dyn WindowAdapter>);
core::ptr::write(
error_str,
match platform_window.renderer().register_font_from_memory(data.as_slice()) {
match window_adapter.renderer().register_font_from_memory(data.as_slice()) {
Ok(()) => Default::default(),
Err(err) => err.to_string().into(),
},