Skip to main content

libshumate/auto/
location.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::ffi;
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// An interface common to objects having latitude and longitude
16    ///
17    /// By implementing #ShumateLocation the object declares that it has latitude
18    /// and longitude and can be used to specify location on the map.
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `latitude`
24    ///  The latitude coordonate in degrees
25    ///
26    /// Readable | Writeable
27    ///
28    ///
29    /// #### `longitude`
30    ///  The longitude coordonate in degrees
31    ///
32    /// Readable | Writeable
33    ///
34    /// # Implements
35    ///
36    /// [`LocationExt`][trait@crate::prelude::LocationExt]
37    #[doc(alias = "ShumateLocation")]
38    pub struct Location(Interface<ffi::ShumateLocation, ffi::ShumateLocationInterface>);
39
40    match fn {
41        type_ => || ffi::shumate_location_get_type(),
42    }
43}
44
45impl Location {
46    pub const NONE: Option<&'static Location> = None;
47}
48
49/// Trait containing all [`struct@Location`] methods.
50///
51/// # Implementors
52///
53/// [`Coordinate`][struct@crate::Coordinate], [`Location`][struct@crate::Location], [`Marker`][struct@crate::Marker], [`Point`][struct@crate::Point], [`SymbolEvent`][struct@crate::SymbolEvent], [`Viewport`][struct@crate::Viewport]
54pub trait LocationExt: IsA<Location> + 'static {
55    /// Calculates the distance in meters between two locations.
56    ///
57    /// This function uses the great-circle distance formula, which assumes
58    /// Earth is a perfect sphere. This limits the accuracy of the result,
59    /// but is good enough for most purposes.
60    /// ## `other`
61    /// a [`Location`][crate::Location]
62    ///
63    /// # Returns
64    ///
65    /// the distance in meters between @self and @other
66    #[cfg(feature = "v1_2")]
67    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
68    #[doc(alias = "shumate_location_distance")]
69    fn distance(&self, other: &impl IsA<Location>) -> f64 {
70        unsafe {
71            ffi::shumate_location_distance(
72                self.as_ref().to_glib_none().0,
73                other.as_ref().to_glib_none().0,
74            )
75        }
76    }
77
78    /// Gets the latitude coordinate in degrees.
79    ///
80    /// # Returns
81    ///
82    /// the latitude coordinate in degrees.
83    #[doc(alias = "shumate_location_get_latitude")]
84    #[doc(alias = "get_latitude")]
85    fn latitude(&self) -> f64 {
86        unsafe { ffi::shumate_location_get_latitude(self.as_ref().to_glib_none().0) }
87    }
88
89    /// Gets the longitude coordinate in degrees.
90    ///
91    /// # Returns
92    ///
93    /// the longitude coordinate in degrees.
94    #[doc(alias = "shumate_location_get_longitude")]
95    #[doc(alias = "get_longitude")]
96    fn longitude(&self) -> f64 {
97        unsafe { ffi::shumate_location_get_longitude(self.as_ref().to_glib_none().0) }
98    }
99
100    /// Sets the coordinates of the location
101    /// ## `latitude`
102    /// the latitude in degrees
103    /// ## `longitude`
104    /// the longitude in degrees
105    #[doc(alias = "shumate_location_set_location")]
106    fn set_location(&self, latitude: f64, longitude: f64) {
107        unsafe {
108            ffi::shumate_location_set_location(self.as_ref().to_glib_none().0, latitude, longitude);
109        }
110    }
111
112    /// The latitude coordonate in degrees
113    fn set_latitude(&self, latitude: f64) {
114        ObjectExt::set_property(self.as_ref(), "latitude", latitude)
115    }
116
117    /// The longitude coordonate in degrees
118    fn set_longitude(&self, longitude: f64) {
119        ObjectExt::set_property(self.as_ref(), "longitude", longitude)
120    }
121
122    #[doc(alias = "latitude")]
123    fn connect_latitude_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
124        unsafe extern "C" fn notify_latitude_trampoline<P: IsA<Location>, F: Fn(&P) + 'static>(
125            this: *mut ffi::ShumateLocation,
126            _param_spec: glib::ffi::gpointer,
127            f: glib::ffi::gpointer,
128        ) {
129            unsafe {
130                let f: &F = &*(f as *const F);
131                f(Location::from_glib_borrow(this).unsafe_cast_ref())
132            }
133        }
134        unsafe {
135            let f: Box_<F> = Box_::new(f);
136            connect_raw(
137                self.as_ptr() as *mut _,
138                c"notify::latitude".as_ptr(),
139                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
140                    notify_latitude_trampoline::<Self, F> as *const (),
141                )),
142                Box_::into_raw(f),
143            )
144        }
145    }
146
147    #[doc(alias = "longitude")]
148    fn connect_longitude_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
149        unsafe extern "C" fn notify_longitude_trampoline<P: IsA<Location>, F: Fn(&P) + 'static>(
150            this: *mut ffi::ShumateLocation,
151            _param_spec: glib::ffi::gpointer,
152            f: glib::ffi::gpointer,
153        ) {
154            unsafe {
155                let f: &F = &*(f as *const F);
156                f(Location::from_glib_borrow(this).unsafe_cast_ref())
157            }
158        }
159        unsafe {
160            let f: Box_<F> = Box_::new(f);
161            connect_raw(
162                self.as_ptr() as *mut _,
163                c"notify::longitude".as_ptr(),
164                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165                    notify_longitude_trampoline::<Self, F> as *const (),
166                )),
167                Box_::into_raw(f),
168            )
169        }
170    }
171}
172
173impl<O: IsA<Location>> LocationExt for O {}