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::Align; 6 use crate::Buildable; 7 use crate::Container; 8 use crate::Widget; 9 use glib::object::Cast; 10 use glib::object::IsA; 11 use glib::signal::connect_raw; 12 use glib::signal::SignalHandlerId; 13 use glib::translate::*; 14 use glib::StaticType; 15 use glib::ToValue; 16 use std::boxed::Box as Box_; 17 use std::fmt; 18 use std::mem::transmute; 19 20 glib::wrapper! { 21 #[doc(alias = "GtkSpinner")] 22 pub struct Spinner(Object<ffi::GtkSpinner, ffi::GtkSpinnerClass>) @extends Widget, @implements Buildable; 23 24 match fn { 25 type_ => || ffi::gtk_spinner_get_type(), 26 } 27 } 28 29 impl Spinner { 30 #[doc(alias = "gtk_spinner_new")] new() -> Spinner31 pub fn new() -> Spinner { 32 assert_initialized_main_thread!(); 33 unsafe { Widget::from_glib_none(ffi::gtk_spinner_new()).unsafe_cast() } 34 } 35 36 // rustdoc-stripper-ignore-next 37 /// Creates a new builder-pattern struct instance to construct [`Spinner`] objects. 38 /// 39 /// This method returns an instance of [`SpinnerBuilder`] which can be used to create [`Spinner`] objects. builder() -> SpinnerBuilder40 pub fn builder() -> SpinnerBuilder { 41 SpinnerBuilder::default() 42 } 43 } 44 45 impl Default for Spinner { default() -> Self46 fn default() -> Self { 47 Self::new() 48 } 49 } 50 51 #[derive(Clone, Default)] 52 // rustdoc-stripper-ignore-next 53 /// A [builder-pattern] type to construct [`Spinner`] objects. 54 /// 55 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html 56 pub struct SpinnerBuilder { 57 active: Option<bool>, 58 app_paintable: Option<bool>, 59 can_default: Option<bool>, 60 can_focus: Option<bool>, 61 events: Option<gdk::EventMask>, 62 expand: Option<bool>, 63 #[cfg(any(feature = "v3_20", feature = "dox"))] 64 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] 65 focus_on_click: Option<bool>, 66 halign: Option<Align>, 67 has_default: Option<bool>, 68 has_focus: Option<bool>, 69 has_tooltip: Option<bool>, 70 height_request: Option<i32>, 71 hexpand: Option<bool>, 72 hexpand_set: Option<bool>, 73 is_focus: Option<bool>, 74 margin: Option<i32>, 75 margin_bottom: Option<i32>, 76 margin_end: Option<i32>, 77 margin_start: Option<i32>, 78 margin_top: Option<i32>, 79 name: Option<String>, 80 no_show_all: Option<bool>, 81 opacity: Option<f64>, 82 parent: Option<Container>, 83 receives_default: Option<bool>, 84 sensitive: Option<bool>, 85 tooltip_markup: Option<String>, 86 tooltip_text: Option<String>, 87 valign: Option<Align>, 88 vexpand: Option<bool>, 89 vexpand_set: Option<bool>, 90 visible: Option<bool>, 91 width_request: Option<i32>, 92 } 93 94 impl SpinnerBuilder { 95 // rustdoc-stripper-ignore-next 96 /// Create a new [`SpinnerBuilder`]. new() -> Self97 pub fn new() -> Self { 98 Self::default() 99 } 100 101 // rustdoc-stripper-ignore-next 102 /// Build the [`Spinner`]. build(self) -> Spinner103 pub fn build(self) -> Spinner { 104 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 105 if let Some(ref active) = self.active { 106 properties.push(("active", active)); 107 } 108 if let Some(ref app_paintable) = self.app_paintable { 109 properties.push(("app-paintable", app_paintable)); 110 } 111 if let Some(ref can_default) = self.can_default { 112 properties.push(("can-default", can_default)); 113 } 114 if let Some(ref can_focus) = self.can_focus { 115 properties.push(("can-focus", can_focus)); 116 } 117 if let Some(ref events) = self.events { 118 properties.push(("events", events)); 119 } 120 if let Some(ref expand) = self.expand { 121 properties.push(("expand", expand)); 122 } 123 #[cfg(any(feature = "v3_20", feature = "dox"))] 124 if let Some(ref focus_on_click) = self.focus_on_click { 125 properties.push(("focus-on-click", focus_on_click)); 126 } 127 if let Some(ref halign) = self.halign { 128 properties.push(("halign", halign)); 129 } 130 if let Some(ref has_default) = self.has_default { 131 properties.push(("has-default", has_default)); 132 } 133 if let Some(ref has_focus) = self.has_focus { 134 properties.push(("has-focus", has_focus)); 135 } 136 if let Some(ref has_tooltip) = self.has_tooltip { 137 properties.push(("has-tooltip", has_tooltip)); 138 } 139 if let Some(ref height_request) = self.height_request { 140 properties.push(("height-request", height_request)); 141 } 142 if let Some(ref hexpand) = self.hexpand { 143 properties.push(("hexpand", hexpand)); 144 } 145 if let Some(ref hexpand_set) = self.hexpand_set { 146 properties.push(("hexpand-set", hexpand_set)); 147 } 148 if let Some(ref is_focus) = self.is_focus { 149 properties.push(("is-focus", is_focus)); 150 } 151 if let Some(ref margin) = self.margin { 152 properties.push(("margin", margin)); 153 } 154 if let Some(ref margin_bottom) = self.margin_bottom { 155 properties.push(("margin-bottom", margin_bottom)); 156 } 157 if let Some(ref margin_end) = self.margin_end { 158 properties.push(("margin-end", margin_end)); 159 } 160 if let Some(ref margin_start) = self.margin_start { 161 properties.push(("margin-start", margin_start)); 162 } 163 if let Some(ref margin_top) = self.margin_top { 164 properties.push(("margin-top", margin_top)); 165 } 166 if let Some(ref name) = self.name { 167 properties.push(("name", name)); 168 } 169 if let Some(ref no_show_all) = self.no_show_all { 170 properties.push(("no-show-all", no_show_all)); 171 } 172 if let Some(ref opacity) = self.opacity { 173 properties.push(("opacity", opacity)); 174 } 175 if let Some(ref parent) = self.parent { 176 properties.push(("parent", parent)); 177 } 178 if let Some(ref receives_default) = self.receives_default { 179 properties.push(("receives-default", receives_default)); 180 } 181 if let Some(ref sensitive) = self.sensitive { 182 properties.push(("sensitive", sensitive)); 183 } 184 if let Some(ref tooltip_markup) = self.tooltip_markup { 185 properties.push(("tooltip-markup", tooltip_markup)); 186 } 187 if let Some(ref tooltip_text) = self.tooltip_text { 188 properties.push(("tooltip-text", tooltip_text)); 189 } 190 if let Some(ref valign) = self.valign { 191 properties.push(("valign", valign)); 192 } 193 if let Some(ref vexpand) = self.vexpand { 194 properties.push(("vexpand", vexpand)); 195 } 196 if let Some(ref vexpand_set) = self.vexpand_set { 197 properties.push(("vexpand-set", vexpand_set)); 198 } 199 if let Some(ref visible) = self.visible { 200 properties.push(("visible", visible)); 201 } 202 if let Some(ref width_request) = self.width_request { 203 properties.push(("width-request", width_request)); 204 } 205 glib::Object::new::<Spinner>(&properties).expect("Failed to create an instance of Spinner") 206 } 207 active(mut self, active: bool) -> Self208 pub fn active(mut self, active: bool) -> Self { 209 self.active = Some(active); 210 self 211 } 212 app_paintable(mut self, app_paintable: bool) -> Self213 pub fn app_paintable(mut self, app_paintable: bool) -> Self { 214 self.app_paintable = Some(app_paintable); 215 self 216 } 217 can_default(mut self, can_default: bool) -> Self218 pub fn can_default(mut self, can_default: bool) -> Self { 219 self.can_default = Some(can_default); 220 self 221 } 222 can_focus(mut self, can_focus: bool) -> Self223 pub fn can_focus(mut self, can_focus: bool) -> Self { 224 self.can_focus = Some(can_focus); 225 self 226 } 227 events(mut self, events: gdk::EventMask) -> Self228 pub fn events(mut self, events: gdk::EventMask) -> Self { 229 self.events = Some(events); 230 self 231 } 232 expand(mut self, expand: bool) -> Self233 pub fn expand(mut self, expand: bool) -> Self { 234 self.expand = Some(expand); 235 self 236 } 237 238 #[cfg(any(feature = "v3_20", feature = "dox"))] 239 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] focus_on_click(mut self, focus_on_click: bool) -> Self240 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self { 241 self.focus_on_click = Some(focus_on_click); 242 self 243 } 244 halign(mut self, halign: Align) -> Self245 pub fn halign(mut self, halign: Align) -> Self { 246 self.halign = Some(halign); 247 self 248 } 249 has_default(mut self, has_default: bool) -> Self250 pub fn has_default(mut self, has_default: bool) -> Self { 251 self.has_default = Some(has_default); 252 self 253 } 254 has_focus(mut self, has_focus: bool) -> Self255 pub fn has_focus(mut self, has_focus: bool) -> Self { 256 self.has_focus = Some(has_focus); 257 self 258 } 259 has_tooltip(mut self, has_tooltip: bool) -> Self260 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self { 261 self.has_tooltip = Some(has_tooltip); 262 self 263 } 264 height_request(mut self, height_request: i32) -> Self265 pub fn height_request(mut self, height_request: i32) -> Self { 266 self.height_request = Some(height_request); 267 self 268 } 269 hexpand(mut self, hexpand: bool) -> Self270 pub fn hexpand(mut self, hexpand: bool) -> Self { 271 self.hexpand = Some(hexpand); 272 self 273 } 274 hexpand_set(mut self, hexpand_set: bool) -> Self275 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self { 276 self.hexpand_set = Some(hexpand_set); 277 self 278 } 279 is_focus(mut self, is_focus: bool) -> Self280 pub fn is_focus(mut self, is_focus: bool) -> Self { 281 self.is_focus = Some(is_focus); 282 self 283 } 284 margin(mut self, margin: i32) -> Self285 pub fn margin(mut self, margin: i32) -> Self { 286 self.margin = Some(margin); 287 self 288 } 289 margin_bottom(mut self, margin_bottom: i32) -> Self290 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self { 291 self.margin_bottom = Some(margin_bottom); 292 self 293 } 294 margin_end(mut self, margin_end: i32) -> Self295 pub fn margin_end(mut self, margin_end: i32) -> Self { 296 self.margin_end = Some(margin_end); 297 self 298 } 299 margin_start(mut self, margin_start: i32) -> Self300 pub fn margin_start(mut self, margin_start: i32) -> Self { 301 self.margin_start = Some(margin_start); 302 self 303 } 304 margin_top(mut self, margin_top: i32) -> Self305 pub fn margin_top(mut self, margin_top: i32) -> Self { 306 self.margin_top = Some(margin_top); 307 self 308 } 309 name(mut self, name: &str) -> Self310 pub fn name(mut self, name: &str) -> Self { 311 self.name = Some(name.to_string()); 312 self 313 } 314 no_show_all(mut self, no_show_all: bool) -> Self315 pub fn no_show_all(mut self, no_show_all: bool) -> Self { 316 self.no_show_all = Some(no_show_all); 317 self 318 } 319 opacity(mut self, opacity: f64) -> Self320 pub fn opacity(mut self, opacity: f64) -> Self { 321 self.opacity = Some(opacity); 322 self 323 } 324 parent<P: IsA<Container>>(mut self, parent: &P) -> Self325 pub fn parent<P: IsA<Container>>(mut self, parent: &P) -> Self { 326 self.parent = Some(parent.clone().upcast()); 327 self 328 } 329 receives_default(mut self, receives_default: bool) -> Self330 pub fn receives_default(mut self, receives_default: bool) -> Self { 331 self.receives_default = Some(receives_default); 332 self 333 } 334 sensitive(mut self, sensitive: bool) -> Self335 pub fn sensitive(mut self, sensitive: bool) -> Self { 336 self.sensitive = Some(sensitive); 337 self 338 } 339 tooltip_markup(mut self, tooltip_markup: &str) -> Self340 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self { 341 self.tooltip_markup = Some(tooltip_markup.to_string()); 342 self 343 } 344 tooltip_text(mut self, tooltip_text: &str) -> Self345 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self { 346 self.tooltip_text = Some(tooltip_text.to_string()); 347 self 348 } 349 valign(mut self, valign: Align) -> Self350 pub fn valign(mut self, valign: Align) -> Self { 351 self.valign = Some(valign); 352 self 353 } 354 vexpand(mut self, vexpand: bool) -> Self355 pub fn vexpand(mut self, vexpand: bool) -> Self { 356 self.vexpand = Some(vexpand); 357 self 358 } 359 vexpand_set(mut self, vexpand_set: bool) -> Self360 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self { 361 self.vexpand_set = Some(vexpand_set); 362 self 363 } 364 visible(mut self, visible: bool) -> Self365 pub fn visible(mut self, visible: bool) -> Self { 366 self.visible = Some(visible); 367 self 368 } 369 width_request(mut self, width_request: i32) -> Self370 pub fn width_request(mut self, width_request: i32) -> Self { 371 self.width_request = Some(width_request); 372 self 373 } 374 } 375 376 pub const NONE_SPINNER: Option<&Spinner> = None; 377 378 pub trait SpinnerExt: 'static { 379 #[doc(alias = "gtk_spinner_start")] start(&self)380 fn start(&self); 381 382 #[doc(alias = "gtk_spinner_stop")] stop(&self)383 fn stop(&self); 384 is_active(&self) -> bool385 fn is_active(&self) -> bool; 386 set_active(&self, active: bool)387 fn set_active(&self, active: bool); 388 389 #[doc(alias = "active")] connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId390 fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 391 } 392 393 impl<O: IsA<Spinner>> SpinnerExt for O { start(&self)394 fn start(&self) { 395 unsafe { 396 ffi::gtk_spinner_start(self.as_ref().to_glib_none().0); 397 } 398 } 399 stop(&self)400 fn stop(&self) { 401 unsafe { 402 ffi::gtk_spinner_stop(self.as_ref().to_glib_none().0); 403 } 404 } 405 is_active(&self) -> bool406 fn is_active(&self) -> bool { 407 unsafe { 408 let mut value = glib::Value::from_type(<bool as StaticType>::static_type()); 409 glib::gobject_ffi::g_object_get_property( 410 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 411 b"active\0".as_ptr() as *const _, 412 value.to_glib_none_mut().0, 413 ); 414 value 415 .get() 416 .expect("Return Value for property `active` getter") 417 } 418 } 419 set_active(&self, active: bool)420 fn set_active(&self, active: bool) { 421 unsafe { 422 glib::gobject_ffi::g_object_set_property( 423 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject, 424 b"active\0".as_ptr() as *const _, 425 active.to_value().to_glib_none().0, 426 ); 427 } 428 } 429 connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId430 fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 431 unsafe extern "C" fn notify_active_trampoline<P: IsA<Spinner>, F: Fn(&P) + 'static>( 432 this: *mut ffi::GtkSpinner, 433 _param_spec: glib::ffi::gpointer, 434 f: glib::ffi::gpointer, 435 ) { 436 let f: &F = &*(f as *const F); 437 f(Spinner::from_glib_borrow(this).unsafe_cast_ref()) 438 } 439 unsafe { 440 let f: Box_<F> = Box_::new(f); 441 connect_raw( 442 self.as_ptr() as *mut _, 443 b"notify::active\0".as_ptr() as *const _, 444 Some(transmute::<_, unsafe extern "C" fn()>( 445 notify_active_trampoline::<Self, F> as *const (), 446 )), 447 Box_::into_raw(f), 448 ) 449 } 450 } 451 } 452 453 impl fmt::Display for Spinner { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result454 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 455 f.write_str("Spinner") 456 } 457 } 458