Skip to main content

libshumate/auto/
viewport.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{Location, MapSource, ffi};
7#[cfg(feature = "v1_6")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
9use glib::object::ObjectType as _;
10use glib::{
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// The object holding the coordinate, zoom-level, and rotation state of the current view.
19    ///
20    /// As the object implements [`Location`][crate::Location], the latitude and longitude are
21    /// accessible via the interface methods.
22    ///
23    /// ## Properties
24    ///
25    ///
26    /// #### `max-zoom-level`
27    ///  The highest allowed level of zoom of the content.
28    ///
29    /// Readable | Writeable
30    ///
31    ///
32    /// #### `min-zoom-level`
33    ///  The lowest allowed level of zoom of the content.
34    ///
35    /// Readable | Writeable
36    ///
37    ///
38    /// #### `reference-map-source`
39    ///  The reference #ShumateMapSource being displayed
40    ///
41    /// Readable | Writeable
42    ///
43    ///
44    /// #### `rotation`
45    ///  The rotation of the map view, in radians clockwise from up being due north
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `zoom-level`
51    ///  The level of zoom of the content.
52    ///
53    /// Readable | Writeable
54    /// <details><summary><h4>Location</h4></summary>
55    ///
56    ///
57    /// #### `latitude`
58    ///  The latitude coordonate in degrees
59    ///
60    /// Readable | Writeable
61    ///
62    ///
63    /// #### `longitude`
64    ///  The longitude coordonate in degrees
65    ///
66    /// Readable | Writeable
67    /// </details>
68    ///
69    /// ## Signals
70    ///
71    ///
72    /// #### `changed`
73    ///  Emitted when the viewport position (location, zoom, rotation, etc.) changes. Changes to multiple properties at once
74    /// may be combined into a single signal emission.
75    ///
76    ///
77    ///
78    /// # Implements
79    ///
80    /// [`trait@glib::ObjectExt`], [`LocationExt`][trait@crate::prelude::LocationExt]
81    #[doc(alias = "ShumateViewport")]
82    pub struct Viewport(Object<ffi::ShumateViewport, ffi::ShumateViewportClass>) @implements Location;
83
84    match fn {
85        type_ => || ffi::shumate_viewport_get_type(),
86    }
87}
88
89impl Viewport {
90    /// Creates a new #ShumateViewport
91    ///
92    /// # Returns
93    ///
94    /// A new #ShumateViewport
95    #[doc(alias = "shumate_viewport_new")]
96    pub fn new() -> Viewport {
97        assert_initialized_main_thread!();
98        unsafe { from_glib_full(ffi::shumate_viewport_new()) }
99    }
100
101    // rustdoc-stripper-ignore-next
102    /// Creates a new builder-pattern struct instance to construct [`Viewport`] objects.
103    ///
104    /// This method returns an instance of [`ViewportBuilder`](crate::builders::ViewportBuilder) which can be used to create [`Viewport`] objects.
105    pub fn builder() -> ViewportBuilder {
106        ViewportBuilder::new()
107    }
108
109    /// Get the maximal zoom level
110    ///
111    /// # Returns
112    ///
113    /// the maximal zoom level
114    #[doc(alias = "shumate_viewport_get_max_zoom_level")]
115    #[doc(alias = "get_max_zoom_level")]
116    #[doc(alias = "max-zoom-level")]
117    pub fn max_zoom_level(&self) -> u32 {
118        unsafe { ffi::shumate_viewport_get_max_zoom_level(self.to_glib_none().0) }
119    }
120
121    /// Get the minimal zoom level
122    ///
123    /// # Returns
124    ///
125    /// the minimal zoom level
126    #[doc(alias = "shumate_viewport_get_min_zoom_level")]
127    #[doc(alias = "get_min_zoom_level")]
128    #[doc(alias = "min-zoom-level")]
129    pub fn min_zoom_level(&self) -> u32 {
130        unsafe { ffi::shumate_viewport_get_min_zoom_level(self.to_glib_none().0) }
131    }
132
133    /// Get the reference map source
134    ///
135    /// # Returns
136    ///
137    /// the reference #ShumateMapSource or [`None`]
138    /// when none has been set.
139    #[doc(alias = "shumate_viewport_get_reference_map_source")]
140    #[doc(alias = "get_reference_map_source")]
141    #[doc(alias = "reference-map-source")]
142    pub fn reference_map_source(&self) -> Option<MapSource> {
143        unsafe {
144            from_glib_none(ffi::shumate_viewport_get_reference_map_source(
145                self.to_glib_none().0,
146            ))
147        }
148    }
149
150    /// Gets the current rotation
151    ///
152    /// # Returns
153    ///
154    /// the current rotation
155    #[doc(alias = "shumate_viewport_get_rotation")]
156    #[doc(alias = "get_rotation")]
157    pub fn rotation(&self) -> f64 {
158        unsafe { ffi::shumate_viewport_get_rotation(self.to_glib_none().0) }
159    }
160
161    /// Get the current zoom level
162    ///
163    /// # Returns
164    ///
165    /// the current zoom level
166    #[doc(alias = "shumate_viewport_get_zoom_level")]
167    #[doc(alias = "get_zoom_level")]
168    #[doc(alias = "zoom-level")]
169    pub fn zoom_level(&self) -> f64 {
170        unsafe { ffi::shumate_viewport_get_zoom_level(self.to_glib_none().0) }
171    }
172
173    /// Gets the position on @widget that correspond to the given latitude and
174    /// longitude.
175    /// ## `widget`
176    /// a #GtkWidget that uses @self as viewport
177    /// ## `latitude`
178    /// the latitude
179    /// ## `longitude`
180    /// the longitude
181    ///
182    /// # Returns
183    ///
184    ///
185    /// ## `x`
186    /// return value for the x coordinate
187    ///
188    /// ## `y`
189    /// return value for the y coordinate
190    #[doc(alias = "shumate_viewport_location_to_widget_coords")]
191    pub fn location_to_widget_coords(
192        &self,
193        widget: &impl IsA<gtk::Widget>,
194        latitude: f64,
195        longitude: f64,
196    ) -> (f64, f64) {
197        unsafe {
198            let mut x = std::mem::MaybeUninit::uninit();
199            let mut y = std::mem::MaybeUninit::uninit();
200            ffi::shumate_viewport_location_to_widget_coords(
201                self.to_glib_none().0,
202                widget.as_ref().to_glib_none().0,
203                latitude,
204                longitude,
205                x.as_mut_ptr(),
206                y.as_mut_ptr(),
207            );
208            (x.assume_init(), y.assume_init())
209        }
210    }
211
212    /// Set the maximal zoom level
213    /// ## `max_zoom_level`
214    /// the maximal zoom level
215    #[doc(alias = "shumate_viewport_set_max_zoom_level")]
216    #[doc(alias = "max-zoom-level")]
217    pub fn set_max_zoom_level(&self, max_zoom_level: u32) {
218        unsafe {
219            ffi::shumate_viewport_set_max_zoom_level(self.to_glib_none().0, max_zoom_level);
220        }
221    }
222
223    /// Set the minimal zoom level
224    /// ## `min_zoom_level`
225    /// the minimal zoom level
226    #[doc(alias = "shumate_viewport_set_min_zoom_level")]
227    #[doc(alias = "min-zoom-level")]
228    pub fn set_min_zoom_level(&self, min_zoom_level: u32) {
229        unsafe {
230            ffi::shumate_viewport_set_min_zoom_level(self.to_glib_none().0, min_zoom_level);
231        }
232    }
233
234    /// Set the reference map source
235    /// ## `map_source`
236    /// a #ShumateMapSource or [`None`] to set none.
237    #[doc(alias = "shumate_viewport_set_reference_map_source")]
238    #[doc(alias = "reference-map-source")]
239    pub fn set_reference_map_source(&self, map_source: Option<&impl IsA<MapSource>>) {
240        unsafe {
241            ffi::shumate_viewport_set_reference_map_source(
242                self.to_glib_none().0,
243                map_source.map(|p| p.as_ref()).to_glib_none().0,
244            );
245        }
246    }
247
248    /// Sets the rotation
249    /// ## `rotation`
250    /// the rotation
251    #[doc(alias = "shumate_viewport_set_rotation")]
252    #[doc(alias = "rotation")]
253    pub fn set_rotation(&self, rotation: f64) {
254        unsafe {
255            ffi::shumate_viewport_set_rotation(self.to_glib_none().0, rotation);
256        }
257    }
258
259    /// Set the zoom level
260    /// ## `zoom_level`
261    /// the zoom level
262    #[doc(alias = "shumate_viewport_set_zoom_level")]
263    #[doc(alias = "zoom-level")]
264    pub fn set_zoom_level(&self, zoom_level: f64) {
265        unsafe {
266            ffi::shumate_viewport_set_zoom_level(self.to_glib_none().0, zoom_level);
267        }
268    }
269
270    /// Gets the latitude and longitude corresponding to a position on @widget.
271    /// ## `widget`
272    /// a #GtkWidget that uses @self as viewport
273    /// ## `x`
274    /// the x coordinate
275    /// ## `y`
276    /// the y coordinate
277    ///
278    /// # Returns
279    ///
280    ///
281    /// ## `latitude`
282    /// return location for the latitude
283    ///
284    /// ## `longitude`
285    /// return location for the longitude
286    #[doc(alias = "shumate_viewport_widget_coords_to_location")]
287    pub fn widget_coords_to_location(
288        &self,
289        widget: &impl IsA<gtk::Widget>,
290        x: f64,
291        y: f64,
292    ) -> (f64, f64) {
293        unsafe {
294            let mut latitude = std::mem::MaybeUninit::uninit();
295            let mut longitude = std::mem::MaybeUninit::uninit();
296            ffi::shumate_viewport_widget_coords_to_location(
297                self.to_glib_none().0,
298                widget.as_ref().to_glib_none().0,
299                x,
300                y,
301                latitude.as_mut_ptr(),
302                longitude.as_mut_ptr(),
303            );
304            (latitude.assume_init(), longitude.assume_init())
305        }
306    }
307
308    /// Emitted when the viewport position (location, zoom, rotation, etc.) changes. Changes to multiple properties at once
309    /// may be combined into a single signal emission.
310    #[cfg(feature = "v1_6")]
311    #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
312    #[doc(alias = "changed")]
313    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
314        unsafe extern "C" fn changed_trampoline<F: Fn(&Viewport) + 'static>(
315            this: *mut ffi::ShumateViewport,
316            f: glib::ffi::gpointer,
317        ) {
318            unsafe {
319                let f: &F = &*(f as *const F);
320                f(&from_glib_borrow(this))
321            }
322        }
323        unsafe {
324            let f: Box_<F> = Box_::new(f);
325            connect_raw(
326                self.as_ptr() as *mut _,
327                c"changed".as_ptr(),
328                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
329                    changed_trampoline::<F> as *const (),
330                )),
331                Box_::into_raw(f),
332            )
333        }
334    }
335
336    #[doc(alias = "max-zoom-level")]
337    pub fn connect_max_zoom_level_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
338        unsafe extern "C" fn notify_max_zoom_level_trampoline<F: Fn(&Viewport) + 'static>(
339            this: *mut ffi::ShumateViewport,
340            _param_spec: glib::ffi::gpointer,
341            f: glib::ffi::gpointer,
342        ) {
343            unsafe {
344                let f: &F = &*(f as *const F);
345                f(&from_glib_borrow(this))
346            }
347        }
348        unsafe {
349            let f: Box_<F> = Box_::new(f);
350            connect_raw(
351                self.as_ptr() as *mut _,
352                c"notify::max-zoom-level".as_ptr(),
353                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
354                    notify_max_zoom_level_trampoline::<F> as *const (),
355                )),
356                Box_::into_raw(f),
357            )
358        }
359    }
360
361    #[doc(alias = "min-zoom-level")]
362    pub fn connect_min_zoom_level_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
363        unsafe extern "C" fn notify_min_zoom_level_trampoline<F: Fn(&Viewport) + 'static>(
364            this: *mut ffi::ShumateViewport,
365            _param_spec: glib::ffi::gpointer,
366            f: glib::ffi::gpointer,
367        ) {
368            unsafe {
369                let f: &F = &*(f as *const F);
370                f(&from_glib_borrow(this))
371            }
372        }
373        unsafe {
374            let f: Box_<F> = Box_::new(f);
375            connect_raw(
376                self.as_ptr() as *mut _,
377                c"notify::min-zoom-level".as_ptr(),
378                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
379                    notify_min_zoom_level_trampoline::<F> as *const (),
380                )),
381                Box_::into_raw(f),
382            )
383        }
384    }
385
386    #[doc(alias = "reference-map-source")]
387    pub fn connect_reference_map_source_notify<F: Fn(&Self) + 'static>(
388        &self,
389        f: F,
390    ) -> SignalHandlerId {
391        unsafe extern "C" fn notify_reference_map_source_trampoline<F: Fn(&Viewport) + 'static>(
392            this: *mut ffi::ShumateViewport,
393            _param_spec: glib::ffi::gpointer,
394            f: glib::ffi::gpointer,
395        ) {
396            unsafe {
397                let f: &F = &*(f as *const F);
398                f(&from_glib_borrow(this))
399            }
400        }
401        unsafe {
402            let f: Box_<F> = Box_::new(f);
403            connect_raw(
404                self.as_ptr() as *mut _,
405                c"notify::reference-map-source".as_ptr(),
406                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
407                    notify_reference_map_source_trampoline::<F> as *const (),
408                )),
409                Box_::into_raw(f),
410            )
411        }
412    }
413
414    #[doc(alias = "rotation")]
415    pub fn connect_rotation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
416        unsafe extern "C" fn notify_rotation_trampoline<F: Fn(&Viewport) + 'static>(
417            this: *mut ffi::ShumateViewport,
418            _param_spec: glib::ffi::gpointer,
419            f: glib::ffi::gpointer,
420        ) {
421            unsafe {
422                let f: &F = &*(f as *const F);
423                f(&from_glib_borrow(this))
424            }
425        }
426        unsafe {
427            let f: Box_<F> = Box_::new(f);
428            connect_raw(
429                self.as_ptr() as *mut _,
430                c"notify::rotation".as_ptr(),
431                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
432                    notify_rotation_trampoline::<F> as *const (),
433                )),
434                Box_::into_raw(f),
435            )
436        }
437    }
438
439    #[doc(alias = "zoom-level")]
440    pub fn connect_zoom_level_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
441        unsafe extern "C" fn notify_zoom_level_trampoline<F: Fn(&Viewport) + 'static>(
442            this: *mut ffi::ShumateViewport,
443            _param_spec: glib::ffi::gpointer,
444            f: glib::ffi::gpointer,
445        ) {
446            unsafe {
447                let f: &F = &*(f as *const F);
448                f(&from_glib_borrow(this))
449            }
450        }
451        unsafe {
452            let f: Box_<F> = Box_::new(f);
453            connect_raw(
454                self.as_ptr() as *mut _,
455                c"notify::zoom-level".as_ptr(),
456                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
457                    notify_zoom_level_trampoline::<F> as *const (),
458                )),
459                Box_::into_raw(f),
460            )
461        }
462    }
463}
464
465impl Default for Viewport {
466    fn default() -> Self {
467        Self::new()
468    }
469}
470
471// rustdoc-stripper-ignore-next
472/// A [builder-pattern] type to construct [`Viewport`] objects.
473///
474/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
475#[must_use = "The builder must be built to be used"]
476pub struct ViewportBuilder {
477    builder: glib::object::ObjectBuilder<'static, Viewport>,
478}
479
480impl ViewportBuilder {
481    fn new() -> Self {
482        Self {
483            builder: glib::object::Object::builder(),
484        }
485    }
486
487    /// The highest allowed level of zoom of the content.
488    pub fn max_zoom_level(self, max_zoom_level: u32) -> Self {
489        Self {
490            builder: self.builder.property("max-zoom-level", max_zoom_level),
491        }
492    }
493
494    /// The lowest allowed level of zoom of the content.
495    pub fn min_zoom_level(self, min_zoom_level: u32) -> Self {
496        Self {
497            builder: self.builder.property("min-zoom-level", min_zoom_level),
498        }
499    }
500
501    /// The reference #ShumateMapSource being displayed
502    pub fn reference_map_source(self, reference_map_source: &impl IsA<MapSource>) -> Self {
503        Self {
504            builder: self.builder.property(
505                "reference-map-source",
506                reference_map_source.clone().upcast(),
507            ),
508        }
509    }
510
511    /// The rotation of the map view, in radians clockwise from up being due north
512    pub fn rotation(self, rotation: f64) -> Self {
513        Self {
514            builder: self.builder.property("rotation", rotation),
515        }
516    }
517
518    /// The level of zoom of the content.
519    pub fn zoom_level(self, zoom_level: f64) -> Self {
520        Self {
521            builder: self.builder.property("zoom-level", zoom_level),
522        }
523    }
524
525    /// The latitude coordonate in degrees
526    pub fn latitude(self, latitude: f64) -> Self {
527        Self {
528            builder: self.builder.property("latitude", latitude),
529        }
530    }
531
532    /// The longitude coordonate in degrees
533    pub fn longitude(self, longitude: f64) -> Self {
534        Self {
535            builder: self.builder.property("longitude", longitude),
536        }
537    }
538
539    // rustdoc-stripper-ignore-next
540    /// Build the [`Viewport`].
541    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
542    pub fn build(self) -> Viewport {
543        assert_initialized_main_thread!();
544        self.builder.build()
545    }
546}