1 // This file was generated by gir (https://github.com/gtk-rs/gir) 2 // from gir-files (https://github.com/gtk-rs/gir-files) 3 // DO NOT EDIT 4 5 use crate::Actionable; 6 use crate::Align; 7 use crate::Buildable; 8 use crate::Container; 9 use crate::Widget; 10 use glib::object::Cast; 11 use glib::object::IsA; 12 use glib::object::ObjectExt; 13 use glib::signal::connect_raw; 14 use glib::signal::SignalHandlerId; 15 use glib::translate::*; 16 use glib::StaticType; 17 use glib::ToValue; 18 use std::boxed::Box as Box_; 19 use std::fmt; 20 use std::mem::transmute; 21 22 glib::wrapper! { 23 #[doc(alias = "GtkSwitch")] 24 pub struct Switch(Object<ffi::GtkSwitch, ffi::GtkSwitchClass>) @extends Widget, @implements Buildable, Actionable; 25 26 match fn { 27 type_ => || ffi::gtk_switch_get_type(), 28 } 29 } 30 31 impl Switch { 32 #[doc(alias = "gtk_switch_new")] new() -> Switch33 pub fn new() -> Switch { 34 assert_initialized_main_thread!(); 35 unsafe { Widget::from_glib_none(ffi::gtk_switch_new()).unsafe_cast() } 36 } 37 38 // rustdoc-stripper-ignore-next 39 /// Creates a new builder-pattern struct instance to construct [`Switch`] objects. 40 /// 41 /// This method returns an instance of [`SwitchBuilder`] which can be used to create [`Switch`] objects. builder() -> SwitchBuilder42 pub fn builder() -> SwitchBuilder { 43 SwitchBuilder::default() 44 } 45 } 46 47 impl Default for Switch { default() -> Self48 fn default() -> Self { 49 Self::new() 50 } 51 } 52 53 #[derive(Clone, Default)] 54 // rustdoc-stripper-ignore-next 55 /// A [builder-pattern] type to construct [`Switch`] objects. 56 /// 57 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html 58 pub struct SwitchBuilder { 59 active: Option<bool>, 60 state: Option<bool>, 61 app_paintable: Option<bool>, 62 can_default: Option<bool>, 63 can_focus: Option<bool>, 64 events: Option<gdk::EventMask>, 65 expand: Option<bool>, 66 #[cfg(any(feature = "v3_20", feature = "dox"))] 67 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] 68 focus_on_click: Option<bool>, 69 halign: Option<Align>, 70 has_default: Option<bool>, 71 has_focus: Option<bool>, 72 has_tooltip: Option<bool>, 73 height_request: Option<i32>, 74 hexpand: Option<bool>, 75 hexpand_set: Option<bool>, 76 is_focus: Option<bool>, 77 margin: Option<i32>, 78 margin_bottom: Option<i32>, 79 margin_end: Option<i32>, 80 margin_start: Option<i32>, 81 margin_top: Option<i32>, 82 name: Option<String>, 83 no_show_all: Option<bool>, 84 opacity: Option<f64>, 85 parent: Option<Container>, 86 receives_default: Option<bool>, 87 sensitive: Option<bool>, 88 tooltip_markup: Option<String>, 89 tooltip_text: Option<String>, 90 valign: Option<Align>, 91 vexpand: Option<bool>, 92 vexpand_set: Option<bool>, 93 visible: Option<bool>, 94 width_request: Option<i32>, 95 action_name: Option<String>, 96 action_target: Option<glib::Variant>, 97 } 98 99 impl SwitchBuilder { 100 // rustdoc-stripper-ignore-next 101 /// Create a new [`SwitchBuilder`]. new() -> Self102 pub fn new() -> Self { 103 Self::default() 104 } 105 106 // rustdoc-stripper-ignore-next 107 /// Build the [`Switch`]. build(self) -> Switch108 pub fn build(self) -> Switch { 109 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 110 if let Some(ref active) = self.active { 111 properties.push(("active", active)); 112 } 113 if let Some(ref state) = self.state { 114 properties.push(("state", state)); 115 } 116 if let Some(ref app_paintable) = self.app_paintable { 117 properties.push(("app-paintable", app_paintable)); 118 } 119 if let Some(ref can_default) = self.can_default { 120 properties.push(("can-default", can_default)); 121 } 122 if let Some(ref can_focus) = self.can_focus { 123 properties.push(("can-focus", can_focus)); 124 } 125 if let Some(ref events) = self.events { 126 properties.push(("events", events)); 127 } 128 if let Some(ref expand) = self.expand { 129 properties.push(("expand", expand)); 130 } 131 #[cfg(any(feature = "v3_20", feature = "dox"))] 132 if let Some(ref focus_on_click) = self.focus_on_click { 133 properties.push(("focus-on-click", focus_on_click)); 134 } 135 if let Some(ref halign) = self.halign { 136 properties.push(("halign", halign)); 137 } 138 if let Some(ref has_default) = self.has_default { 139 properties.push(("has-default", has_default)); 140 } 141 if let Some(ref has_focus) = self.has_focus { 142 properties.push(("has-focus", has_focus)); 143 } 144 if let Some(ref has_tooltip) = self.has_tooltip { 145 properties.push(("has-tooltip", has_tooltip)); 146 } 147 if let Some(ref height_request) = self.height_request { 148 properties.push(("height-request", height_request)); 149 } 150 if let Some(ref hexpand) = self.hexpand { 151 properties.push(("hexpand", hexpand)); 152 } 153 if let Some(ref hexpand_set) = self.hexpand_set { 154 properties.push(("hexpand-set", hexpand_set)); 155 } 156 if let Some(ref is_focus) = self.is_focus { 157 properties.push(("is-focus", is_focus)); 158 } 159 if let Some(ref margin) = self.margin { 160 properties.push(("margin", margin)); 161 } 162 if let Some(ref margin_bottom) = self.margin_bottom { 163 properties.push(("margin-bottom", margin_bottom)); 164 } 165 if let Some(ref margin_end) = self.margin_end { 166 properties.push(("margin-end", margin_end)); 167 } 168 if let Some(ref margin_start) = self.margin_start { 169 properties.push(("margin-start", margin_start)); 170 } 171 if let Some(ref margin_top) = self.margin_top { 172 properties.push(("margin-top", margin_top)); 173 } 174 if let Some(ref name) = self.name { 175 properties.push(("name", name)); 176 } 177 if let Some(ref no_show_all) = self.no_show_all { 178 properties.push(("no-show-all", no_show_all)); 179 } 180 if let Some(ref opacity) = self.opacity { 181 properties.push(("opacity", opacity)); 182 } 183 if let Some(ref parent) = self.parent { 184 properties.push(("parent", parent)); 185 } 186 if let Some(ref receives_default) = self.receives_default { 187 properties.push(("receives-default", receives_default)); 188 } 189 if let Some(ref sensitive) = self.sensitive { 190 properties.push(("sensitive", sensitive)); 191 } 192 if let Some(ref tooltip_markup) = self.tooltip_markup { 193 properties.push(("tooltip-markup", tooltip_markup)); 194 } 195 if let Some(ref tooltip_text) = self.tooltip_text { 196 properties.push(("tooltip-text", tooltip_text)); 197 } 198 if let Some(ref valign) = self.valign { 199 properties.push(("valign", valign)); 200 } 201 if let Some(ref vexpand) = self.vexpand { 202 properties.push(("vexpand", vexpand)); 203 } 204 if let Some(ref vexpand_set) = self.vexpand_set { 205 properties.push(("vexpand-set", vexpand_set)); 206 } 207 if let Some(ref visible) = self.visible { 208 properties.push(("visible", visible)); 209 } 210 if let Some(ref width_request) = self.width_request { 211 properties.push(("width-request", width_request)); 212 } 213 if let Some(ref action_name) = self.action_name { 214 properties.push(("action-name", action_name)); 215 } 216 if let Some(ref action_target) = self.action_target { 217 properties.push(("action-target", action_target)); 218 } 219 glib::Object::new::<Switch>(&properties).expect("Failed to create an instance of Switch") 220 } 221 active(mut self, active: bool) -> Self222 pub fn active(mut self, active: bool) -> Self { 223 self.active = Some(active); 224 self 225 } 226 state(mut self, state: bool) -> Self227 pub fn state(mut self, state: bool) -> Self { 228 self.state = Some(state); 229 self 230 } 231 app_paintable(mut self, app_paintable: bool) -> Self232 pub fn app_paintable(mut self, app_paintable: bool) -> Self { 233 self.app_paintable = Some(app_paintable); 234 self 235 } 236 can_default(mut self, can_default: bool) -> Self237 pub fn can_default(mut self, can_default: bool) -> Self { 238 self.can_default = Some(can_default); 239 self 240 } 241 can_focus(mut self, can_focus: bool) -> Self242 pub fn can_focus(mut self, can_focus: bool) -> Self { 243 self.can_focus = Some(can_focus); 244 self 245 } 246 events(mut self, events: gdk::EventMask) -> Self247 pub fn events(mut self, events: gdk::EventMask) -> Self { 248 self.events = Some(events); 249 self 250 } 251 expand(mut self, expand: bool) -> Self252 pub fn expand(mut self, expand: bool) -> Self { 253 self.expand = Some(expand); 254 self 255 } 256 257 #[cfg(any(feature = "v3_20", feature = "dox"))] 258 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] focus_on_click(mut self, focus_on_click: bool) -> Self259 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self { 260 self.focus_on_click = Some(focus_on_click); 261 self 262 } 263 halign(mut self, halign: Align) -> Self264 pub fn halign(mut self, halign: Align) -> Self { 265 self.halign = Some(halign); 266 self 267 } 268 has_default(mut self, has_default: bool) -> Self269 pub fn has_default(mut self, has_default: bool) -> Self { 270 self.has_default = Some(has_default); 271 self 272 } 273 has_focus(mut self, has_focus: bool) -> Self274 pub fn has_focus(mut self, has_focus: bool) -> Self { 275 self.has_focus = Some(has_focus); 276 self 277 } 278 has_tooltip(mut self, has_tooltip: bool) -> Self279 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self { 280 self.has_tooltip = Some(has_tooltip); 281 self 282 } 283 height_request(mut self, height_request: i32) -> Self284 pub fn height_request(mut self, height_request: i32) -> Self { 285 self.height_request = Some(height_request); 286 self 287 } 288 hexpand(mut self, hexpand: bool) -> Self289 pub fn hexpand(mut self, hexpand: bool) -> Self { 290 self.hexpand = Some(hexpand); 291 self 292 } 293 hexpand_set(mut self, hexpand_set: bool) -> Self294 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self { 295 self.hexpand_set = Some(hexpand_set); 296 self 297 } 298 is_focus(mut self, is_focus: bool) -> Self299 pub fn is_focus(mut self, is_focus: bool) -> Self { 300 self.is_focus = Some(is_focus); 301 self 302 } 303 margin(mut self, margin: i32) -> Self304 pub fn margin(mut self, margin: i32) -> Self { 305 self.margin = Some(margin); 306 self 307 } 308 margin_bottom(mut self, margin_bottom: i32) -> Self309 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self { 310 self.margin_bottom = Some(margin_bottom); 311 self 312 } 313 margin_end(mut self, margin_end: i32) -> Self314 pub fn margin_end(mut self, margin_end: i32) -> Self { 315 self.margin_end = Some(margin_end); 316 self 317 } 318 margin_start(mut self, margin_start: i32) -> Self319 pub fn margin_start(mut self, margin_start: i32) -> Self { 320 self.margin_start = Some(margin_start); 321 self 322 } 323 margin_top(mut self, margin_top: i32) -> Self324 pub fn margin_top(mut self, margin_top: i32) -> Self { 325 self.margin_top = Some(margin_top); 326 self 327 } 328 name(mut self, name: &str) -> Self329 pub fn name(mut self, name: &str) -> Self { 330 self.name = Some(name.to_string()); 331 self 332 } 333 no_show_all(mut self, no_show_all: bool) -> Self334 pub fn no_show_all(mut self, no_show_all: bool) -> Self { 335 self.no_show_all = Some(no_show_all); 336 self 337 } 338 opacity(mut self, opacity: f64) -> Self339 pub fn opacity(mut self, opacity: f64) -> Self { 340 self.opacity = Some(opacity); 341 self 342 } 343 parent<P: IsA<Container>>(mut self, parent: &P) -> Self344 pub fn parent<P: IsA<Container>>(mut self, parent: &P) -> Self { 345 self.parent = Some(parent.clone().upcast()); 346 self 347 } 348 receives_default(mut self, receives_default: bool) -> Self349 pub fn receives_default(mut self, receives_default: bool) -> Self { 350 self.receives_default = Some(receives_default); 351 self 352 } 353 sensitive(mut self, sensitive: bool) -> Self354 pub fn sensitive(mut self, sensitive: bool) -> Self { 355 self.sensitive = Some(sensitive); 356 self 357 } 358 tooltip_markup(mut self, tooltip_markup: &str) -> Self359 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self { 360 self.tooltip_markup = Some(tooltip_markup.to_string()); 361 self 362 } 363 tooltip_text(mut self, tooltip_text: &str) -> Self364 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self { 365 self.tooltip_text = Some(tooltip_text.to_string()); 366 self 367 } 368 valign(mut self, valign: Align) -> Self369 pub fn valign(mut self, valign: Align) -> Self { 370 self.valign = Some(valign); 371 self 372 } 373 vexpand(mut self, vexpand: bool) -> Self374 pub fn vexpand(mut self, vexpand: bool) -> Self { 375 self.vexpand = Some(vexpand); 376 self 377 } 378 vexpand_set(mut self, vexpand_set: bool) -> Self379 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self { 380 self.vexpand_set = Some(vexpand_set); 381 self 382 } 383 visible(mut self, visible: bool) -> Self384 pub fn visible(mut self, visible: bool) -> Self { 385 self.visible = Some(visible); 386 self 387 } 388 width_request(mut self, width_request: i32) -> Self389 pub fn width_request(mut self, width_request: i32) -> Self { 390 self.width_request = Some(width_request); 391 self 392 } 393 action_name(mut self, action_name: &str) -> Self394 pub fn action_name(mut self, action_name: &str) -> Self { 395 self.action_name = Some(action_name.to_string()); 396 self 397 } 398 action_target(mut self, action_target: &glib::Variant) -> Self399 pub fn action_target(mut self, action_target: &glib::Variant) -> Self { 400 self.action_target = Some(action_target.clone()); 401 self 402 } 403 } 404 405 pub const NONE_SWITCH: Option<&Switch> = None; 406 407 pub trait SwitchExt: 'static { 408 #[doc(alias = "gtk_switch_get_active")] 409 #[doc(alias = "get_active")] is_active(&self) -> bool410 fn is_active(&self) -> bool; 411 412 #[doc(alias = "gtk_switch_get_state")] 413 #[doc(alias = "get_state")] state(&self) -> bool414 fn state(&self) -> bool; 415 416 #[doc(alias = "gtk_switch_set_active")] set_active(&self, is_active: bool)417 fn set_active(&self, is_active: bool); 418 419 #[doc(alias = "gtk_switch_set_state")] set_state(&self, state: bool)420 fn set_state(&self, state: bool); 421 422 #[doc(alias = "activate")] connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId423 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 424 emit_activate(&self)425 fn emit_activate(&self); 426 427 #[doc(alias = "state-set")] connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>( &self, f: F, ) -> SignalHandlerId428 fn connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>( 429 &self, 430 f: F, 431 ) -> SignalHandlerId; 432 433 #[doc(alias = "active")] connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId434 fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 435 436 #[doc(alias = "state")] connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId437 fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 438 } 439 440 impl<O: IsA<Switch>> SwitchExt for O { is_active(&self) -> bool441 fn is_active(&self) -> bool { 442 unsafe { from_glib(ffi::gtk_switch_get_active(self.as_ref().to_glib_none().0)) } 443 } 444 state(&self) -> bool445 fn state(&self) -> bool { 446 unsafe { from_glib(ffi::gtk_switch_get_state(self.as_ref().to_glib_none().0)) } 447 } 448 set_active(&self, is_active: bool)449 fn set_active(&self, is_active: bool) { 450 unsafe { 451 ffi::gtk_switch_set_active(self.as_ref().to_glib_none().0, is_active.into_glib()); 452 } 453 } 454 set_state(&self, state: bool)455 fn set_state(&self, state: bool) { 456 unsafe { 457 ffi::gtk_switch_set_state(self.as_ref().to_glib_none().0, state.into_glib()); 458 } 459 } 460 connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId461 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 462 unsafe extern "C" fn activate_trampoline<P: IsA<Switch>, F: Fn(&P) + 'static>( 463 this: *mut ffi::GtkSwitch, 464 f: glib::ffi::gpointer, 465 ) { 466 let f: &F = &*(f as *const F); 467 f(Switch::from_glib_borrow(this).unsafe_cast_ref()) 468 } 469 unsafe { 470 let f: Box_<F> = Box_::new(f); 471 connect_raw( 472 self.as_ptr() as *mut _, 473 b"activate\0".as_ptr() as *const _, 474 Some(transmute::<_, unsafe extern "C" fn()>( 475 activate_trampoline::<Self, F> as *const (), 476 )), 477 Box_::into_raw(f), 478 ) 479 } 480 } 481 emit_activate(&self)482 fn emit_activate(&self) { 483 let _ = unsafe { 484 glib::Object::from_glib_borrow(self.as_ptr() as *mut glib::gobject_ffi::GObject) 485 .emit_by_name("activate", &[]) 486 .unwrap() 487 }; 488 } 489 connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>( &self, f: F, ) -> SignalHandlerId490 fn connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>( 491 &self, 492 f: F, 493 ) -> SignalHandlerId { 494 unsafe extern "C" fn state_set_trampoline< 495 P: IsA<Switch>, 496 F: Fn(&P, bool) -> glib::signal::Inhibit + 'static, 497 >( 498 this: *mut ffi::GtkSwitch, 499 state: glib::ffi::gboolean, 500 f: glib::ffi::gpointer, 501 ) -> glib::ffi::gboolean { 502 let f: &F = &*(f as *const F); 503 f( 504 Switch::from_glib_borrow(this).unsafe_cast_ref(), 505 from_glib(state), 506 ) 507 .into_glib() 508 } 509 unsafe { 510 let f: Box_<F> = Box_::new(f); 511 connect_raw( 512 self.as_ptr() as *mut _, 513 b"state-set\0".as_ptr() as *const _, 514 Some(transmute::<_, unsafe extern "C" fn()>( 515 state_set_trampoline::<Self, F> as *const (), 516 )), 517 Box_::into_raw(f), 518 ) 519 } 520 } 521 connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId522 fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 523 unsafe extern "C" fn notify_active_trampoline<P: IsA<Switch>, F: Fn(&P) + 'static>( 524 this: *mut ffi::GtkSwitch, 525 _param_spec: glib::ffi::gpointer, 526 f: glib::ffi::gpointer, 527 ) { 528 let f: &F = &*(f as *const F); 529 f(Switch::from_glib_borrow(this).unsafe_cast_ref()) 530 } 531 unsafe { 532 let f: Box_<F> = Box_::new(f); 533 connect_raw( 534 self.as_ptr() as *mut _, 535 b"notify::active\0".as_ptr() as *const _, 536 Some(transmute::<_, unsafe extern "C" fn()>( 537 notify_active_trampoline::<Self, F> as *const (), 538 )), 539 Box_::into_raw(f), 540 ) 541 } 542 } 543 connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId544 fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 545 unsafe extern "C" fn notify_state_trampoline<P: IsA<Switch>, F: Fn(&P) + 'static>( 546 this: *mut ffi::GtkSwitch, 547 _param_spec: glib::ffi::gpointer, 548 f: glib::ffi::gpointer, 549 ) { 550 let f: &F = &*(f as *const F); 551 f(Switch::from_glib_borrow(this).unsafe_cast_ref()) 552 } 553 unsafe { 554 let f: Box_<F> = Box_::new(f); 555 connect_raw( 556 self.as_ptr() as *mut _, 557 b"notify::state\0".as_ptr() as *const _, 558 Some(transmute::<_, unsafe extern "C" fn()>( 559 notify_state_trampoline::<Self, F> as *const (), 560 )), 561 Box_::into_raw(f), 562 ) 563 } 564 } 565 } 566 567 impl fmt::Display for Switch { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result568 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 569 f.write_str("Switch") 570 } 571 } 572