1#![allow(deprecated)]
5
6use crate::{
7 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, FontChooser,
8 FontChooserLevel, LayoutManager, Overflow, Widget,
9};
10use glib::{
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkFontChooserWidget")]
19 pub struct FontChooserWidget(Object<ffi::GtkFontChooserWidget>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, FontChooser;
20
21 match fn {
22 type_ => || ffi::gtk_font_chooser_widget_get_type(),
23 }
24}
25
26impl FontChooserWidget {
27 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
28 #[allow(deprecated)]
29 #[doc(alias = "gtk_font_chooser_widget_new")]
30 pub fn new() -> FontChooserWidget {
31 assert_initialized_main_thread!();
32 unsafe { Widget::from_glib_none(ffi::gtk_font_chooser_widget_new()).unsafe_cast() }
33 }
34
35 pub fn builder() -> FontChooserWidgetBuilder {
40 FontChooserWidgetBuilder::new()
41 }
42
43 #[doc(alias = "tweak-action")]
44 pub fn tweak_action(&self) -> Option<gio::Action> {
45 ObjectExt::property(self, "tweak-action")
46 }
47
48 #[doc(alias = "tweak-action")]
49 pub fn connect_tweak_action_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
50 unsafe extern "C" fn notify_tweak_action_trampoline<F: Fn(&FontChooserWidget) + 'static>(
51 this: *mut ffi::GtkFontChooserWidget,
52 _param_spec: glib::ffi::gpointer,
53 f: glib::ffi::gpointer,
54 ) {
55 let f: &F = &*(f as *const F);
56 f(&from_glib_borrow(this))
57 }
58 unsafe {
59 let f: Box_<F> = Box_::new(f);
60 connect_raw(
61 self.as_ptr() as *mut _,
62 c"notify::tweak-action".as_ptr() as *const _,
63 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
64 notify_tweak_action_trampoline::<F> as *const (),
65 )),
66 Box_::into_raw(f),
67 )
68 }
69 }
70}
71
72impl Default for FontChooserWidget {
73 fn default() -> Self {
74 Self::new()
75 }
76}
77
78#[must_use = "The builder must be built to be used"]
83pub struct FontChooserWidgetBuilder {
84 builder: glib::object::ObjectBuilder<'static, FontChooserWidget>,
85}
86
87impl FontChooserWidgetBuilder {
88 fn new() -> Self {
89 Self {
90 builder: glib::object::Object::builder(),
91 }
92 }
93
94 pub fn can_focus(self, can_focus: bool) -> Self {
95 Self {
96 builder: self.builder.property("can-focus", can_focus),
97 }
98 }
99
100 pub fn can_target(self, can_target: bool) -> Self {
101 Self {
102 builder: self.builder.property("can-target", can_target),
103 }
104 }
105
106 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
107 Self {
108 builder: self.builder.property("css-classes", css_classes.into()),
109 }
110 }
111
112 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
113 Self {
114 builder: self.builder.property("css-name", css_name.into()),
115 }
116 }
117
118 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
119 Self {
120 builder: self.builder.property("cursor", cursor.clone()),
121 }
122 }
123
124 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
125 Self {
126 builder: self.builder.property("focus-on-click", focus_on_click),
127 }
128 }
129
130 pub fn focusable(self, focusable: bool) -> Self {
131 Self {
132 builder: self.builder.property("focusable", focusable),
133 }
134 }
135
136 pub fn halign(self, halign: Align) -> Self {
137 Self {
138 builder: self.builder.property("halign", halign),
139 }
140 }
141
142 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
143 Self {
144 builder: self.builder.property("has-tooltip", has_tooltip),
145 }
146 }
147
148 pub fn height_request(self, height_request: i32) -> Self {
149 Self {
150 builder: self.builder.property("height-request", height_request),
151 }
152 }
153
154 pub fn hexpand(self, hexpand: bool) -> Self {
155 Self {
156 builder: self.builder.property("hexpand", hexpand),
157 }
158 }
159
160 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
161 Self {
162 builder: self.builder.property("hexpand-set", hexpand_set),
163 }
164 }
165
166 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
167 Self {
168 builder: self
169 .builder
170 .property("layout-manager", layout_manager.clone().upcast()),
171 }
172 }
173
174 #[cfg(feature = "v4_18")]
175 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
176 pub fn limit_events(self, limit_events: bool) -> Self {
177 Self {
178 builder: self.builder.property("limit-events", limit_events),
179 }
180 }
181
182 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
183 Self {
184 builder: self.builder.property("margin-bottom", margin_bottom),
185 }
186 }
187
188 pub fn margin_end(self, margin_end: i32) -> Self {
189 Self {
190 builder: self.builder.property("margin-end", margin_end),
191 }
192 }
193
194 pub fn margin_start(self, margin_start: i32) -> Self {
195 Self {
196 builder: self.builder.property("margin-start", margin_start),
197 }
198 }
199
200 pub fn margin_top(self, margin_top: i32) -> Self {
201 Self {
202 builder: self.builder.property("margin-top", margin_top),
203 }
204 }
205
206 pub fn name(self, name: impl Into<glib::GString>) -> Self {
207 Self {
208 builder: self.builder.property("name", name.into()),
209 }
210 }
211
212 pub fn opacity(self, opacity: f64) -> Self {
213 Self {
214 builder: self.builder.property("opacity", opacity),
215 }
216 }
217
218 pub fn overflow(self, overflow: Overflow) -> Self {
219 Self {
220 builder: self.builder.property("overflow", overflow),
221 }
222 }
223
224 pub fn receives_default(self, receives_default: bool) -> Self {
225 Self {
226 builder: self.builder.property("receives-default", receives_default),
227 }
228 }
229
230 pub fn sensitive(self, sensitive: bool) -> Self {
231 Self {
232 builder: self.builder.property("sensitive", sensitive),
233 }
234 }
235
236 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
237 Self {
238 builder: self
239 .builder
240 .property("tooltip-markup", tooltip_markup.into()),
241 }
242 }
243
244 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
245 Self {
246 builder: self.builder.property("tooltip-text", tooltip_text.into()),
247 }
248 }
249
250 pub fn valign(self, valign: Align) -> Self {
251 Self {
252 builder: self.builder.property("valign", valign),
253 }
254 }
255
256 pub fn vexpand(self, vexpand: bool) -> Self {
257 Self {
258 builder: self.builder.property("vexpand", vexpand),
259 }
260 }
261
262 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
263 Self {
264 builder: self.builder.property("vexpand-set", vexpand_set),
265 }
266 }
267
268 pub fn visible(self, visible: bool) -> Self {
269 Self {
270 builder: self.builder.property("visible", visible),
271 }
272 }
273
274 pub fn width_request(self, width_request: i32) -> Self {
275 Self {
276 builder: self.builder.property("width-request", width_request),
277 }
278 }
279
280 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
281 Self {
282 builder: self.builder.property("accessible-role", accessible_role),
283 }
284 }
285
286 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
287 pub fn font(self, font: impl Into<glib::GString>) -> Self {
288 Self {
289 builder: self.builder.property("font", font.into()),
290 }
291 }
292
293 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
294 pub fn font_desc(self, font_desc: &pango::FontDescription) -> Self {
295 Self {
296 builder: self.builder.property("font-desc", font_desc),
297 }
298 }
299
300 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
301 pub fn language(self, language: impl Into<glib::GString>) -> Self {
302 Self {
303 builder: self.builder.property("language", language.into()),
304 }
305 }
306
307 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
308 pub fn level(self, level: FontChooserLevel) -> Self {
309 Self {
310 builder: self.builder.property("level", level),
311 }
312 }
313
314 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
315 pub fn preview_text(self, preview_text: impl Into<glib::GString>) -> Self {
316 Self {
317 builder: self.builder.property("preview-text", preview_text.into()),
318 }
319 }
320
321 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
322 pub fn show_preview_entry(self, show_preview_entry: bool) -> Self {
323 Self {
324 builder: self
325 .builder
326 .property("show-preview-entry", show_preview_entry),
327 }
328 }
329
330 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
333 pub fn build(self) -> FontChooserWidget {
334 assert_initialized_main_thread!();
335 self.builder.build()
336 }
337}