Skip to main content

libshumate/auto/
symbol_event.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, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// An object containing the details of a map feature that has been clicked.
16    /// It is the argument of the [`symbol-clicked`][struct@crate::MapLayer#symbol-clicked] and
17    /// [`symbol-clicked`][struct@crate::SimpleMap#symbol-clicked] signals.
18    ///
19    /// When vector maps are rendered, they may contain labels and icons. When one
20    /// of these symbols is clicked, these signals are emitted to give the
21    /// application access to the original location and details of the map feature.
22    ///
23    /// [`SymbolEvent`][crate::SymbolEvent] implements [`Location`][crate::Location] so you can get the latitude
24    /// and longitude of the feature that was clicked.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `feature-id`
30    ///  The ID of the feature that this event pertains to, as it was given in the
31    /// data source.
32    ///
33    /// Readable
34    ///
35    ///
36    /// #### `layer`
37    ///  The ID of the style layer of the symbol that this event pertains to.
38    ///
39    /// Readable
40    ///
41    ///
42    /// #### `n-press`
43    ///  The number of clicks/presses triggering the symbol event.
44    ///
45    /// Readable | Writeable
46    ///
47    ///
48    /// #### `source-layer`
49    ///  The ID of the source layer of the symbol that this event pertains to.
50    ///
51    /// Readable
52    /// <details><summary><h4>Location</h4></summary>
53    ///
54    ///
55    /// #### `latitude`
56    ///  The latitude coordonate in degrees
57    ///
58    /// Readable | Writeable
59    ///
60    ///
61    /// #### `longitude`
62    ///  The longitude coordonate in degrees
63    ///
64    /// Readable | Writeable
65    /// </details>
66    ///
67    /// # Implements
68    ///
69    /// [`trait@glib::ObjectExt`], [`LocationExt`][trait@crate::prelude::LocationExt]
70    #[doc(alias = "ShumateSymbolEvent")]
71    pub struct SymbolEvent(Object<ffi::ShumateSymbolEvent, ffi::ShumateSymbolEventClass>) @implements Location;
72
73    match fn {
74        type_ => || ffi::shumate_symbol_event_get_type(),
75    }
76}
77
78impl SymbolEvent {
79    // rustdoc-stripper-ignore-next
80    /// Creates a new builder-pattern struct instance to construct [`SymbolEvent`] objects.
81    ///
82    /// This method returns an instance of [`SymbolEventBuilder`](crate::builders::SymbolEventBuilder) which can be used to create [`SymbolEvent`] objects.
83    pub fn builder() -> SymbolEventBuilder {
84        SymbolEventBuilder::new()
85    }
86
87    /// Gets the feature ID as specified in the data source. The meaning of the
88    /// ID, if any, is up to the source.
89    ///
90    /// Feature IDs in Mapbox Vector Tile format are integers, but they are
91    /// formatted as a string here for futureproofing.
92    ///
93    /// # Returns
94    ///
95    /// the feature ID
96    #[doc(alias = "shumate_symbol_event_get_feature_id")]
97    #[doc(alias = "get_feature_id")]
98    #[doc(alias = "feature-id")]
99    pub fn feature_id(&self) -> Option<glib::GString> {
100        unsafe {
101            from_glib_none(ffi::shumate_symbol_event_get_feature_id(
102                self.to_glib_none().0,
103            ))
104        }
105    }
106
107    /// Gets the name of the layer the clicked symbol is in, as named in the vector
108    /// stylesheet.
109    ///
110    /// Note that this is distinct from the name of the layer in the vector tile
111    /// schema. Some styles have multiple symbol layers derived from the same
112    /// data source layer.
113    ///
114    /// # Returns
115    ///
116    /// the layer name
117    #[doc(alias = "shumate_symbol_event_get_layer")]
118    #[doc(alias = "get_layer")]
119    pub fn layer(&self) -> Option<glib::GString> {
120        unsafe { from_glib_none(ffi::shumate_symbol_event_get_layer(self.to_glib_none().0)) }
121    }
122
123    /// Gets the number of clicks/presses that initiated the event.
124    ///
125    /// # Returns
126    ///
127    /// the number of presses
128    #[cfg(feature = "v1_5")]
129    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
130    #[doc(alias = "shumate_symbol_event_get_n_press")]
131    #[doc(alias = "get_n_press")]
132    #[doc(alias = "n-press")]
133    pub fn n_press(&self) -> i32 {
134        unsafe { ffi::shumate_symbol_event_get_n_press(self.to_glib_none().0) }
135    }
136
137    /// Gets the name of the source layer the clicked feature is in,
138    /// as named in the vector tile schema.
139    ///
140    /// # Returns
141    ///
142    /// the layer name
143    #[doc(alias = "shumate_symbol_event_get_source_layer")]
144    #[doc(alias = "get_source_layer")]
145    #[doc(alias = "source-layer")]
146    pub fn source_layer(&self) -> Option<glib::GString> {
147        unsafe {
148            from_glib_none(ffi::shumate_symbol_event_get_source_layer(
149                self.to_glib_none().0,
150            ))
151        }
152    }
153
154    /// Gets a tag from the source feature.
155    ///
156    /// The available tags depend on the vector tile schema and the source layer.
157    /// Check the documentation for the tiles you're using to see what information
158    /// is available.
159    /// ## `tag_name`
160    /// the tag to get
161    ///
162    /// # Returns
163    ///
164    /// the tag value, formatted as a string
165    #[doc(alias = "shumate_symbol_event_get_tag")]
166    #[doc(alias = "get_tag")]
167    pub fn tag(&self, tag_name: &str) -> Option<glib::GString> {
168        unsafe {
169            from_glib_none(ffi::shumate_symbol_event_get_tag(
170                self.to_glib_none().0,
171                tag_name.to_glib_none().0,
172            ))
173        }
174    }
175
176    /// The number of clicks/presses triggering the symbol event.
177    #[cfg(feature = "v1_5")]
178    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
179    #[doc(alias = "n-press")]
180    pub fn set_n_press(&self, n_press: u32) {
181        ObjectExt::set_property(self, "n-press", n_press)
182    }
183
184    #[cfg(not(feature = "v1_1"))]
185    #[cfg_attr(docsrs, doc(cfg(not(feature = "v1_1"))))]
186    #[doc(alias = "source-layer")]
187    pub fn source_layer(&self) -> Option<glib::GString> {
188        ObjectExt::property(self, "source-layer")
189    }
190
191    #[cfg(feature = "v1_1")]
192    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
193    #[doc(alias = "feature-id")]
194    pub fn connect_feature_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
195        unsafe extern "C" fn notify_feature_id_trampoline<F: Fn(&SymbolEvent) + 'static>(
196            this: *mut ffi::ShumateSymbolEvent,
197            _param_spec: glib::ffi::gpointer,
198            f: glib::ffi::gpointer,
199        ) {
200            unsafe {
201                let f: &F = &*(f as *const F);
202                f(&from_glib_borrow(this))
203            }
204        }
205        unsafe {
206            let f: Box_<F> = Box_::new(f);
207            connect_raw(
208                self.as_ptr() as *mut _,
209                c"notify::feature-id".as_ptr(),
210                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
211                    notify_feature_id_trampoline::<F> as *const (),
212                )),
213                Box_::into_raw(f),
214            )
215        }
216    }
217
218    #[cfg(feature = "v1_1")]
219    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
220    #[doc(alias = "layer")]
221    pub fn connect_layer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
222        unsafe extern "C" fn notify_layer_trampoline<F: Fn(&SymbolEvent) + 'static>(
223            this: *mut ffi::ShumateSymbolEvent,
224            _param_spec: glib::ffi::gpointer,
225            f: glib::ffi::gpointer,
226        ) {
227            unsafe {
228                let f: &F = &*(f as *const F);
229                f(&from_glib_borrow(this))
230            }
231        }
232        unsafe {
233            let f: Box_<F> = Box_::new(f);
234            connect_raw(
235                self.as_ptr() as *mut _,
236                c"notify::layer".as_ptr(),
237                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
238                    notify_layer_trampoline::<F> as *const (),
239                )),
240                Box_::into_raw(f),
241            )
242        }
243    }
244
245    #[cfg(feature = "v1_5")]
246    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
247    #[doc(alias = "n-press")]
248    pub fn connect_n_press_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
249        unsafe extern "C" fn notify_n_press_trampoline<F: Fn(&SymbolEvent) + 'static>(
250            this: *mut ffi::ShumateSymbolEvent,
251            _param_spec: glib::ffi::gpointer,
252            f: glib::ffi::gpointer,
253        ) {
254            unsafe {
255                let f: &F = &*(f as *const F);
256                f(&from_glib_borrow(this))
257            }
258        }
259        unsafe {
260            let f: Box_<F> = Box_::new(f);
261            connect_raw(
262                self.as_ptr() as *mut _,
263                c"notify::n-press".as_ptr(),
264                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
265                    notify_n_press_trampoline::<F> as *const (),
266                )),
267                Box_::into_raw(f),
268            )
269        }
270    }
271
272    #[doc(alias = "source-layer")]
273    pub fn connect_source_layer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
274        unsafe extern "C" fn notify_source_layer_trampoline<F: Fn(&SymbolEvent) + 'static>(
275            this: *mut ffi::ShumateSymbolEvent,
276            _param_spec: glib::ffi::gpointer,
277            f: glib::ffi::gpointer,
278        ) {
279            unsafe {
280                let f: &F = &*(f as *const F);
281                f(&from_glib_borrow(this))
282            }
283        }
284        unsafe {
285            let f: Box_<F> = Box_::new(f);
286            connect_raw(
287                self.as_ptr() as *mut _,
288                c"notify::source-layer".as_ptr(),
289                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290                    notify_source_layer_trampoline::<F> as *const (),
291                )),
292                Box_::into_raw(f),
293            )
294        }
295    }
296}
297
298// rustdoc-stripper-ignore-next
299/// A [builder-pattern] type to construct [`SymbolEvent`] objects.
300///
301/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
302#[must_use = "The builder must be built to be used"]
303pub struct SymbolEventBuilder {
304    builder: glib::object::ObjectBuilder<'static, SymbolEvent>,
305}
306
307impl SymbolEventBuilder {
308    fn new() -> Self {
309        Self {
310            builder: glib::object::Object::builder(),
311        }
312    }
313
314    /// The number of clicks/presses triggering the symbol event.
315    #[cfg(feature = "v1_5")]
316    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
317    pub fn n_press(self, n_press: u32) -> Self {
318        Self {
319            builder: self.builder.property("n-press", n_press),
320        }
321    }
322
323    /// The latitude coordonate in degrees
324    pub fn latitude(self, latitude: f64) -> Self {
325        Self {
326            builder: self.builder.property("latitude", latitude),
327        }
328    }
329
330    /// The longitude coordonate in degrees
331    pub fn longitude(self, longitude: f64) -> Self {
332        Self {
333            builder: self.builder.property("longitude", longitude),
334        }
335    }
336
337    // rustdoc-stripper-ignore-next
338    /// Build the [`SymbolEvent`].
339    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
340    pub fn build(self) -> SymbolEvent {
341        assert_initialized_main_thread!();
342        self.builder.build()
343    }
344}