mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 13:38:35 +00:00
20 lines
545 B
Rust
20 lines
545 B
Rust
use clipboard::{ClipboardContext, ClipboardProvider};
|
|
use imgui::{ClipboardBackend, ImStr, ImString};
|
|
|
|
pub struct ClipboardSupport(ClipboardContext);
|
|
|
|
pub fn init() -> Option<ClipboardSupport> {
|
|
ClipboardContext::new()
|
|
.ok()
|
|
.map(|ctx| ClipboardSupport(ctx))
|
|
}
|
|
|
|
impl ClipboardBackend for ClipboardSupport {
|
|
fn get(&mut self) -> Option<ImString> {
|
|
self.0.get_contents().ok().map(|text| text.into())
|
|
}
|
|
fn set(&mut self, text: &ImStr) {
|
|
let _ = self.0.set_contents(text.to_str().to_owned());
|
|
}
|
|
}
|