diff --git a/gtk4/src/editable.rs b/gtk4/src/editable.rs index 026b73a9e1bd..c730297fa69d 100644 --- a/gtk4/src/editable.rs +++ b/gtk4/src/editable.rs @@ -56,3 +56,10 @@ unsafe extern "C" fn insert_text_trampoline std::fmt::Write for T { + fn write_str(&mut self, s: &str) -> std::fmt::Result { + self.insert_text(s, &mut -1); + Ok(()) + } +} diff --git a/gtk4/src/entry_buffer.rs b/gtk4/src/entry_buffer.rs index 41b65345fc56..40a0992feba1 100644 --- a/gtk4/src/entry_buffer.rs +++ b/gtk4/src/entry_buffer.rs @@ -127,3 +127,11 @@ impl Default for EntryBuffer { glib::Object::new() } } + +impl std::fmt::Write for EntryBuffer { + fn write_str(&mut self, s: &str) -> std::fmt::Result { + let pos = self.length(); + self.insert_text(pos, s); + Ok(()) + } +} diff --git a/gtk4/src/text_buffer.rs b/gtk4/src/text_buffer.rs index 0167c5062c8c..f077f0bc9a90 100644 --- a/gtk4/src/text_buffer.rs +++ b/gtk4/src/text_buffer.rs @@ -103,3 +103,11 @@ pub trait TextBufferExtManual: sealed::Sealed + IsA + 'static { } impl> TextBufferExtManual for O {} + +impl std::fmt::Write for TextBuffer { + fn write_str(&mut self, s: &str) -> std::fmt::Result { + let mut iter = self.end_iter(); + self.insert(&mut iter, s); + Ok(()) + } +}