gsk4/auto/path_measure.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi, Path, PathPoint};
use glib::translate::*;
glib::wrapper! {
/// [`PathMeasure`][crate::PathMeasure] is an object that allows measurements
/// on [`Path`][crate::Path]s such as determining the length of the path.
///
/// Many measuring operations require sampling the path length
/// at intermediate points. Therefore, a [`PathMeasure`][crate::PathMeasure] has
/// a tolerance that determines what precision is required
/// for such approximations.
///
/// A [`PathMeasure`][crate::PathMeasure] struct is a reference counted struct
/// and should be treated as opaque.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PathMeasure(Shared<ffi::GskPathMeasure>);
match fn {
ref => |ptr| ffi::gsk_path_measure_ref(ptr),
unref => |ptr| ffi::gsk_path_measure_unref(ptr),
type_ => || ffi::gsk_path_measure_get_type(),
}
}
impl PathMeasure {
/// Creates a measure object for the given @path with the
/// default tolerance.
/// ## `path`
/// the path to measure
///
/// # Returns
///
/// a new [`PathMeasure`][crate::PathMeasure] representing @path
#[doc(alias = "gsk_path_measure_new")]
pub fn new(path: &Path) -> PathMeasure {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gsk_path_measure_new(path.to_glib_none().0)) }
}
/// Creates a measure object for the given @path and @tolerance.
/// ## `path`
/// the path to measure
/// ## `tolerance`
/// the tolerance for measuring operations
///
/// # Returns
///
/// a new [`PathMeasure`][crate::PathMeasure] representing @path
#[doc(alias = "gsk_path_measure_new_with_tolerance")]
#[doc(alias = "new_with_tolerance")]
pub fn with_tolerance(path: &Path, tolerance: f32) -> PathMeasure {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gsk_path_measure_new_with_tolerance(
path.to_glib_none().0,
tolerance,
))
}
}
/// Gets the length of the path being measured.
///
/// The length is cached, so this function does not do any work.
///
/// # Returns
///
/// The length of the path measured by @self
#[doc(alias = "gsk_path_measure_get_length")]
#[doc(alias = "get_length")]
pub fn length(&self) -> f32 {
unsafe { ffi::gsk_path_measure_get_length(self.to_glib_none().0) }
}
/// Returns the path that the measure was created for.
///
/// # Returns
///
/// the path of @self
#[doc(alias = "gsk_path_measure_get_path")]
#[doc(alias = "get_path")]
pub fn path(&self) -> Path {
unsafe { from_glib_none(ffi::gsk_path_measure_get_path(self.to_glib_none().0)) }
}
/// Sets @result to the point at the given distance into the path.
///
/// An empty path has no points, so `FALSE` is returned in that case.
/// ## `distance`
/// the distance
///
/// # Returns
///
/// `TRUE` if @result was set
///
/// ## `result`
/// return location for the result
#[doc(alias = "gsk_path_measure_get_point")]
#[doc(alias = "get_point")]
pub fn point(&self, distance: f32) -> Option<PathPoint> {
unsafe {
let mut result = PathPoint::uninitialized();
let ret = from_glib(ffi::gsk_path_measure_get_point(
self.to_glib_none().0,
distance,
result.to_glib_none_mut().0,
));
if ret {
Some(result)
} else {
None
}
}
}
/// Returns the tolerance that the measure was created with.
///
/// # Returns
///
/// the tolerance of @self
#[doc(alias = "gsk_path_measure_get_tolerance")]
#[doc(alias = "get_tolerance")]
pub fn tolerance(&self) -> f32 {
unsafe { ffi::gsk_path_measure_get_tolerance(self.to_glib_none().0) }
}
}