1 // Copyright 2016, The Gtk-rs Project Developers. 2 // See the COPYRIGHT file at the top-level directory of this distribution. 3 // Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT> 4 5 use gdk; 6 use glib::object::Cast; 7 use glib::object::IsA; 8 use glib::translate::*; 9 use gtk_sys; 10 use std::mem; 11 use ColorButton; 12 use Widget; 13 14 pub trait ColorButtonExtManual: 'static { new_with_color(color: &gdk::Color) -> ColorButton15 fn new_with_color(color: &gdk::Color) -> ColorButton; 16 get_color(&self) -> gdk::Color17 fn get_color(&self) -> gdk::Color; 18 set_color(&self, color: &gdk::Color)19 fn set_color(&self, color: &gdk::Color); 20 } 21 22 impl<O: IsA<ColorButton>> ColorButtonExtManual for O { new_with_color(color: &gdk::Color) -> ColorButton23 fn new_with_color(color: &gdk::Color) -> ColorButton { 24 assert_initialized_main_thread!(); 25 unsafe { 26 Widget::from_glib_none(gtk_sys::gtk_color_button_new_with_color(color)).unsafe_cast() 27 } 28 } 29 get_color(&self) -> gdk::Color30 fn get_color(&self) -> gdk::Color { 31 unsafe { 32 let mut color = mem::MaybeUninit::uninit(); 33 gtk_sys::gtk_color_button_get_color(self.as_ref().to_glib_none().0, color.as_mut_ptr()); 34 color.assume_init() 35 } 36 } 37 set_color(&self, color: &gdk::Color)38 fn set_color(&self, color: &gdk::Color) { 39 unsafe { gtk_sys::gtk_color_button_set_color(self.as_ref().to_glib_none().0, color) } 40 } 41 } 42