1#![allow(deprecated)]
5
6use crate::{
7 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, FontChooser,
8 FontChooserLevel, LayoutManager, Overflow, Widget,
9};
10use glib::{
11 object::ObjectType as _,
12 prelude::*,
13 signal::{connect_raw, SignalHandlerId},
14 translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19 #[doc(alias = "GtkFontButton")]
20 pub struct FontButton(Object<ffi::GtkFontButton>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, FontChooser;
21
22 match fn {
23 type_ => || ffi::gtk_font_button_get_type(),
24 }
25}
26
27impl FontButton {
28 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
29 #[allow(deprecated)]
30 #[doc(alias = "gtk_font_button_new")]
31 pub fn new() -> FontButton {
32 assert_initialized_main_thread!();
33 unsafe { Widget::from_glib_none(ffi::gtk_font_button_new()).unsafe_cast() }
34 }
35
36 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
37 #[allow(deprecated)]
38 #[doc(alias = "gtk_font_button_new_with_font")]
39 #[doc(alias = "new_with_font")]
40 pub fn with_font(fontname: &str) -> FontButton {
41 assert_initialized_main_thread!();
42 unsafe {
43 Widget::from_glib_none(ffi::gtk_font_button_new_with_font(
44 fontname.to_glib_none().0,
45 ))
46 .unsafe_cast()
47 }
48 }
49
50 pub fn builder() -> FontButtonBuilder {
55 FontButtonBuilder::new()
56 }
57
58 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
59 #[allow(deprecated)]
60 #[doc(alias = "gtk_font_button_get_modal")]
61 #[doc(alias = "get_modal")]
62 #[doc(alias = "modal")]
63 pub fn is_modal(&self) -> bool {
64 unsafe { from_glib(ffi::gtk_font_button_get_modal(self.to_glib_none().0)) }
65 }
66
67 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
68 #[allow(deprecated)]
69 #[doc(alias = "gtk_font_button_get_title")]
70 #[doc(alias = "get_title")]
71 pub fn title(&self) -> glib::GString {
72 unsafe { from_glib_none(ffi::gtk_font_button_get_title(self.to_glib_none().0)) }
73 }
74
75 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
76 #[allow(deprecated)]
77 #[doc(alias = "gtk_font_button_get_use_font")]
78 #[doc(alias = "get_use_font")]
79 #[doc(alias = "use-font")]
80 pub fn uses_font(&self) -> bool {
81 unsafe { from_glib(ffi::gtk_font_button_get_use_font(self.to_glib_none().0)) }
82 }
83
84 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
85 #[allow(deprecated)]
86 #[doc(alias = "gtk_font_button_get_use_size")]
87 #[doc(alias = "get_use_size")]
88 #[doc(alias = "use-size")]
89 pub fn uses_size(&self) -> bool {
90 unsafe { from_glib(ffi::gtk_font_button_get_use_size(self.to_glib_none().0)) }
91 }
92
93 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
94 #[allow(deprecated)]
95 #[doc(alias = "gtk_font_button_set_modal")]
96 #[doc(alias = "modal")]
97 pub fn set_modal(&self, modal: bool) {
98 unsafe {
99 ffi::gtk_font_button_set_modal(self.to_glib_none().0, modal.into_glib());
100 }
101 }
102
103 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
104 #[allow(deprecated)]
105 #[doc(alias = "gtk_font_button_set_title")]
106 #[doc(alias = "title")]
107 pub fn set_title(&self, title: &str) {
108 unsafe {
109 ffi::gtk_font_button_set_title(self.to_glib_none().0, title.to_glib_none().0);
110 }
111 }
112
113 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
114 #[allow(deprecated)]
115 #[doc(alias = "gtk_font_button_set_use_font")]
116 #[doc(alias = "use-font")]
117 pub fn set_use_font(&self, use_font: bool) {
118 unsafe {
119 ffi::gtk_font_button_set_use_font(self.to_glib_none().0, use_font.into_glib());
120 }
121 }
122
123 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
124 #[allow(deprecated)]
125 #[doc(alias = "gtk_font_button_set_use_size")]
126 #[doc(alias = "use-size")]
127 pub fn set_use_size(&self, use_size: bool) {
128 unsafe {
129 ffi::gtk_font_button_set_use_size(self.to_glib_none().0, use_size.into_glib());
130 }
131 }
132
133 #[cfg(feature = "v4_4")]
134 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
135 #[doc(alias = "activate")]
136 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
137 unsafe extern "C" fn activate_trampoline<F: Fn(&FontButton) + 'static>(
138 this: *mut ffi::GtkFontButton,
139 f: glib::ffi::gpointer,
140 ) {
141 let f: &F = &*(f as *const F);
142 f(&from_glib_borrow(this))
143 }
144 unsafe {
145 let f: Box_<F> = Box_::new(f);
146 connect_raw(
147 self.as_ptr() as *mut _,
148 c"activate".as_ptr() as *const _,
149 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
150 activate_trampoline::<F> as *const (),
151 )),
152 Box_::into_raw(f),
153 )
154 }
155 }
156
157 #[cfg(feature = "v4_4")]
158 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
159 pub fn emit_activate(&self) {
160 self.emit_by_name::<()>("activate", &[]);
161 }
162
163 #[doc(alias = "font-set")]
164 pub fn connect_font_set<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
165 unsafe extern "C" fn font_set_trampoline<F: Fn(&FontButton) + 'static>(
166 this: *mut ffi::GtkFontButton,
167 f: glib::ffi::gpointer,
168 ) {
169 let f: &F = &*(f as *const F);
170 f(&from_glib_borrow(this))
171 }
172 unsafe {
173 let f: Box_<F> = Box_::new(f);
174 connect_raw(
175 self.as_ptr() as *mut _,
176 c"font-set".as_ptr() as *const _,
177 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
178 font_set_trampoline::<F> as *const (),
179 )),
180 Box_::into_raw(f),
181 )
182 }
183 }
184
185 #[doc(alias = "modal")]
186 pub fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
187 unsafe extern "C" fn notify_modal_trampoline<F: Fn(&FontButton) + 'static>(
188 this: *mut ffi::GtkFontButton,
189 _param_spec: glib::ffi::gpointer,
190 f: glib::ffi::gpointer,
191 ) {
192 let f: &F = &*(f as *const F);
193 f(&from_glib_borrow(this))
194 }
195 unsafe {
196 let f: Box_<F> = Box_::new(f);
197 connect_raw(
198 self.as_ptr() as *mut _,
199 c"notify::modal".as_ptr() as *const _,
200 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
201 notify_modal_trampoline::<F> as *const (),
202 )),
203 Box_::into_raw(f),
204 )
205 }
206 }
207
208 #[doc(alias = "title")]
209 pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
210 unsafe extern "C" fn notify_title_trampoline<F: Fn(&FontButton) + 'static>(
211 this: *mut ffi::GtkFontButton,
212 _param_spec: glib::ffi::gpointer,
213 f: glib::ffi::gpointer,
214 ) {
215 let f: &F = &*(f as *const F);
216 f(&from_glib_borrow(this))
217 }
218 unsafe {
219 let f: Box_<F> = Box_::new(f);
220 connect_raw(
221 self.as_ptr() as *mut _,
222 c"notify::title".as_ptr() as *const _,
223 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
224 notify_title_trampoline::<F> as *const (),
225 )),
226 Box_::into_raw(f),
227 )
228 }
229 }
230
231 #[doc(alias = "use-font")]
232 pub fn connect_use_font_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
233 unsafe extern "C" fn notify_use_font_trampoline<F: Fn(&FontButton) + 'static>(
234 this: *mut ffi::GtkFontButton,
235 _param_spec: glib::ffi::gpointer,
236 f: glib::ffi::gpointer,
237 ) {
238 let f: &F = &*(f as *const F);
239 f(&from_glib_borrow(this))
240 }
241 unsafe {
242 let f: Box_<F> = Box_::new(f);
243 connect_raw(
244 self.as_ptr() as *mut _,
245 c"notify::use-font".as_ptr() as *const _,
246 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
247 notify_use_font_trampoline::<F> as *const (),
248 )),
249 Box_::into_raw(f),
250 )
251 }
252 }
253
254 #[doc(alias = "use-size")]
255 pub fn connect_use_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
256 unsafe extern "C" fn notify_use_size_trampoline<F: Fn(&FontButton) + 'static>(
257 this: *mut ffi::GtkFontButton,
258 _param_spec: glib::ffi::gpointer,
259 f: glib::ffi::gpointer,
260 ) {
261 let f: &F = &*(f as *const F);
262 f(&from_glib_borrow(this))
263 }
264 unsafe {
265 let f: Box_<F> = Box_::new(f);
266 connect_raw(
267 self.as_ptr() as *mut _,
268 c"notify::use-size".as_ptr() as *const _,
269 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270 notify_use_size_trampoline::<F> as *const (),
271 )),
272 Box_::into_raw(f),
273 )
274 }
275 }
276}
277
278impl Default for FontButton {
279 fn default() -> Self {
280 Self::new()
281 }
282}
283
284#[must_use = "The builder must be built to be used"]
289pub struct FontButtonBuilder {
290 builder: glib::object::ObjectBuilder<'static, FontButton>,
291}
292
293impl FontButtonBuilder {
294 fn new() -> Self {
295 Self {
296 builder: glib::object::Object::builder(),
297 }
298 }
299
300 pub fn modal(self, modal: bool) -> Self {
301 Self {
302 builder: self.builder.property("modal", modal),
303 }
304 }
305
306 pub fn title(self, title: impl Into<glib::GString>) -> Self {
307 Self {
308 builder: self.builder.property("title", title.into()),
309 }
310 }
311
312 pub fn use_font(self, use_font: bool) -> Self {
313 Self {
314 builder: self.builder.property("use-font", use_font),
315 }
316 }
317
318 pub fn use_size(self, use_size: bool) -> Self {
319 Self {
320 builder: self.builder.property("use-size", use_size),
321 }
322 }
323
324 pub fn can_focus(self, can_focus: bool) -> Self {
325 Self {
326 builder: self.builder.property("can-focus", can_focus),
327 }
328 }
329
330 pub fn can_target(self, can_target: bool) -> Self {
331 Self {
332 builder: self.builder.property("can-target", can_target),
333 }
334 }
335
336 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
337 Self {
338 builder: self.builder.property("css-classes", css_classes.into()),
339 }
340 }
341
342 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
343 Self {
344 builder: self.builder.property("css-name", css_name.into()),
345 }
346 }
347
348 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
349 Self {
350 builder: self.builder.property("cursor", cursor.clone()),
351 }
352 }
353
354 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
355 Self {
356 builder: self.builder.property("focus-on-click", focus_on_click),
357 }
358 }
359
360 pub fn focusable(self, focusable: bool) -> Self {
361 Self {
362 builder: self.builder.property("focusable", focusable),
363 }
364 }
365
366 pub fn halign(self, halign: Align) -> Self {
367 Self {
368 builder: self.builder.property("halign", halign),
369 }
370 }
371
372 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
373 Self {
374 builder: self.builder.property("has-tooltip", has_tooltip),
375 }
376 }
377
378 pub fn height_request(self, height_request: i32) -> Self {
379 Self {
380 builder: self.builder.property("height-request", height_request),
381 }
382 }
383
384 pub fn hexpand(self, hexpand: bool) -> Self {
385 Self {
386 builder: self.builder.property("hexpand", hexpand),
387 }
388 }
389
390 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
391 Self {
392 builder: self.builder.property("hexpand-set", hexpand_set),
393 }
394 }
395
396 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
397 Self {
398 builder: self
399 .builder
400 .property("layout-manager", layout_manager.clone().upcast()),
401 }
402 }
403
404 #[cfg(feature = "v4_18")]
405 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
406 pub fn limit_events(self, limit_events: bool) -> Self {
407 Self {
408 builder: self.builder.property("limit-events", limit_events),
409 }
410 }
411
412 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
413 Self {
414 builder: self.builder.property("margin-bottom", margin_bottom),
415 }
416 }
417
418 pub fn margin_end(self, margin_end: i32) -> Self {
419 Self {
420 builder: self.builder.property("margin-end", margin_end),
421 }
422 }
423
424 pub fn margin_start(self, margin_start: i32) -> Self {
425 Self {
426 builder: self.builder.property("margin-start", margin_start),
427 }
428 }
429
430 pub fn margin_top(self, margin_top: i32) -> Self {
431 Self {
432 builder: self.builder.property("margin-top", margin_top),
433 }
434 }
435
436 pub fn name(self, name: impl Into<glib::GString>) -> Self {
437 Self {
438 builder: self.builder.property("name", name.into()),
439 }
440 }
441
442 pub fn opacity(self, opacity: f64) -> Self {
443 Self {
444 builder: self.builder.property("opacity", opacity),
445 }
446 }
447
448 pub fn overflow(self, overflow: Overflow) -> Self {
449 Self {
450 builder: self.builder.property("overflow", overflow),
451 }
452 }
453
454 pub fn receives_default(self, receives_default: bool) -> Self {
455 Self {
456 builder: self.builder.property("receives-default", receives_default),
457 }
458 }
459
460 pub fn sensitive(self, sensitive: bool) -> Self {
461 Self {
462 builder: self.builder.property("sensitive", sensitive),
463 }
464 }
465
466 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
467 Self {
468 builder: self
469 .builder
470 .property("tooltip-markup", tooltip_markup.into()),
471 }
472 }
473
474 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
475 Self {
476 builder: self.builder.property("tooltip-text", tooltip_text.into()),
477 }
478 }
479
480 pub fn valign(self, valign: Align) -> Self {
481 Self {
482 builder: self.builder.property("valign", valign),
483 }
484 }
485
486 pub fn vexpand(self, vexpand: bool) -> Self {
487 Self {
488 builder: self.builder.property("vexpand", vexpand),
489 }
490 }
491
492 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
493 Self {
494 builder: self.builder.property("vexpand-set", vexpand_set),
495 }
496 }
497
498 pub fn visible(self, visible: bool) -> Self {
499 Self {
500 builder: self.builder.property("visible", visible),
501 }
502 }
503
504 pub fn width_request(self, width_request: i32) -> Self {
505 Self {
506 builder: self.builder.property("width-request", width_request),
507 }
508 }
509
510 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
511 Self {
512 builder: self.builder.property("accessible-role", accessible_role),
513 }
514 }
515
516 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
517 pub fn font(self, font: impl Into<glib::GString>) -> Self {
518 Self {
519 builder: self.builder.property("font", font.into()),
520 }
521 }
522
523 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
524 pub fn font_desc(self, font_desc: &pango::FontDescription) -> Self {
525 Self {
526 builder: self.builder.property("font-desc", font_desc),
527 }
528 }
529
530 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
531 pub fn language(self, language: impl Into<glib::GString>) -> Self {
532 Self {
533 builder: self.builder.property("language", language.into()),
534 }
535 }
536
537 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
538 pub fn level(self, level: FontChooserLevel) -> Self {
539 Self {
540 builder: self.builder.property("level", level),
541 }
542 }
543
544 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
545 pub fn preview_text(self, preview_text: impl Into<glib::GString>) -> Self {
546 Self {
547 builder: self.builder.property("preview-text", preview_text.into()),
548 }
549 }
550
551 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
552 pub fn show_preview_entry(self, show_preview_entry: bool) -> Self {
553 Self {
554 builder: self
555 .builder
556 .property("show-preview-entry", show_preview_entry),
557 }
558 }
559
560 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
563 pub fn build(self) -> FontButton {
564 assert_initialized_main_thread!();
565 self.builder.build()
566 }
567}