gtk/auto/offscreen_window.rs
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
5use crate::{
6 Align, Application, Bin, Buildable, Container, ResizeMode, Widget, Window, WindowPosition,
7 WindowType, ffi,
8};
9use glib::{prelude::*, translate::*};
10
11glib::wrapper! {
12 /// GtkOffscreenWindow is strictly intended to be used for obtaining
13 /// snapshots of widgets that are not part of a normal widget hierarchy.
14 /// Since [`OffscreenWindow`][crate::OffscreenWindow] is a toplevel widget you cannot obtain
15 /// snapshots of a full window with it since you cannot pack a toplevel
16 /// widget in another toplevel.
17 ///
18 /// The idea is to take a widget and manually set the state of it,
19 /// add it to a GtkOffscreenWindow and then retrieve the snapshot
20 /// as a [`cairo::Surface`][crate::cairo::Surface] or [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
21 ///
22 /// GtkOffscreenWindow derives from [`Window`][crate::Window] only as an implementation
23 /// detail. Applications should not use any API specific to [`Window`][crate::Window]
24 /// to operate on this object. It should be treated as a [`Bin`][crate::Bin] that
25 /// has no parent widget.
26 ///
27 /// When contained offscreen widgets are redrawn, GtkOffscreenWindow
28 /// will emit a [`damage-event`][struct@crate::Widget#damage-event] signal.
29 ///
30 /// # Implements
31 ///
32 /// [`OffscreenWindowExt`][trait@crate::prelude::OffscreenWindowExt], [`GtkWindowExt`][trait@crate::prelude::GtkWindowExt], [`BinExt`][trait@crate::prelude::BinExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`GtkWindowExtManual`][trait@crate::prelude::GtkWindowExtManual], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
33 #[doc(alias = "GtkOffscreenWindow")]
34 pub struct OffscreenWindow(Object<ffi::GtkOffscreenWindow, ffi::GtkOffscreenWindowClass>) @extends Window, Bin, Container, Widget, @implements Buildable;
35
36 match fn {
37 type_ => || ffi::gtk_offscreen_window_get_type(),
38 }
39}
40
41impl OffscreenWindow {
42 pub const NONE: Option<&'static OffscreenWindow> = None;
43
44 /// Creates a toplevel container widget that is used to retrieve
45 /// snapshots of widgets without showing them on the screen.
46 ///
47 /// # Returns
48 ///
49 /// A pointer to a [`Widget`][crate::Widget]
50 #[doc(alias = "gtk_offscreen_window_new")]
51 pub fn new() -> OffscreenWindow {
52 assert_initialized_main_thread!();
53 unsafe { Widget::from_glib_none(ffi::gtk_offscreen_window_new()).unsafe_cast() }
54 }
55
56 // rustdoc-stripper-ignore-next
57 /// Creates a new builder-pattern struct instance to construct [`OffscreenWindow`] objects.
58 ///
59 /// This method returns an instance of [`OffscreenWindowBuilder`](crate::builders::OffscreenWindowBuilder) which can be used to create [`OffscreenWindow`] objects.
60 pub fn builder() -> OffscreenWindowBuilder {
61 OffscreenWindowBuilder::new()
62 }
63}
64
65impl Default for OffscreenWindow {
66 fn default() -> Self {
67 Self::new()
68 }
69}
70
71// rustdoc-stripper-ignore-next
72/// A [builder-pattern] type to construct [`OffscreenWindow`] objects.
73///
74/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
75#[must_use = "The builder must be built to be used"]
76pub struct OffscreenWindowBuilder {
77 builder: glib::object::ObjectBuilder<'static, OffscreenWindow>,
78}
79
80impl OffscreenWindowBuilder {
81 fn new() -> Self {
82 Self {
83 builder: glib::object::Object::builder(),
84 }
85 }
86
87 /// Whether the window should receive the input focus.
88 pub fn accept_focus(self, accept_focus: bool) -> Self {
89 Self {
90 builder: self.builder.property("accept-focus", accept_focus),
91 }
92 }
93
94 /// The [`Application`][crate::Application] associated with the window.
95 ///
96 /// The application will be kept alive for at least as long as it
97 /// has any windows associated with it (see [`ApplicationExtManual::hold()`][crate::gio::prelude::ApplicationExtManual::hold()]
98 /// for a way to keep it alive without windows).
99 ///
100 /// Normally, the connection between the application and the window
101 /// will remain until the window is destroyed, but you can explicitly
102 /// remove it by setting the :application property to [`None`].
103 pub fn application(self, application: &impl IsA<Application>) -> Self {
104 Self {
105 builder: self
106 .builder
107 .property("application", application.clone().upcast()),
108 }
109 }
110
111 /// The widget to which this window is attached.
112 /// See [`GtkWindowExt::set_attached_to()`][crate::prelude::GtkWindowExt::set_attached_to()].
113 ///
114 /// Examples of places where specifying this relation is useful are
115 /// for instance a [`Menu`][crate::Menu] created by a [`ComboBox`][crate::ComboBox], a completion
116 /// popup window created by [`Entry`][crate::Entry] or a typeahead search entry
117 /// created by [`TreeView`][crate::TreeView].
118 pub fn attached_to(self, attached_to: &impl IsA<Widget>) -> Self {
119 Self {
120 builder: self
121 .builder
122 .property("attached-to", attached_to.clone().upcast()),
123 }
124 }
125
126 /// Whether the window should be decorated by the window manager.
127 pub fn decorated(self, decorated: bool) -> Self {
128 Self {
129 builder: self.builder.property("decorated", decorated),
130 }
131 }
132
133 pub fn default_height(self, default_height: i32) -> Self {
134 Self {
135 builder: self.builder.property("default-height", default_height),
136 }
137 }
138
139 pub fn default_width(self, default_width: i32) -> Self {
140 Self {
141 builder: self.builder.property("default-width", default_width),
142 }
143 }
144
145 /// Whether the window frame should have a close button.
146 pub fn deletable(self, deletable: bool) -> Self {
147 Self {
148 builder: self.builder.property("deletable", deletable),
149 }
150 }
151
152 pub fn destroy_with_parent(self, destroy_with_parent: bool) -> Self {
153 Self {
154 builder: self
155 .builder
156 .property("destroy-with-parent", destroy_with_parent),
157 }
158 }
159
160 /// Whether the window should receive the input focus when mapped.
161 pub fn focus_on_map(self, focus_on_map: bool) -> Self {
162 Self {
163 builder: self.builder.property("focus-on-map", focus_on_map),
164 }
165 }
166
167 /// Whether 'focus rectangles' are currently visible in this window.
168 ///
169 /// This property is maintained by GTK+ based on user input
170 /// and should not be set by applications.
171 pub fn focus_visible(self, focus_visible: bool) -> Self {
172 Self {
173 builder: self.builder.property("focus-visible", focus_visible),
174 }
175 }
176
177 /// The window gravity of the window. See [`GtkWindowExt::move_()`][crate::prelude::GtkWindowExt::move_()] and [`gdk::Gravity`][crate::gdk::Gravity] for
178 /// more details about window gravity.
179 pub fn gravity(self, gravity: gdk::Gravity) -> Self {
180 Self {
181 builder: self.builder.property("gravity", gravity),
182 }
183 }
184
185 /// Whether the titlebar should be hidden during maximization.
186 pub fn hide_titlebar_when_maximized(self, hide_titlebar_when_maximized: bool) -> Self {
187 Self {
188 builder: self
189 .builder
190 .property("hide-titlebar-when-maximized", hide_titlebar_when_maximized),
191 }
192 }
193
194 pub fn icon(self, icon: &gdk_pixbuf::Pixbuf) -> Self {
195 Self {
196 builder: self.builder.property("icon", icon.clone()),
197 }
198 }
199
200 /// The :icon-name property specifies the name of the themed icon to
201 /// use as the window icon. See [`IconTheme`][crate::IconTheme] for more details.
202 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
203 Self {
204 builder: self.builder.property("icon-name", icon_name.into()),
205 }
206 }
207
208 /// Whether mnemonics are currently visible in this window.
209 ///
210 /// This property is maintained by GTK+ based on user input,
211 /// and should not be set by applications.
212 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
213 Self {
214 builder: self
215 .builder
216 .property("mnemonics-visible", mnemonics_visible),
217 }
218 }
219
220 pub fn modal(self, modal: bool) -> Self {
221 Self {
222 builder: self.builder.property("modal", modal),
223 }
224 }
225
226 pub fn resizable(self, resizable: bool) -> Self {
227 Self {
228 builder: self.builder.property("resizable", resizable),
229 }
230 }
231
232 pub fn role(self, role: impl Into<glib::GString>) -> Self {
233 Self {
234 builder: self.builder.property("role", role.into()),
235 }
236 }
237
238 pub fn screen(self, screen: &gdk::Screen) -> Self {
239 Self {
240 builder: self.builder.property("screen", screen.clone()),
241 }
242 }
243
244 pub fn skip_pager_hint(self, skip_pager_hint: bool) -> Self {
245 Self {
246 builder: self.builder.property("skip-pager-hint", skip_pager_hint),
247 }
248 }
249
250 pub fn skip_taskbar_hint(self, skip_taskbar_hint: bool) -> Self {
251 Self {
252 builder: self
253 .builder
254 .property("skip-taskbar-hint", skip_taskbar_hint),
255 }
256 }
257
258 /// The :startup-id is a write-only property for setting window's
259 /// startup notification identifier. See [`GtkWindowExt::set_startup_id()`][crate::prelude::GtkWindowExt::set_startup_id()]
260 /// for more details.
261 pub fn startup_id(self, startup_id: impl Into<glib::GString>) -> Self {
262 Self {
263 builder: self.builder.property("startup-id", startup_id.into()),
264 }
265 }
266
267 pub fn title(self, title: impl Into<glib::GString>) -> Self {
268 Self {
269 builder: self.builder.property("title", title.into()),
270 }
271 }
272
273 /// The transient parent of the window. See [`GtkWindowExt::set_transient_for()`][crate::prelude::GtkWindowExt::set_transient_for()] for
274 /// more details about transient windows.
275 pub fn transient_for(self, transient_for: &impl IsA<Window>) -> Self {
276 Self {
277 builder: self
278 .builder
279 .property("transient-for", transient_for.clone().upcast()),
280 }
281 }
282
283 pub fn type_(self, type_: WindowType) -> Self {
284 Self {
285 builder: self.builder.property("type", type_),
286 }
287 }
288
289 pub fn type_hint(self, type_hint: gdk::WindowTypeHint) -> Self {
290 Self {
291 builder: self.builder.property("type-hint", type_hint),
292 }
293 }
294
295 pub fn urgency_hint(self, urgency_hint: bool) -> Self {
296 Self {
297 builder: self.builder.property("urgency-hint", urgency_hint),
298 }
299 }
300
301 pub fn window_position(self, window_position: WindowPosition) -> Self {
302 Self {
303 builder: self.builder.property("window-position", window_position),
304 }
305 }
306
307 pub fn border_width(self, border_width: u32) -> Self {
308 Self {
309 builder: self.builder.property("border-width", border_width),
310 }
311 }
312
313 pub fn child(self, child: &impl IsA<Widget>) -> Self {
314 Self {
315 builder: self.builder.property("child", child.clone().upcast()),
316 }
317 }
318
319 pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
320 Self {
321 builder: self.builder.property("resize-mode", resize_mode),
322 }
323 }
324
325 pub fn app_paintable(self, app_paintable: bool) -> Self {
326 Self {
327 builder: self.builder.property("app-paintable", app_paintable),
328 }
329 }
330
331 pub fn can_default(self, can_default: bool) -> Self {
332 Self {
333 builder: self.builder.property("can-default", can_default),
334 }
335 }
336
337 pub fn can_focus(self, can_focus: bool) -> Self {
338 Self {
339 builder: self.builder.property("can-focus", can_focus),
340 }
341 }
342
343 pub fn events(self, events: gdk::EventMask) -> Self {
344 Self {
345 builder: self.builder.property("events", events),
346 }
347 }
348
349 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
350 pub fn expand(self, expand: bool) -> Self {
351 Self {
352 builder: self.builder.property("expand", expand),
353 }
354 }
355
356 /// Whether the widget should grab focus when it is clicked with the mouse.
357 ///
358 /// This property is only relevant for widgets that can take focus.
359 ///
360 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
361 /// GtkComboBox) implemented this property individually.
362 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
363 Self {
364 builder: self.builder.property("focus-on-click", focus_on_click),
365 }
366 }
367
368 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
369 pub fn halign(self, halign: Align) -> Self {
370 Self {
371 builder: self.builder.property("halign", halign),
372 }
373 }
374
375 pub fn has_default(self, has_default: bool) -> Self {
376 Self {
377 builder: self.builder.property("has-default", has_default),
378 }
379 }
380
381 pub fn has_focus(self, has_focus: bool) -> Self {
382 Self {
383 builder: self.builder.property("has-focus", has_focus),
384 }
385 }
386
387 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
388 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
389 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
390 /// whether it will provide a tooltip or not.
391 ///
392 /// Note that setting this property to [`true`] for the first time will change
393 /// the event masks of the GdkWindows of this widget to include leave-notify
394 /// and motion-notify events. This cannot and will not be undone when the
395 /// property is set to [`false`] again.
396 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
397 Self {
398 builder: self.builder.property("has-tooltip", has_tooltip),
399 }
400 }
401
402 pub fn height_request(self, height_request: i32) -> Self {
403 Self {
404 builder: self.builder.property("height-request", height_request),
405 }
406 }
407
408 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
409 pub fn hexpand(self, hexpand: bool) -> Self {
410 Self {
411 builder: self.builder.property("hexpand", hexpand),
412 }
413 }
414
415 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
416 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
417 Self {
418 builder: self.builder.property("hexpand-set", hexpand_set),
419 }
420 }
421
422 pub fn is_focus(self, is_focus: bool) -> Self {
423 Self {
424 builder: self.builder.property("is-focus", is_focus),
425 }
426 }
427
428 /// Sets all four sides' margin at once. If read, returns max
429 /// margin on any side.
430 pub fn margin(self, margin: i32) -> Self {
431 Self {
432 builder: self.builder.property("margin", margin),
433 }
434 }
435
436 /// Margin on bottom side of widget.
437 ///
438 /// This property adds margin outside of the widget's normal size
439 /// request, the margin will be added in addition to the size from
440 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
441 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
442 Self {
443 builder: self.builder.property("margin-bottom", margin_bottom),
444 }
445 }
446
447 /// Margin on end of widget, horizontally. This property supports
448 /// left-to-right and right-to-left text directions.
449 ///
450 /// This property adds margin outside of the widget's normal size
451 /// request, the margin will be added in addition to the size from
452 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
453 pub fn margin_end(self, margin_end: i32) -> Self {
454 Self {
455 builder: self.builder.property("margin-end", margin_end),
456 }
457 }
458
459 /// Margin on start of widget, horizontally. This property supports
460 /// left-to-right and right-to-left text directions.
461 ///
462 /// This property adds margin outside of the widget's normal size
463 /// request, the margin will be added in addition to the size from
464 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
465 pub fn margin_start(self, margin_start: i32) -> Self {
466 Self {
467 builder: self.builder.property("margin-start", margin_start),
468 }
469 }
470
471 /// Margin on top side of widget.
472 ///
473 /// This property adds margin outside of the widget's normal size
474 /// request, the margin will be added in addition to the size from
475 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
476 pub fn margin_top(self, margin_top: i32) -> Self {
477 Self {
478 builder: self.builder.property("margin-top", margin_top),
479 }
480 }
481
482 pub fn name(self, name: impl Into<glib::GString>) -> Self {
483 Self {
484 builder: self.builder.property("name", name.into()),
485 }
486 }
487
488 pub fn no_show_all(self, no_show_all: bool) -> Self {
489 Self {
490 builder: self.builder.property("no-show-all", no_show_all),
491 }
492 }
493
494 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
495 /// more details about window opacity.
496 ///
497 /// Before 3.8 this was only available in GtkWindow
498 pub fn opacity(self, opacity: f64) -> Self {
499 Self {
500 builder: self.builder.property("opacity", opacity),
501 }
502 }
503
504 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
505 Self {
506 builder: self.builder.property("parent", parent.clone().upcast()),
507 }
508 }
509
510 pub fn receives_default(self, receives_default: bool) -> Self {
511 Self {
512 builder: self.builder.property("receives-default", receives_default),
513 }
514 }
515
516 pub fn sensitive(self, sensitive: bool) -> Self {
517 Self {
518 builder: self.builder.property("sensitive", sensitive),
519 }
520 }
521
522 /// Sets the text of tooltip to be the given string, which is marked up
523 /// with the [Pango text markup language][PangoMarkupFormat].
524 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
525 ///
526 /// This is a convenience property which will take care of getting the
527 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
528 /// will automatically be set to [`true`] and there will be taken care of
529 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
530 ///
531 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
532 /// are set, the last one wins.
533 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
534 Self {
535 builder: self
536 .builder
537 .property("tooltip-markup", tooltip_markup.into()),
538 }
539 }
540
541 /// Sets the text of tooltip to be the given string.
542 ///
543 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
544 ///
545 /// This is a convenience property which will take care of getting the
546 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
547 /// will automatically be set to [`true`] and there will be taken care of
548 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
549 ///
550 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
551 /// are set, the last one wins.
552 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
553 Self {
554 builder: self.builder.property("tooltip-text", tooltip_text.into()),
555 }
556 }
557
558 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
559 pub fn valign(self, valign: Align) -> Self {
560 Self {
561 builder: self.builder.property("valign", valign),
562 }
563 }
564
565 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
566 pub fn vexpand(self, vexpand: bool) -> Self {
567 Self {
568 builder: self.builder.property("vexpand", vexpand),
569 }
570 }
571
572 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
573 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
574 Self {
575 builder: self.builder.property("vexpand-set", vexpand_set),
576 }
577 }
578
579 pub fn visible(self, visible: bool) -> Self {
580 Self {
581 builder: self.builder.property("visible", visible),
582 }
583 }
584
585 pub fn width_request(self, width_request: i32) -> Self {
586 Self {
587 builder: self.builder.property("width-request", width_request),
588 }
589 }
590
591 // rustdoc-stripper-ignore-next
592 /// Build the [`OffscreenWindow`].
593 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
594 pub fn build(self) -> OffscreenWindow {
595 assert_initialized_main_thread!();
596 self.builder.build()
597 }
598}
599
600/// Trait containing all [`struct@OffscreenWindow`] methods.
601///
602/// # Implementors
603///
604/// [`OffscreenWindow`][struct@crate::OffscreenWindow]
605pub trait OffscreenWindowExt: IsA<OffscreenWindow> + 'static {
606 /// Retrieves a snapshot of the contained widget in the form of
607 /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]. This is a new pixbuf with a reference count of 1,
608 /// and the application should unreference it once it is no longer
609 /// needed.
610 ///
611 /// # Returns
612 ///
613 /// A [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] pointer, or [`None`].
614 #[doc(alias = "gtk_offscreen_window_get_pixbuf")]
615 #[doc(alias = "get_pixbuf")]
616 fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
617 unsafe {
618 from_glib_full(ffi::gtk_offscreen_window_get_pixbuf(
619 self.as_ref().to_glib_none().0,
620 ))
621 }
622 }
623
624 /// Retrieves a snapshot of the contained widget in the form of
625 /// a [`cairo::Surface`][crate::cairo::Surface]. If you need to keep this around over window
626 /// resizes then you should add a reference to it.
627 ///
628 /// # Returns
629 ///
630 /// A [`cairo::Surface`][crate::cairo::Surface] pointer to the offscreen
631 /// surface, or [`None`].
632 #[doc(alias = "gtk_offscreen_window_get_surface")]
633 #[doc(alias = "get_surface")]
634 fn surface(&self) -> Option<cairo::Surface> {
635 unsafe {
636 from_glib_none(ffi::gtk_offscreen_window_get_surface(
637 self.as_ref().to_glib_none().0,
638 ))
639 }
640 }
641}
642
643impl<O: IsA<OffscreenWindow>> OffscreenWindowExt for O {}