mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-30 23:27:22 +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
|
@ -267,6 +267,7 @@ public:
|
|||
class Platform
|
||||
{
|
||||
public:
|
||||
using Clipboard = cbindgen_private::Clipboard;
|
||||
virtual ~Platform() = default;
|
||||
Platform(const Platform &) = delete;
|
||||
Platform &operator=(const Platform &) = delete;
|
||||
|
@ -286,6 +287,19 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
/// Sends the given text into the system clipboard.
|
||||
///
|
||||
/// If the platform doesn't support the specified clipboard, this function should do nothing
|
||||
virtual void set_clipboard_text(const SharedString &, Clipboard) { }
|
||||
|
||||
/// Returns a copy of text stored in the system clipboard, if any.
|
||||
///
|
||||
/// If the platform doesn't support the specified clipboard, the function should return nullopt
|
||||
virtual std::optional<SharedString> clipboard_text(Clipboard)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
/// Spins an event loop and renders the visible windows.
|
||||
virtual void run_event_loop() { }
|
||||
|
||||
|
@ -364,6 +378,19 @@ inline void set_platform(std::unique_ptr<Platform> platform)
|
|||
return reinterpret_cast<const Platform *>(p)->duration_since_start().count();
|
||||
#endif
|
||||
},
|
||||
[](void *p, const SharedString *text, uint8_t clipboard) {
|
||||
reinterpret_cast<Platform *>(p)->set_clipboard_text(*text,
|
||||
Platform::Clipboard(clipboard));
|
||||
},
|
||||
[](void *p, SharedString *out_text, uint8_t clipboard) -> bool {
|
||||
auto maybe_clipboard = reinterpret_cast<Platform *>(p)->clipboard_text(
|
||||
Platform::Clipboard(clipboard));
|
||||
|
||||
bool status = maybe_clipboard.has_value();
|
||||
if (status)
|
||||
*out_text = maybe_clipboard.value();
|
||||
return status;
|
||||
},
|
||||
[](void *p) { return reinterpret_cast<Platform *>(p)->run_event_loop(); },
|
||||
[](void *p) { return reinterpret_cast<Platform *>(p)->quit_event_loop(); },
|
||||
[](void *p, cbindgen_private::PlatformTaskOpaque event) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue