1use crate::Align;
4use crate::Container;
5use crate::IconSize;
6use crate::Image;
7use glib::object::{IsA, ObjectExt};
8use glib::signal::{connect_raw, SignalHandlerId};
9use glib::translate::*;
10use glib::Cast;
11use std::boxed::Box as Box_;
12use std::mem::transmute;
13
14mod sealed {
15 pub trait Sealed {}
16 impl<T: glib::IsA<crate::Image>> Sealed for T {}
17}
18
19pub trait ImageExtManual: IsA<Image> + sealed::Sealed + 'static {
20 #[doc(alias = "icon-size")]
21 fn icon_size(&self) -> IconSize {
22 unsafe { from_glib(self.as_ref().property::<i32>("icon-size")) }
23 }
24
25 #[doc(alias = "icon-size")]
26 fn set_icon_size(&self, icon_size: IconSize) {
27 self.as_ref()
28 .set_property("icon-size", icon_size.into_glib());
29 }
30
31 #[doc(alias = "icon-size")]
32 fn connect_icon_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
33 unsafe extern "C" fn notify_icon_size_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
34 this: *mut ffi::GtkImage,
35 _param_spec: glib::ffi::gpointer,
36 f: glib::ffi::gpointer,
37 ) {
38 let f: &F = &*(f as *const F);
39 f(Image::from_glib_borrow(this).unsafe_cast_ref())
40 }
41 unsafe {
42 let f: Box_<F> = Box_::new(f);
43 connect_raw(
44 self.as_ptr() as *mut _,
45 b"notify::icon-size\0".as_ptr() as *const _,
46 Some(transmute::<_, unsafe extern "C" fn()>(
47 notify_icon_size_trampoline::<Self, F> as *const (),
48 )),
49 Box_::into_raw(f),
50 )
51 }
52 }
53}
54
55impl<O: IsA<Image>> ImageExtManual for O {}
56
57impl Image {
58 pub fn builder() -> ImageBuilder {
63 ImageBuilder::new()
64 }
65}
66
67#[must_use = "The builder must be built to be used"]
70pub struct ImageBuilder {
71 builder: glib::object::ObjectBuilder<'static, Image>,
72}
73
74impl ImageBuilder {
75 pub fn new() -> Self {
78 Self {
79 builder: glib::object::Object::builder(),
80 }
81 }
82
83 pub fn file(self, file: &str) -> Self {
84 Self {
85 builder: self.builder.property("file", file),
86 }
87 }
88
89 pub fn gicon<P: IsA<gio::Icon>>(self, gicon: &P) -> Self {
90 Self {
91 builder: self.builder.property("gicon", gicon),
92 }
93 }
94
95 pub fn icon_name(self, icon_name: &str) -> Self {
96 Self {
97 builder: self.builder.property("icon-name", icon_name),
98 }
99 }
100
101 pub fn icon_size(self, icon_size: IconSize) -> Self {
102 Self {
103 builder: self.builder.property("icon-size", icon_size),
104 }
105 }
106
107 pub fn pixbuf(self, pixbuf: &gdk_pixbuf::Pixbuf) -> Self {
108 Self {
109 builder: self.builder.property("pixbuf", pixbuf),
110 }
111 }
112
113 pub fn pixbuf_animation<P: IsA<gdk_pixbuf::PixbufAnimation>>(
114 self,
115 pixbuf_animation: &P,
116 ) -> Self {
117 Self {
118 builder: self.builder.property("pixbuf-animation", pixbuf_animation),
119 }
120 }
121
122 pub fn pixel_size(self, pixel_size: i32) -> Self {
123 Self {
124 builder: self.builder.property("pixel-size", pixel_size),
125 }
126 }
127
128 pub fn resource(self, resource: &str) -> Self {
129 Self {
130 builder: self.builder.property("resource", resource),
131 }
132 }
133
134 pub fn surface(self, surface: &cairo::Surface) -> Self {
135 Self {
136 builder: self.builder.property("surface", surface),
137 }
138 }
139
140 pub fn use_fallback(self, use_fallback: bool) -> Self {
141 Self {
142 builder: self.builder.property("use-fallback", use_fallback),
143 }
144 }
145
146 pub fn app_paintable(self, app_paintable: bool) -> Self {
147 Self {
148 builder: self.builder.property("app-paintable", app_paintable),
149 }
150 }
151
152 pub fn can_default(self, can_default: bool) -> Self {
153 Self {
154 builder: self.builder.property("can-default", can_default),
155 }
156 }
157
158 pub fn can_focus(self, can_focus: bool) -> Self {
159 Self {
160 builder: self.builder.property("can-focus", can_focus),
161 }
162 }
163
164 pub fn events(self, events: gdk::EventMask) -> Self {
165 Self {
166 builder: self.builder.property("events", events),
167 }
168 }
169
170 pub fn expand(self, expand: bool) -> Self {
171 Self {
172 builder: self.builder.property("expand", expand),
173 }
174 }
175
176 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
177 Self {
178 builder: self.builder.property("focus-on-click", focus_on_click),
179 }
180 }
181
182 pub fn halign(self, halign: Align) -> Self {
183 Self {
184 builder: self.builder.property("halign", halign),
185 }
186 }
187
188 pub fn has_default(self, has_default: bool) -> Self {
189 Self {
190 builder: self.builder.property("has-default", has_default),
191 }
192 }
193
194 pub fn has_focus(self, has_focus: bool) -> Self {
195 Self {
196 builder: self.builder.property("has-focus", has_focus),
197 }
198 }
199
200 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
201 Self {
202 builder: self.builder.property("has-tooltip", has_tooltip),
203 }
204 }
205
206 pub fn height_request(self, height_request: i32) -> Self {
207 Self {
208 builder: self.builder.property("height-request", height_request),
209 }
210 }
211
212 pub fn hexpand(self, hexpand: bool) -> Self {
213 Self {
214 builder: self.builder.property("hexpand", hexpand),
215 }
216 }
217
218 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
219 Self {
220 builder: self.builder.property("hexpand-set", hexpand_set),
221 }
222 }
223
224 pub fn is_focus(self, is_focus: bool) -> Self {
225 Self {
226 builder: self.builder.property("is-focus", is_focus),
227 }
228 }
229
230 pub fn margin(self, margin: i32) -> Self {
231 Self {
232 builder: self.builder.property("margin", margin),
233 }
234 }
235
236 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
237 Self {
238 builder: self.builder.property("margin-bottom", margin_bottom),
239 }
240 }
241
242 pub fn margin_end(self, margin_end: i32) -> Self {
243 Self {
244 builder: self.builder.property("margin-end", margin_end),
245 }
246 }
247
248 pub fn margin_start(self, margin_start: i32) -> Self {
249 Self {
250 builder: self.builder.property("margin-start", margin_start),
251 }
252 }
253
254 pub fn margin_top(self, margin_top: i32) -> Self {
255 Self {
256 builder: self.builder.property("margin-top", margin_top),
257 }
258 }
259
260 pub fn name(self, name: &str) -> Self {
261 Self {
262 builder: self.builder.property("name", name),
263 }
264 }
265
266 pub fn no_show_all(self, no_show_all: bool) -> Self {
267 Self {
268 builder: self.builder.property("no-show-all", no_show_all),
269 }
270 }
271
272 pub fn opacity(self, opacity: f64) -> Self {
273 Self {
274 builder: self.builder.property("opacity", opacity),
275 }
276 }
277
278 pub fn parent<P: IsA<Container>>(self, parent: &P) -> Self {
279 Self {
280 builder: self.builder.property("parent", parent),
281 }
282 }
283
284 pub fn receives_default(self, receives_default: bool) -> Self {
285 Self {
286 builder: self.builder.property("receives-default", receives_default),
287 }
288 }
289
290 pub fn sensitive(self, sensitive: bool) -> Self {
291 Self {
292 builder: self.builder.property("sensitive", sensitive),
293 }
294 }
295
296 pub fn tooltip_markup(self, tooltip_markup: &str) -> Self {
297 Self {
298 builder: self.builder.property("tooltip-markup", tooltip_markup),
299 }
300 }
301
302 pub fn tooltip_text(self, tooltip_text: &str) -> Self {
303 Self {
304 builder: self.builder.property("tooltip-text", tooltip_text),
305 }
306 }
307
308 pub fn valign(self, valign: Align) -> Self {
309 Self {
310 builder: self.builder.property("valign", valign),
311 }
312 }
313
314 pub fn vexpand(self, vexpand: bool) -> Self {
315 Self {
316 builder: self.builder.property("vexpand", vexpand),
317 }
318 }
319
320 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
321 Self {
322 builder: self.builder.property("vexpandset", vexpand_set),
323 }
324 }
325
326 pub fn visible(self, visible: bool) -> Self {
327 Self {
328 builder: self.builder.property("visible", visible),
329 }
330 }
331
332 pub fn width_request(self, width_request: i32) -> Self {
333 Self {
334 builder: self.builder.property("width-request", width_request),
335 }
336 }
337
338 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
341 pub fn build(self) -> Image {
342 self.builder.build()
343 }
344}