Skip to content

Commit

Permalink
Impl Write on text buffers and Editable widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
ranfdev committed Aug 4, 2023
1 parent 413eae2 commit 383d1f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gtk4/src/editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ unsafe extern "C" fn insert_text_trampoline<T, F: Fn(&T, &str, &mut i32) + 'stat
&mut *position,
);
}

impl<T: EditableExt> std::fmt::Write for T {

Check failure on line 60 in gtk4/src/editable.rs

View workflow job for this annotation

GitHub Actions / macOS

type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)

Check failure on line 60 in gtk4/src/editable.rs

View workflow job for this annotation

GitHub Actions / Windows MSVC

type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
fn write_str(&mut self, s: &str) -> std::fmt::Result {
self.insert_text(s, &mut -1);
Ok(())
}
}
8 changes: 8 additions & 0 deletions gtk4/src/entry_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
8 changes: 8 additions & 0 deletions gtk4/src/text_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ pub trait TextBufferExtManual: sealed::Sealed + IsA<TextBuffer> + 'static {
}

impl<O: IsA<TextBuffer>> 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(())
}
}

0 comments on commit 383d1f7

Please sign in to comment.