mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Expose clipboard_text accessors to C++ (#3265)
This commit is contained in:
parent
93a8f604a8
commit
1de7b1512c
4 changed files with 60 additions and 3 deletions
|
@ -6,7 +6,7 @@ use alloc::rc::Rc;
|
|||
use core::ffi::c_void;
|
||||
use i_slint_core::api::{LogicalSize, PhysicalSize, Window};
|
||||
use i_slint_core::graphics::IntSize;
|
||||
use i_slint_core::platform::{Platform, PlatformError};
|
||||
use i_slint_core::platform::{Clipboard, Platform, PlatformError};
|
||||
use i_slint_core::renderer::Renderer;
|
||||
use i_slint_core::window::ffi::WindowAdapterRcOpaque;
|
||||
use i_slint_core::window::{WindowAdapter, WindowProperties};
|
||||
|
@ -141,6 +141,9 @@ struct CppPlatform {
|
|||
window_factory: unsafe extern "C" fn(PlatformUserData, *mut WindowAdapterRcOpaque),
|
||||
#[cfg(not(feature = "std"))]
|
||||
duration_since_start: unsafe extern "C" fn(PlatformUserData) -> u64,
|
||||
set_clipboard_text: unsafe extern "C" fn(PlatformUserData, &SharedString, _clipboard: u8),
|
||||
clipboard_text:
|
||||
unsafe extern "C" fn(PlatformUserData, &mut SharedString, _clipboard: u8) -> bool,
|
||||
run_event_loop: unsafe extern "C" fn(PlatformUserData),
|
||||
quit_event_loop: unsafe extern "C" fn(PlatformUserData),
|
||||
invoke_from_event_loop: unsafe extern "C" fn(PlatformUserData, PlatformTaskOpaque),
|
||||
|
@ -181,6 +184,23 @@ impl Platform for CppPlatform {
|
|||
invoke_from_event_loop: self.invoke_from_event_loop,
|
||||
}))
|
||||
}
|
||||
|
||||
fn set_clipboard_text(&self, _text: &str, _clipboard: Clipboard) {
|
||||
let shared_text = SharedString::from(_text);
|
||||
unsafe { (self.set_clipboard_text)(self.user_data, &shared_text, _clipboard as u8) }
|
||||
}
|
||||
|
||||
fn clipboard_text(&self, _clipboard: Clipboard) -> Option<String> {
|
||||
let mut out_text = SharedString::new();
|
||||
let status =
|
||||
unsafe { (self.clipboard_text)(self.user_data, &mut out_text, _clipboard as u8) };
|
||||
|
||||
if !status {
|
||||
None
|
||||
} else {
|
||||
String::from(out_text).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CppEventLoopProxy {
|
||||
|
@ -218,6 +238,12 @@ pub unsafe extern "C" fn slint_platform_register(
|
|||
drop: unsafe extern "C" fn(PlatformUserData),
|
||||
window_factory: unsafe extern "C" fn(PlatformUserData, *mut WindowAdapterRcOpaque),
|
||||
#[allow(unused)] duration_since_start: unsafe extern "C" fn(PlatformUserData) -> u64,
|
||||
set_clipboard_text: unsafe extern "C" fn(PlatformUserData, &SharedString, _clipboard: u8),
|
||||
clipboard_text: unsafe extern "C" fn(
|
||||
PlatformUserData,
|
||||
&mut SharedString,
|
||||
_clipboard: u8,
|
||||
) -> bool,
|
||||
run_event_loop: unsafe extern "C" fn(PlatformUserData),
|
||||
quit_event_loop: unsafe extern "C" fn(PlatformUserData),
|
||||
invoke_from_event_loop: unsafe extern "C" fn(PlatformUserData, PlatformTaskOpaque),
|
||||
|
@ -228,6 +254,8 @@ pub unsafe extern "C" fn slint_platform_register(
|
|||
window_factory,
|
||||
#[cfg(not(feature = "std"))]
|
||||
duration_since_start,
|
||||
set_clipboard_text,
|
||||
clipboard_text,
|
||||
run_event_loop,
|
||||
quit_event_loop,
|
||||
invoke_from_event_loop,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue