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
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::{Expression, NumericSorter};
use glib::translate::*;
impl NumericSorter {
/// Creates a new numeric sorter using the given `expression`.
///
/// Smaller numbers will be sorted first. You can call
/// [``set_sort_order()``][`Self::set_sort_order()`] to change this.
/// ## `expression`
/// The expression to evaluate
///
/// # Returns
///
/// a new [`NumericSorter`][crate::NumericSorter]
#[doc(alias = "gtk_numeric_sorter_new")]
pub fn new<E: AsRef<Expression>>(expression: Option<&E>) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::gtk_numeric_sorter_new(
expression.map(|e| e.as_ref()).to_glib_full(),
))
}
}
/// Sets the expression that is evaluated to obtain numbers from items.
///
/// Unless an expression is set on `self`, the sorter will always
/// compare items as invalid.
///
/// The expression must have a return type that can be compared
/// numerically, such as `G_TYPE_INT` or `G_TYPE_DOUBLE`.
/// ## `expression`
/// a [`Expression`][crate::Expression]
#[doc(alias = "gtk_numeric_sorter_set_expression")]
pub fn set_expression<E: AsRef<Expression>>(&self, expression: Option<&E>) {
unsafe {
ffi::gtk_numeric_sorter_set_expression(
self.to_glib_none().0,
expression.map(|e| e.as_ref()).to_glib_none().0,
);
}
}
}