1use gdk;
6use glib::object::Cast;
7use glib::translate::*;
8use glib::StaticType;
9use glib::ToValue;
10use gtk_sys;
11use std::fmt;
12use Align;
13use Buildable;
14use Container;
15use Widget;
16
17glib_wrapper! {
18 pub struct DrawingArea(Object<gtk_sys::GtkDrawingArea, gtk_sys::GtkDrawingAreaClass, DrawingAreaClass>) @extends Widget, @implements Buildable;
19
20 match fn {
21 get_type => || gtk_sys::gtk_drawing_area_get_type(),
22 }
23}
24
25impl DrawingArea {
26 pub fn new() -> DrawingArea {
27 assert_initialized_main_thread!();
28 unsafe { Widget::from_glib_none(gtk_sys::gtk_drawing_area_new()).unsafe_cast() }
29 }
30}
31
32impl Default for DrawingArea {
33 fn default() -> Self {
34 Self::new()
35 }
36}
37
38pub struct DrawingAreaBuilder {
39 app_paintable: Option<bool>,
40 can_default: Option<bool>,
41 can_focus: Option<bool>,
42 events: Option<gdk::EventMask>,
43 expand: Option<bool>,
44 #[cfg(any(feature = "v3_20", feature = "dox"))]
45 focus_on_click: Option<bool>,
46 halign: Option<Align>,
47 has_default: Option<bool>,
48 has_focus: Option<bool>,
49 has_tooltip: Option<bool>,
50 height_request: Option<i32>,
51 hexpand: Option<bool>,
52 hexpand_set: Option<bool>,
53 is_focus: Option<bool>,
54 margin: Option<i32>,
55 margin_bottom: Option<i32>,
56 margin_end: Option<i32>,
57 margin_start: Option<i32>,
58 margin_top: Option<i32>,
59 name: Option<String>,
60 no_show_all: Option<bool>,
61 opacity: Option<f64>,
62 parent: Option<Container>,
63 receives_default: Option<bool>,
64 sensitive: Option<bool>,
65 tooltip_markup: Option<String>,
67 tooltip_text: Option<String>,
68 valign: Option<Align>,
69 vexpand: Option<bool>,
70 vexpand_set: Option<bool>,
71 visible: Option<bool>,
72 width_request: Option<i32>,
73}
74
75impl DrawingAreaBuilder {
76 pub fn new() -> Self {
77 Self {
78 app_paintable: None,
79 can_default: None,
80 can_focus: None,
81 events: None,
82 expand: None,
83 #[cfg(any(feature = "v3_20", feature = "dox"))]
84 focus_on_click: None,
85 halign: None,
86 has_default: None,
87 has_focus: None,
88 has_tooltip: None,
89 height_request: None,
90 hexpand: None,
91 hexpand_set: None,
92 is_focus: None,
93 margin: None,
94 margin_bottom: None,
95 margin_end: None,
96 margin_start: None,
97 margin_top: None,
98 name: None,
99 no_show_all: None,
100 opacity: None,
101 parent: None,
102 receives_default: None,
103 sensitive: None,
104 tooltip_markup: None,
105 tooltip_text: None,
106 valign: None,
107 vexpand: None,
108 vexpand_set: None,
109 visible: None,
110 width_request: None,
111 }
112 }
113
114 pub fn build(self) -> DrawingArea {
115 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
116 if let Some(ref app_paintable) = self.app_paintable {
117 properties.push(("app-paintable", app_paintable));
118 }
119 if let Some(ref can_default) = self.can_default {
120 properties.push(("can-default", can_default));
121 }
122 if let Some(ref can_focus) = self.can_focus {
123 properties.push(("can-focus", can_focus));
124 }
125 if let Some(ref events) = self.events {
126 properties.push(("events", events));
127 }
128 if let Some(ref expand) = self.expand {
129 properties.push(("expand", expand));
130 }
131 #[cfg(any(feature = "v3_20", feature = "dox"))]
132 {
133 if let Some(ref focus_on_click) = self.focus_on_click {
134 properties.push(("focus-on-click", focus_on_click));
135 }
136 }
137 if let Some(ref halign) = self.halign {
138 properties.push(("halign", halign));
139 }
140 if let Some(ref has_default) = self.has_default {
141 properties.push(("has-default", has_default));
142 }
143 if let Some(ref has_focus) = self.has_focus {
144 properties.push(("has-focus", has_focus));
145 }
146 if let Some(ref has_tooltip) = self.has_tooltip {
147 properties.push(("has-tooltip", has_tooltip));
148 }
149 if let Some(ref height_request) = self.height_request {
150 properties.push(("height-request", height_request));
151 }
152 if let Some(ref hexpand) = self.hexpand {
153 properties.push(("hexpand", hexpand));
154 }
155 if let Some(ref hexpand_set) = self.hexpand_set {
156 properties.push(("hexpand-set", hexpand_set));
157 }
158 if let Some(ref is_focus) = self.is_focus {
159 properties.push(("is-focus", is_focus));
160 }
161 if let Some(ref margin) = self.margin {
162 properties.push(("margin", margin));
163 }
164 if let Some(ref margin_bottom) = self.margin_bottom {
165 properties.push(("margin-bottom", margin_bottom));
166 }
167 if let Some(ref margin_end) = self.margin_end {
168 properties.push(("margin-end", margin_end));
169 }
170 if let Some(ref margin_start) = self.margin_start {
171 properties.push(("margin-start", margin_start));
172 }
173 if let Some(ref margin_top) = self.margin_top {
174 properties.push(("margin-top", margin_top));
175 }
176 if let Some(ref name) = self.name {
177 properties.push(("name", name));
178 }
179 if let Some(ref no_show_all) = self.no_show_all {
180 properties.push(("no-show-all", no_show_all));
181 }
182 if let Some(ref opacity) = self.opacity {
183 properties.push(("opacity", opacity));
184 }
185 if let Some(ref parent) = self.parent {
186 properties.push(("parent", parent));
187 }
188 if let Some(ref receives_default) = self.receives_default {
189 properties.push(("receives-default", receives_default));
190 }
191 if let Some(ref sensitive) = self.sensitive {
192 properties.push(("sensitive", sensitive));
193 }
194 if let Some(ref tooltip_markup) = self.tooltip_markup {
195 properties.push(("tooltip-markup", tooltip_markup));
196 }
197 if let Some(ref tooltip_text) = self.tooltip_text {
198 properties.push(("tooltip-text", tooltip_text));
199 }
200 if let Some(ref valign) = self.valign {
201 properties.push(("valign", valign));
202 }
203 if let Some(ref vexpand) = self.vexpand {
204 properties.push(("vexpand", vexpand));
205 }
206 if let Some(ref vexpand_set) = self.vexpand_set {
207 properties.push(("vexpand-set", vexpand_set));
208 }
209 if let Some(ref visible) = self.visible {
210 properties.push(("visible", visible));
211 }
212 if let Some(ref width_request) = self.width_request {
213 properties.push(("width-request", width_request));
214 }
215 glib::Object::new(DrawingArea::static_type(), &properties)
216 .expect("object new")
217 .downcast()
218 .expect("downcast")
219 }
220
221 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
222 self.app_paintable = Some(app_paintable);
223 self
224 }
225
226 pub fn can_default(mut self, can_default: bool) -> Self {
227 self.can_default = Some(can_default);
228 self
229 }
230
231 pub fn can_focus(mut self, can_focus: bool) -> Self {
232 self.can_focus = Some(can_focus);
233 self
234 }
235
236 pub fn events(mut self, events: gdk::EventMask) -> Self {
237 self.events = Some(events);
238 self
239 }
240
241 pub fn expand(mut self, expand: bool) -> Self {
242 self.expand = Some(expand);
243 self
244 }
245
246 #[cfg(any(feature = "v3_20", feature = "dox"))]
247 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
248 self.focus_on_click = Some(focus_on_click);
249 self
250 }
251
252 pub fn halign(mut self, halign: Align) -> Self {
253 self.halign = Some(halign);
254 self
255 }
256
257 pub fn has_default(mut self, has_default: bool) -> Self {
258 self.has_default = Some(has_default);
259 self
260 }
261
262 pub fn has_focus(mut self, has_focus: bool) -> Self {
263 self.has_focus = Some(has_focus);
264 self
265 }
266
267 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
268 self.has_tooltip = Some(has_tooltip);
269 self
270 }
271
272 pub fn height_request(mut self, height_request: i32) -> Self {
273 self.height_request = Some(height_request);
274 self
275 }
276
277 pub fn hexpand(mut self, hexpand: bool) -> Self {
278 self.hexpand = Some(hexpand);
279 self
280 }
281
282 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
283 self.hexpand_set = Some(hexpand_set);
284 self
285 }
286
287 pub fn is_focus(mut self, is_focus: bool) -> Self {
288 self.is_focus = Some(is_focus);
289 self
290 }
291
292 pub fn margin(mut self, margin: i32) -> Self {
293 self.margin = Some(margin);
294 self
295 }
296
297 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
298 self.margin_bottom = Some(margin_bottom);
299 self
300 }
301
302 pub fn margin_end(mut self, margin_end: i32) -> Self {
303 self.margin_end = Some(margin_end);
304 self
305 }
306
307 pub fn margin_start(mut self, margin_start: i32) -> Self {
308 self.margin_start = Some(margin_start);
309 self
310 }
311
312 pub fn margin_top(mut self, margin_top: i32) -> Self {
313 self.margin_top = Some(margin_top);
314 self
315 }
316
317 pub fn name(mut self, name: &str) -> Self {
318 self.name = Some(name.to_string());
319 self
320 }
321
322 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
323 self.no_show_all = Some(no_show_all);
324 self
325 }
326
327 pub fn opacity(mut self, opacity: f64) -> Self {
328 self.opacity = Some(opacity);
329 self
330 }
331
332 pub fn parent(mut self, parent: &Container) -> Self {
333 self.parent = Some(parent.clone());
334 self
335 }
336
337 pub fn receives_default(mut self, receives_default: bool) -> Self {
338 self.receives_default = Some(receives_default);
339 self
340 }
341
342 pub fn sensitive(mut self, sensitive: bool) -> Self {
343 self.sensitive = Some(sensitive);
344 self
345 }
346
347 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
348 self.tooltip_markup = Some(tooltip_markup.to_string());
349 self
350 }
351
352 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
353 self.tooltip_text = Some(tooltip_text.to_string());
354 self
355 }
356
357 pub fn valign(mut self, valign: Align) -> Self {
358 self.valign = Some(valign);
359 self
360 }
361
362 pub fn vexpand(mut self, vexpand: bool) -> Self {
363 self.vexpand = Some(vexpand);
364 self
365 }
366
367 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
368 self.vexpand_set = Some(vexpand_set);
369 self
370 }
371
372 pub fn visible(mut self, visible: bool) -> Self {
373 self.visible = Some(visible);
374 self
375 }
376
377 pub fn width_request(mut self, width_request: i32) -> Self {
378 self.width_request = Some(width_request);
379 self
380 }
381}
382
383pub const NONE_DRAWING_AREA: Option<&DrawingArea> = None;
384
385impl fmt::Display for DrawingArea {
386 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
387 write!(f, "DrawingArea")
388 }
389}