gtk/auto/drawing_area.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::{Align, Buildable, Container, Widget, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// color);
10 ///
11 /// cairo_fill (cr);
12 ///
13 /// return FALSE;
14 /// }
15 /// [...]
16 /// GtkWidget *drawing_area = gtk_drawing_area_new ();
17 /// gtk_widget_set_size_request (drawing_area, 100, 100);
18 /// g_signal_connect (G_OBJECT (drawing_area), "draw",
19 /// G_CALLBACK (draw_callback), NULL);
20 /// ]|
21 ///
22 /// Draw signals are normally delivered when a drawing area first comes
23 /// onscreen, or when it’s covered by another window and then uncovered.
24 /// You can also force an expose event by adding to the “damage region”
25 /// of the drawing area’s window; [`WidgetExt::queue_draw_area()`][crate::prelude::WidgetExt::queue_draw_area()] and
26 /// [`Window::invalidate_rect()`][crate::gdk::Window::invalidate_rect()] are equally good ways to do this.
27 /// You’ll then get a draw signal for the invalid region.
28 ///
29 /// The available routines for drawing are documented on the
30 /// [GDK Drawing Primitives][gdk3-Cairo-Interaction] page
31 /// and the cairo documentation.
32 ///
33 /// To receive mouse events on a drawing area, you will need to enable
34 /// them with [`WidgetExtManual::add_events()`][crate::prelude::WidgetExtManual::add_events()]. To receive keyboard events, you
35 /// will need to set the “can-focus” property on the drawing area, and you
36 /// should probably draw some user-visible indication that the drawing
37 /// area is focused. Use [`WidgetExt::has_focus()`][crate::prelude::WidgetExt::has_focus()] in your expose event
38 /// handler to decide whether to draw the focus indicator. See
39 /// [`render_focus()`][crate::render_focus()] for one way to draw focus.
40 ///
41 /// # Implements
42 ///
43 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
44 #[doc(alias = "GtkDrawingArea")]
45 pub struct DrawingArea(Object<ffi::GtkDrawingArea, ffi::GtkDrawingAreaClass>) @extends Widget, @implements Buildable;
46
47 match fn {
48 type_ => || ffi::gtk_drawing_area_get_type(),
49 }
50}
51
52impl DrawingArea {
53 pub const NONE: Option<&'static DrawingArea> = None;
54
55 /// Creates a new drawing area.
56 ///
57 /// # Returns
58 ///
59 /// a new [`DrawingArea`][crate::DrawingArea]
60 #[doc(alias = "gtk_drawing_area_new")]
61 pub fn new() -> DrawingArea {
62 assert_initialized_main_thread!();
63 unsafe { Widget::from_glib_none(ffi::gtk_drawing_area_new()).unsafe_cast() }
64 }
65
66 // rustdoc-stripper-ignore-next
67 /// Creates a new builder-pattern struct instance to construct [`DrawingArea`] objects.
68 ///
69 /// This method returns an instance of [`DrawingAreaBuilder`](crate::builders::DrawingAreaBuilder) which can be used to create [`DrawingArea`] objects.
70 pub fn builder() -> DrawingAreaBuilder {
71 DrawingAreaBuilder::new()
72 }
73}
74
75impl Default for DrawingArea {
76 fn default() -> Self {
77 Self::new()
78 }
79}
80
81// rustdoc-stripper-ignore-next
82/// A [builder-pattern] type to construct [`DrawingArea`] objects.
83///
84/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
85#[must_use = "The builder must be built to be used"]
86pub struct DrawingAreaBuilder {
87 builder: glib::object::ObjectBuilder<'static, DrawingArea>,
88}
89
90impl DrawingAreaBuilder {
91 fn new() -> Self {
92 Self {
93 builder: glib::object::Object::builder(),
94 }
95 }
96
97 pub fn app_paintable(self, app_paintable: bool) -> Self {
98 Self {
99 builder: self.builder.property("app-paintable", app_paintable),
100 }
101 }
102
103 pub fn can_default(self, can_default: bool) -> Self {
104 Self {
105 builder: self.builder.property("can-default", can_default),
106 }
107 }
108
109 pub fn can_focus(self, can_focus: bool) -> Self {
110 Self {
111 builder: self.builder.property("can-focus", can_focus),
112 }
113 }
114
115 pub fn events(self, events: gdk::EventMask) -> Self {
116 Self {
117 builder: self.builder.property("events", events),
118 }
119 }
120
121 /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
122 pub fn expand(self, expand: bool) -> Self {
123 Self {
124 builder: self.builder.property("expand", expand),
125 }
126 }
127
128 /// Whether the widget should grab focus when it is clicked with the mouse.
129 ///
130 /// This property is only relevant for widgets that can take focus.
131 ///
132 /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
133 /// GtkComboBox) implemented this property individually.
134 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
135 Self {
136 builder: self.builder.property("focus-on-click", focus_on_click),
137 }
138 }
139
140 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
141 pub fn halign(self, halign: Align) -> Self {
142 Self {
143 builder: self.builder.property("halign", halign),
144 }
145 }
146
147 pub fn has_default(self, has_default: bool) -> Self {
148 Self {
149 builder: self.builder.property("has-default", has_default),
150 }
151 }
152
153 pub fn has_focus(self, has_focus: bool) -> Self {
154 Self {
155 builder: self.builder.property("has-focus", has_focus),
156 }
157 }
158
159 /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
160 /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
161 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
162 /// whether it will provide a tooltip or not.
163 ///
164 /// Note that setting this property to [`true`] for the first time will change
165 /// the event masks of the GdkWindows of this widget to include leave-notify
166 /// and motion-notify events. This cannot and will not be undone when the
167 /// property is set to [`false`] again.
168 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
169 Self {
170 builder: self.builder.property("has-tooltip", has_tooltip),
171 }
172 }
173
174 pub fn height_request(self, height_request: i32) -> Self {
175 Self {
176 builder: self.builder.property("height-request", height_request),
177 }
178 }
179
180 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
181 pub fn hexpand(self, hexpand: bool) -> Self {
182 Self {
183 builder: self.builder.property("hexpand", hexpand),
184 }
185 }
186
187 /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
188 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
189 Self {
190 builder: self.builder.property("hexpand-set", hexpand_set),
191 }
192 }
193
194 pub fn is_focus(self, is_focus: bool) -> Self {
195 Self {
196 builder: self.builder.property("is-focus", is_focus),
197 }
198 }
199
200 /// Sets all four sides' margin at once. If read, returns max
201 /// margin on any side.
202 pub fn margin(self, margin: i32) -> Self {
203 Self {
204 builder: self.builder.property("margin", margin),
205 }
206 }
207
208 /// Margin on bottom side of widget.
209 ///
210 /// This property adds margin outside of the widget's normal size
211 /// request, the margin will be added in addition to the size from
212 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
213 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
214 Self {
215 builder: self.builder.property("margin-bottom", margin_bottom),
216 }
217 }
218
219 /// Margin on end of widget, horizontally. This property supports
220 /// left-to-right and right-to-left text directions.
221 ///
222 /// This property adds margin outside of the widget's normal size
223 /// request, the margin will be added in addition to the size from
224 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
225 pub fn margin_end(self, margin_end: i32) -> Self {
226 Self {
227 builder: self.builder.property("margin-end", margin_end),
228 }
229 }
230
231 /// Margin on start of widget, horizontally. This property supports
232 /// left-to-right and right-to-left text directions.
233 ///
234 /// This property adds margin outside of the widget's normal size
235 /// request, the margin will be added in addition to the size from
236 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
237 pub fn margin_start(self, margin_start: i32) -> Self {
238 Self {
239 builder: self.builder.property("margin-start", margin_start),
240 }
241 }
242
243 /// Margin on top side of widget.
244 ///
245 /// This property adds margin outside of the widget's normal size
246 /// request, the margin will be added in addition to the size from
247 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
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 /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
267 /// more details about window opacity.
268 ///
269 /// Before 3.8 this was only available in GtkWindow
270 pub fn opacity(self, opacity: f64) -> Self {
271 Self {
272 builder: self.builder.property("opacity", opacity),
273 }
274 }
275
276 pub fn parent(self, parent: &impl IsA<Container>) -> Self {
277 Self {
278 builder: self.builder.property("parent", parent.clone().upcast()),
279 }
280 }
281
282 pub fn receives_default(self, receives_default: bool) -> Self {
283 Self {
284 builder: self.builder.property("receives-default", receives_default),
285 }
286 }
287
288 pub fn sensitive(self, sensitive: bool) -> Self {
289 Self {
290 builder: self.builder.property("sensitive", sensitive),
291 }
292 }
293
294 /// Sets the text of tooltip to be the given string, which is marked up
295 /// with the [Pango text markup language][PangoMarkupFormat].
296 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
297 ///
298 /// This is a convenience property which will take care of getting the
299 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
300 /// will automatically be set to [`true`] and there will be taken care of
301 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
302 ///
303 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
304 /// are set, the last one wins.
305 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
306 Self {
307 builder: self
308 .builder
309 .property("tooltip-markup", tooltip_markup.into()),
310 }
311 }
312
313 /// Sets the text of tooltip to be the given string.
314 ///
315 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
316 ///
317 /// This is a convenience property which will take care of getting the
318 /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
319 /// will automatically be set to [`true`] and there will be taken care of
320 /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
321 ///
322 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
323 /// are set, the last one wins.
324 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
325 Self {
326 builder: self.builder.property("tooltip-text", tooltip_text.into()),
327 }
328 }
329
330 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
331 pub fn valign(self, valign: Align) -> Self {
332 Self {
333 builder: self.builder.property("valign", valign),
334 }
335 }
336
337 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
338 pub fn vexpand(self, vexpand: bool) -> Self {
339 Self {
340 builder: self.builder.property("vexpand", vexpand),
341 }
342 }
343
344 /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
345 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
346 Self {
347 builder: self.builder.property("vexpand-set", vexpand_set),
348 }
349 }
350
351 pub fn visible(self, visible: bool) -> Self {
352 Self {
353 builder: self.builder.property("visible", visible),
354 }
355 }
356
357 pub fn width_request(self, width_request: i32) -> Self {
358 Self {
359 builder: self.builder.property("width-request", width_request),
360 }
361 }
362
363 // rustdoc-stripper-ignore-next
364 /// Build the [`DrawingArea`].
365 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
366 pub fn build(self) -> DrawingArea {
367 assert_initialized_main_thread!();
368 self.builder.build()
369 }
370}