forked from gtk-rs/gtk3-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gtk: add Scrollable subclassing support
- Loading branch information
1 parent
20a5f70
commit 5f65745
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::{Border, Scrollable}; | ||
use glib::subclass::prelude::*; | ||
use glib::translate::*; | ||
use glib::Cast; | ||
|
||
pub trait ScrollableImpl: ObjectImpl { | ||
fn get_border(&self, scrollable: &Self::Type) -> Option<Border>; | ||
} | ||
|
||
unsafe impl<T: ScrollableImpl> IsImplementable<T> for Scrollable { | ||
unsafe extern "C" fn interface_init( | ||
iface: glib::ffi::gpointer, | ||
_iface_data: glib::ffi::gpointer, | ||
) { | ||
let scrollable_iface = &mut *(iface as *mut ffi::GtkScrollableInterface); | ||
|
||
scrollable_iface.get_border = Some(scrollable_get_border::<T>); | ||
} | ||
} | ||
|
||
unsafe extern "C" fn scrollable_get_border<T: ScrollableImpl>( | ||
scrollable: *mut ffi::GtkScrollable, | ||
borderptr: *mut ffi::GtkBorder, | ||
) -> glib::ffi::gboolean { | ||
let instance = &*(scrollable as *mut T::Instance); | ||
let imp = instance.get_impl(); | ||
|
||
if let Some(border) = | ||
imp.get_border(from_glib_borrow::<_, Scrollable>(scrollable).unsafe_cast_ref()) | ||
{ | ||
*borderptr = *border.to_glib_full(); | ||
true.to_glib() | ||
} else { | ||
*borderptr = *std::ptr::null(); | ||
false.to_glib() | ||
} | ||
} |