mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-13 06:28:36 +00:00
18 lines
516 B
Rust
18 lines
516 B
Rust
use clipboard::{ClipboardContext, ClipboardProvider};
|
|
use imgui::{ClipboardBackend, ImStr, ImString};
|
|
|
|
pub struct ClipboardSupport(ClipboardContext);
|
|
|
|
pub fn init() -> Option<ClipboardSupport> {
|
|
ClipboardContext::new().ok().map(ClipboardSupport)
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|