1use crate::{Actionable, Align, Bin, Buildable, Container, ResizeMode, ToolItem, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14 #[doc(alias = "GtkToolButton")]
15 pub struct ToolButton(Object<ffi::GtkToolButton, ffi::GtkToolButtonClass>) @extends ToolItem, Bin, Container, Widget, @implements Buildable, Actionable;
16
17 match fn {
18 type_ => || ffi::gtk_tool_button_get_type(),
19 }
20}
21
22impl ToolButton {
23 pub const NONE: Option<&'static ToolButton> = None;
24
25 #[doc(alias = "gtk_tool_button_new")]
26 pub fn new(icon_widget: Option<&impl IsA<Widget>>, label: Option<&str>) -> ToolButton {
27 assert_initialized_main_thread!();
28 unsafe {
29 ToolItem::from_glib_none(ffi::gtk_tool_button_new(
30 icon_widget.map(|p| p.as_ref()).to_glib_none().0,
31 label.to_glib_none().0,
32 ))
33 .unsafe_cast()
34 }
35 }
36
37 pub fn builder() -> ToolButtonBuilder {
42 ToolButtonBuilder::new()
43 }
44}
45
46impl Default for ToolButton {
47 fn default() -> Self {
48 glib::object::Object::new::<Self>()
49 }
50}
51
52#[must_use = "The builder must be built to be used"]
57pub struct ToolButtonBuilder {
58 builder: glib::object::ObjectBuilder<'static, ToolButton>,
59}
60
61impl ToolButtonBuilder {
62 fn new() -> Self {
63 Self {
64 builder: glib::object::Object::builder(),
65 }
66 }
67
68 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
69 Self {
70 builder: self.builder.property("icon-name", icon_name.into()),
71 }
72 }
73
74 pub fn icon_widget(self, icon_widget: &impl IsA<Widget>) -> Self {
75 Self {
76 builder: self
77 .builder
78 .property("icon-widget", icon_widget.clone().upcast()),
79 }
80 }
81
82 pub fn label(self, label: impl Into<glib::GString>) -> Self {
83 Self {
84 builder: self.builder.property("label", label.into()),
85 }
86 }
87
88 pub fn label_widget(self, label_widget: &impl IsA<Widget>) -> Self {
89 Self {
90 builder: self
91 .builder
92 .property("label-widget", label_widget.clone().upcast()),
93 }
94 }
95
96 pub fn use_underline(self, use_underline: bool) -> Self {
97 Self {
98 builder: self.builder.property("use-underline", use_underline),
99 }
100 }
101
102 pub fn is_important(self, is_important: bool) -> Self {
103 Self {
104 builder: self.builder.property("is-important", is_important),
105 }
106 }
107
108 pub fn visible_horizontal(self, visible_horizontal: bool) -> Self {
109 Self {
110 builder: self
111 .builder
112 .property("visible-horizontal", visible_horizontal),
113 }
114 }
115
116 pub fn visible_vertical(self, visible_vertical: bool) -> Self {
117 Self {
118 builder: self.builder.property("visible-vertical", visible_vertical),
119 }
120 }
121
122 pub fn border_width(self, border_width: u32) -> Self {
123 Self {
124 builder: self.builder.property("border-width", border_width),
125 }
126 }
127
128 pub fn child(self, child: &impl IsA<Widget>) -> Self {
129 Self {
130 builder: self.builder.property("child", child.clone().upcast()),
131 }
132 }
133
134 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
135 Self {
136 builder: self.builder.property("resize-mode", resize_mode),
137 }
138 }
139
140 pub fn app_paintable(self, app_paintable: bool) -> Self {
141 Self {
142 builder: self.builder.property("app-paintable", app_paintable),
143 }
144 }
145
146 pub fn can_default(self, can_default: bool) -> Self {
147 Self {
148 builder: self.builder.property("can-default", can_default),
149 }
150 }
151
152 pub fn can_focus(self, can_focus: bool) -> Self {
153 Self {
154 builder: self.builder.property("can-focus", can_focus),
155 }
156 }
157
158 pub fn events(self, events: gdk::EventMask) -> Self {
159 Self {
160 builder: self.builder.property("events", events),
161 }
162 }
163
164 pub fn expand(self, expand: bool) -> Self {
165 Self {
166 builder: self.builder.property("expand", expand),
167 }
168 }
169
170 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
171 Self {
172 builder: self.builder.property("focus-on-click", focus_on_click),
173 }
174 }
175
176 pub fn halign(self, halign: Align) -> Self {
177 Self {
178 builder: self.builder.property("halign", halign),
179 }
180 }
181
182 pub fn has_default(self, has_default: bool) -> Self {
183 Self {
184 builder: self.builder.property("has-default", has_default),
185 }
186 }
187
188 pub fn has_focus(self, has_focus: bool) -> Self {
189 Self {
190 builder: self.builder.property("has-focus", has_focus),
191 }
192 }
193
194 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
195 Self {
196 builder: self.builder.property("has-tooltip", has_tooltip),
197 }
198 }
199
200 pub fn height_request(self, height_request: i32) -> Self {
201 Self {
202 builder: self.builder.property("height-request", height_request),
203 }
204 }
205
206 pub fn hexpand(self, hexpand: bool) -> Self {
207 Self {
208 builder: self.builder.property("hexpand", hexpand),
209 }
210 }
211
212 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
213 Self {
214 builder: self.builder.property("hexpand-set", hexpand_set),
215 }
216 }
217
218 pub fn is_focus(self, is_focus: bool) -> Self {
219 Self {
220 builder: self.builder.property("is-focus", is_focus),
221 }
222 }
223
224 pub fn margin(self, margin: i32) -> Self {
225 Self {
226 builder: self.builder.property("margin", margin),
227 }
228 }
229
230 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
231 Self {
232 builder: self.builder.property("margin-bottom", margin_bottom),
233 }
234 }
235
236 pub fn margin_end(self, margin_end: i32) -> Self {
237 Self {
238 builder: self.builder.property("margin-end", margin_end),
239 }
240 }
241
242 pub fn margin_start(self, margin_start: i32) -> Self {
243 Self {
244 builder: self.builder.property("margin-start", margin_start),
245 }
246 }
247
248 pub fn margin_top(self, margin_top: i32) -> Self {
249 Self {
250 builder: self.builder.property("margin-top", margin_top),
251 }
252 }
253
254 pub fn name(self, name: impl Into<glib::GString>) -> Self {
255 Self {
256 builder: self.builder.property("name", name.into()),
257 }
258 }
259
260 pub fn no_show_all(self, no_show_all: bool) -> Self {
261 Self {
262 builder: self.builder.property("no-show-all", no_show_all),
263 }
264 }
265
266 pub fn opacity(self, opacity: f64) -> Self {
267 Self {
268 builder: self.builder.property("opacity", opacity),
269 }
270 }
271
272 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
273 Self {
274 builder: self.builder.property("parent", parent.clone().upcast()),
275 }
276 }
277
278 pub fn receives_default(self, receives_default: bool) -> Self {
279 Self {
280 builder: self.builder.property("receives-default", receives_default),
281 }
282 }
283
284 pub fn sensitive(self, sensitive: bool) -> Self {
285 Self {
286 builder: self.builder.property("sensitive", sensitive),
287 }
288 }
289
290 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
291 Self {
292 builder: self
293 .builder
294 .property("tooltip-markup", tooltip_markup.into()),
295 }
296 }
297
298 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
299 Self {
300 builder: self.builder.property("tooltip-text", tooltip_text.into()),
301 }
302 }
303
304 pub fn valign(self, valign: Align) -> Self {
305 Self {
306 builder: self.builder.property("valign", valign),
307 }
308 }
309
310 pub fn vexpand(self, vexpand: bool) -> Self {
311 Self {
312 builder: self.builder.property("vexpand", vexpand),
313 }
314 }
315
316 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
317 Self {
318 builder: self.builder.property("vexpand-set", vexpand_set),
319 }
320 }
321
322 pub fn visible(self, visible: bool) -> Self {
323 Self {
324 builder: self.builder.property("visible", visible),
325 }
326 }
327
328 pub fn width_request(self, width_request: i32) -> Self {
329 Self {
330 builder: self.builder.property("width-request", width_request),
331 }
332 }
333
334 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
335 Self {
336 builder: self.builder.property("action-name", action_name.into()),
337 }
338 }
339
340 pub fn action_target(self, action_target: &glib::Variant) -> Self {
341 Self {
342 builder: self
343 .builder
344 .property("action-target", action_target.clone()),
345 }
346 }
347
348 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
351 pub fn build(self) -> ToolButton {
352 self.builder.build()
353 }
354}
355
356mod sealed {
357 pub trait Sealed {}
358 impl<T: super::IsA<super::ToolButton>> Sealed for T {}
359}
360
361pub trait ToolButtonExt: IsA<ToolButton> + sealed::Sealed + 'static {
362 #[doc(alias = "gtk_tool_button_get_icon_name")]
363 #[doc(alias = "get_icon_name")]
364 fn icon_name(&self) -> Option<glib::GString> {
365 unsafe {
366 from_glib_none(ffi::gtk_tool_button_get_icon_name(
367 self.as_ref().to_glib_none().0,
368 ))
369 }
370 }
371
372 #[doc(alias = "gtk_tool_button_get_icon_widget")]
373 #[doc(alias = "get_icon_widget")]
374 fn icon_widget(&self) -> Option<Widget> {
375 unsafe {
376 from_glib_none(ffi::gtk_tool_button_get_icon_widget(
377 self.as_ref().to_glib_none().0,
378 ))
379 }
380 }
381
382 #[doc(alias = "gtk_tool_button_get_label")]
383 #[doc(alias = "get_label")]
384 fn label(&self) -> Option<glib::GString> {
385 unsafe {
386 from_glib_none(ffi::gtk_tool_button_get_label(
387 self.as_ref().to_glib_none().0,
388 ))
389 }
390 }
391
392 #[doc(alias = "gtk_tool_button_get_label_widget")]
393 #[doc(alias = "get_label_widget")]
394 fn label_widget(&self) -> Option<Widget> {
395 unsafe {
396 from_glib_none(ffi::gtk_tool_button_get_label_widget(
397 self.as_ref().to_glib_none().0,
398 ))
399 }
400 }
401
402 #[doc(alias = "gtk_tool_button_get_use_underline")]
403 #[doc(alias = "get_use_underline")]
404 fn uses_underline(&self) -> bool {
405 unsafe {
406 from_glib(ffi::gtk_tool_button_get_use_underline(
407 self.as_ref().to_glib_none().0,
408 ))
409 }
410 }
411
412 #[doc(alias = "gtk_tool_button_set_icon_name")]
413 fn set_icon_name(&self, icon_name: Option<&str>) {
414 unsafe {
415 ffi::gtk_tool_button_set_icon_name(
416 self.as_ref().to_glib_none().0,
417 icon_name.to_glib_none().0,
418 );
419 }
420 }
421
422 #[doc(alias = "gtk_tool_button_set_icon_widget")]
423 fn set_icon_widget(&self, icon_widget: Option<&impl IsA<Widget>>) {
424 unsafe {
425 ffi::gtk_tool_button_set_icon_widget(
426 self.as_ref().to_glib_none().0,
427 icon_widget.map(|p| p.as_ref()).to_glib_none().0,
428 );
429 }
430 }
431
432 #[doc(alias = "gtk_tool_button_set_label")]
433 fn set_label(&self, label: Option<&str>) {
434 unsafe {
435 ffi::gtk_tool_button_set_label(self.as_ref().to_glib_none().0, label.to_glib_none().0);
436 }
437 }
438
439 #[doc(alias = "gtk_tool_button_set_label_widget")]
440 fn set_label_widget(&self, label_widget: Option<&impl IsA<Widget>>) {
441 unsafe {
442 ffi::gtk_tool_button_set_label_widget(
443 self.as_ref().to_glib_none().0,
444 label_widget.map(|p| p.as_ref()).to_glib_none().0,
445 );
446 }
447 }
448
449 #[doc(alias = "gtk_tool_button_set_use_underline")]
450 fn set_use_underline(&self, use_underline: bool) {
451 unsafe {
452 ffi::gtk_tool_button_set_use_underline(
453 self.as_ref().to_glib_none().0,
454 use_underline.into_glib(),
455 );
456 }
457 }
458
459 #[doc(alias = "clicked")]
460 fn connect_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
461 unsafe extern "C" fn clicked_trampoline<P: IsA<ToolButton>, F: Fn(&P) + 'static>(
462 this: *mut ffi::GtkToolButton,
463 f: glib::ffi::gpointer,
464 ) {
465 let f: &F = &*(f as *const F);
466 f(ToolButton::from_glib_borrow(this).unsafe_cast_ref())
467 }
468 unsafe {
469 let f: Box_<F> = Box_::new(f);
470 connect_raw(
471 self.as_ptr() as *mut _,
472 b"clicked\0".as_ptr() as *const _,
473 Some(transmute::<_, unsafe extern "C" fn()>(
474 clicked_trampoline::<Self, F> as *const (),
475 )),
476 Box_::into_raw(f),
477 )
478 }
479 }
480
481 fn emit_clicked(&self) {
482 self.emit_by_name::<()>("clicked", &[]);
483 }
484
485 #[doc(alias = "icon-name")]
486 fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
487 unsafe extern "C" fn notify_icon_name_trampoline<
488 P: IsA<ToolButton>,
489 F: Fn(&P) + 'static,
490 >(
491 this: *mut ffi::GtkToolButton,
492 _param_spec: glib::ffi::gpointer,
493 f: glib::ffi::gpointer,
494 ) {
495 let f: &F = &*(f as *const F);
496 f(ToolButton::from_glib_borrow(this).unsafe_cast_ref())
497 }
498 unsafe {
499 let f: Box_<F> = Box_::new(f);
500 connect_raw(
501 self.as_ptr() as *mut _,
502 b"notify::icon-name\0".as_ptr() as *const _,
503 Some(transmute::<_, unsafe extern "C" fn()>(
504 notify_icon_name_trampoline::<Self, F> as *const (),
505 )),
506 Box_::into_raw(f),
507 )
508 }
509 }
510
511 #[doc(alias = "icon-widget")]
512 fn connect_icon_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
513 unsafe extern "C" fn notify_icon_widget_trampoline<
514 P: IsA<ToolButton>,
515 F: Fn(&P) + 'static,
516 >(
517 this: *mut ffi::GtkToolButton,
518 _param_spec: glib::ffi::gpointer,
519 f: glib::ffi::gpointer,
520 ) {
521 let f: &F = &*(f as *const F);
522 f(ToolButton::from_glib_borrow(this).unsafe_cast_ref())
523 }
524 unsafe {
525 let f: Box_<F> = Box_::new(f);
526 connect_raw(
527 self.as_ptr() as *mut _,
528 b"notify::icon-widget\0".as_ptr() as *const _,
529 Some(transmute::<_, unsafe extern "C" fn()>(
530 notify_icon_widget_trampoline::<Self, F> as *const (),
531 )),
532 Box_::into_raw(f),
533 )
534 }
535 }
536
537 #[doc(alias = "label")]
538 fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
539 unsafe extern "C" fn notify_label_trampoline<P: IsA<ToolButton>, F: Fn(&P) + 'static>(
540 this: *mut ffi::GtkToolButton,
541 _param_spec: glib::ffi::gpointer,
542 f: glib::ffi::gpointer,
543 ) {
544 let f: &F = &*(f as *const F);
545 f(ToolButton::from_glib_borrow(this).unsafe_cast_ref())
546 }
547 unsafe {
548 let f: Box_<F> = Box_::new(f);
549 connect_raw(
550 self.as_ptr() as *mut _,
551 b"notify::label\0".as_ptr() as *const _,
552 Some(transmute::<_, unsafe extern "C" fn()>(
553 notify_label_trampoline::<Self, F> as *const (),
554 )),
555 Box_::into_raw(f),
556 )
557 }
558 }
559
560 #[doc(alias = "label-widget")]
561 fn connect_label_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
562 unsafe extern "C" fn notify_label_widget_trampoline<
563 P: IsA<ToolButton>,
564 F: Fn(&P) + 'static,
565 >(
566 this: *mut ffi::GtkToolButton,
567 _param_spec: glib::ffi::gpointer,
568 f: glib::ffi::gpointer,
569 ) {
570 let f: &F = &*(f as *const F);
571 f(ToolButton::from_glib_borrow(this).unsafe_cast_ref())
572 }
573 unsafe {
574 let f: Box_<F> = Box_::new(f);
575 connect_raw(
576 self.as_ptr() as *mut _,
577 b"notify::label-widget\0".as_ptr() as *const _,
578 Some(transmute::<_, unsafe extern "C" fn()>(
579 notify_label_widget_trampoline::<Self, F> as *const (),
580 )),
581 Box_::into_raw(f),
582 )
583 }
584 }
585
586 #[doc(alias = "use-underline")]
587 fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
588 unsafe extern "C" fn notify_use_underline_trampoline<
589 P: IsA<ToolButton>,
590 F: Fn(&P) + 'static,
591 >(
592 this: *mut ffi::GtkToolButton,
593 _param_spec: glib::ffi::gpointer,
594 f: glib::ffi::gpointer,
595 ) {
596 let f: &F = &*(f as *const F);
597 f(ToolButton::from_glib_borrow(this).unsafe_cast_ref())
598 }
599 unsafe {
600 let f: Box_<F> = Box_::new(f);
601 connect_raw(
602 self.as_ptr() as *mut _,
603 b"notify::use-underline\0".as_ptr() as *const _,
604 Some(transmute::<_, unsafe extern "C" fn()>(
605 notify_use_underline_trampoline::<Self, F> as *const (),
606 )),
607 Box_::into_raw(f),
608 )
609 }
610 }
611}
612
613impl<O: IsA<ToolButton>> ToolButtonExt for O {}
614
615impl fmt::Display for ToolButton {
616 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
617 f.write_str("ToolButton")
618 }
619}