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
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::{DropDown, Expression, Widget};
use glib::translate::*;
use glib::Cast;
impl DropDown {
/// Creates a new [`DropDown`][crate::DropDown].
///
/// You may want to call [``set_factory()``][`Self::set_factory()`]
/// to set up a way to map its items to widgets.
/// ## `model`
/// the model to use
/// ## `expression`
/// the expression to use
///
/// # Returns
///
/// a new [`DropDown`][crate::DropDown]
#[doc(alias = "gtk_drop_down_new")]
pub fn new<P: glib::IsA<gio::ListModel>, E: AsRef<Expression>>(
model: Option<&P>,
expression: Option<&E>,
) -> Self {
assert_initialized_main_thread!();
unsafe {
Widget::from_glib_none(ffi::gtk_drop_down_new(
model.map(|p| p.as_ref()).to_glib_full(),
expression.map(|e| e.as_ref()).to_glib_full(),
))
.unsafe_cast()
}
}
/// Sets the expression that gets evaluated to obtain strings from items.
///
/// This is used for search in the popup. The expression must have
/// a value type of `G_TYPE_STRING`.
/// ## `expression`
/// a [`Expression`][crate::Expression]
#[doc(alias = "gtk_drop_down_set_expression")]
pub fn set_expression<E: AsRef<Expression>>(&self, expression: Option<&E>) {
unsafe {
ffi::gtk_drop_down_set_expression(
self.to_glib_none().0,
expression.map(|e| e.as_ref()).to_glib_none().0,
);
}
}
}