use crate::{
Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Expression, LayoutManager,
ListItemFactory, Overflow, Widget,
};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};
glib::wrapper! {
#[doc(alias = "GtkDropDown")]
pub struct DropDown(Object<ffi::GtkDropDown, ffi::GtkDropDownClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
match fn {
type_ => || ffi::gtk_drop_down_get_type(),
}
}
impl DropDown {
#[doc(alias = "gtk_drop_down_new")]
pub fn new(
model: Option<impl IsA<gio::ListModel>>,
expression: Option<impl AsRef<Expression>>,
) -> DropDown {
assert_initialized_main_thread!();
unsafe {
Widget::from_glib_none(ffi::gtk_drop_down_new(
model.map(|p| p.upcast()).into_glib_ptr(),
expression
.map(|p| p.as_ref().clone().upcast())
.into_glib_ptr(),
))
.unsafe_cast()
}
}
#[doc(alias = "gtk_drop_down_new_from_strings")]
#[doc(alias = "new_from_strings")]
pub fn from_strings(strings: &[&str]) -> DropDown {
assert_initialized_main_thread!();
unsafe {
Widget::from_glib_none(ffi::gtk_drop_down_new_from_strings(
strings.to_glib_none().0,
))
.unsafe_cast()
}
}
pub fn builder() -> DropDownBuilder {
DropDownBuilder::new()
}
#[doc(alias = "gtk_drop_down_get_enable_search")]
#[doc(alias = "get_enable_search")]
pub fn enables_search(&self) -> bool {
unsafe { from_glib(ffi::gtk_drop_down_get_enable_search(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_drop_down_get_expression")]
#[doc(alias = "get_expression")]
pub fn expression(&self) -> Option<Expression> {
unsafe { from_glib_none(ffi::gtk_drop_down_get_expression(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_drop_down_get_factory")]
#[doc(alias = "get_factory")]
pub fn factory(&self) -> Option<ListItemFactory> {
unsafe { from_glib_none(ffi::gtk_drop_down_get_factory(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_drop_down_get_list_factory")]
#[doc(alias = "get_list_factory")]
pub fn list_factory(&self) -> Option<ListItemFactory> {
unsafe { from_glib_none(ffi::gtk_drop_down_get_list_factory(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_drop_down_get_model")]
#[doc(alias = "get_model")]
pub fn model(&self) -> Option<gio::ListModel> {
unsafe { from_glib_none(ffi::gtk_drop_down_get_model(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_drop_down_get_selected")]
#[doc(alias = "get_selected")]
pub fn selected(&self) -> u32 {
unsafe { ffi::gtk_drop_down_get_selected(self.to_glib_none().0) }
}
#[doc(alias = "gtk_drop_down_get_selected_item")]
#[doc(alias = "get_selected_item")]
pub fn selected_item(&self) -> Option<glib::Object> {
unsafe { from_glib_none(ffi::gtk_drop_down_get_selected_item(self.to_glib_none().0)) }
}
#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
#[doc(alias = "gtk_drop_down_get_show_arrow")]
#[doc(alias = "get_show_arrow")]
pub fn shows_arrow(&self) -> bool {
unsafe { from_glib(ffi::gtk_drop_down_get_show_arrow(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_drop_down_set_enable_search")]
pub fn set_enable_search(&self, enable_search: bool) {
unsafe {
ffi::gtk_drop_down_set_enable_search(self.to_glib_none().0, enable_search.into_glib());
}
}
#[doc(alias = "gtk_drop_down_set_expression")]
pub fn set_expression(&self, expression: Option<impl AsRef<Expression>>) {
unsafe {
ffi::gtk_drop_down_set_expression(
self.to_glib_none().0,
expression.as_ref().map(|p| p.as_ref()).to_glib_none().0,
);
}
}
#[doc(alias = "gtk_drop_down_set_factory")]
pub fn set_factory(&self, factory: Option<&impl IsA<ListItemFactory>>) {
unsafe {
ffi::gtk_drop_down_set_factory(
self.to_glib_none().0,
factory.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
#[doc(alias = "gtk_drop_down_set_list_factory")]
pub fn set_list_factory(&self, factory: Option<&impl IsA<ListItemFactory>>) {
unsafe {
ffi::gtk_drop_down_set_list_factory(
self.to_glib_none().0,
factory.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
#[doc(alias = "gtk_drop_down_set_model")]
pub fn set_model(&self, model: Option<&impl IsA<gio::ListModel>>) {
unsafe {
ffi::gtk_drop_down_set_model(
self.to_glib_none().0,
model.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
#[doc(alias = "gtk_drop_down_set_selected")]
pub fn set_selected(&self, position: u32) {
unsafe {
ffi::gtk_drop_down_set_selected(self.to_glib_none().0, position);
}
}
#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
#[doc(alias = "gtk_drop_down_set_show_arrow")]
pub fn set_show_arrow(&self, show_arrow: bool) {
unsafe {
ffi::gtk_drop_down_set_show_arrow(self.to_glib_none().0, show_arrow.into_glib());
}
}
#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
#[doc(alias = "activate")]
pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn activate_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"activate\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
activate_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
pub fn emit_activate(&self) {
self.emit_by_name::<()>("activate", &[]);
}
#[doc(alias = "enable-search")]
pub fn connect_enable_search_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_enable_search_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::enable-search\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_enable_search_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "expression")]
pub fn connect_expression_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_expression_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::expression\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_expression_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "factory")]
pub fn connect_factory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_factory_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::factory\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_factory_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "list-factory")]
pub fn connect_list_factory_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_list_factory_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::list-factory\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_list_factory_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "model")]
pub fn connect_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_model_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::model\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_model_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "selected")]
pub fn connect_selected_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_selected_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::selected\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_selected_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "selected-item")]
pub fn connect_selected_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_selected_item_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::selected-item\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_selected_item_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
#[doc(alias = "show-arrow")]
pub fn connect_show_arrow_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_show_arrow_trampoline<F: Fn(&DropDown) + 'static>(
this: *mut ffi::GtkDropDown,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::show-arrow\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_show_arrow_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for DropDown {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
#[must_use = "The builder must be built to be used"]
pub struct DropDownBuilder {
builder: glib::object::ObjectBuilder<'static, DropDown>,
}
impl DropDownBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn enable_search(self, enable_search: bool) -> Self {
Self {
builder: self.builder.property("enable-search", enable_search),
}
}
pub fn expression(self, expression: impl AsRef<Expression>) -> Self {
Self {
builder: self
.builder
.property("expression", expression.as_ref().clone()),
}
}
pub fn factory(self, factory: &impl IsA<ListItemFactory>) -> Self {
Self {
builder: self.builder.property("factory", factory.clone().upcast()),
}
}
pub fn list_factory(self, list_factory: &impl IsA<ListItemFactory>) -> Self {
Self {
builder: self
.builder
.property("list-factory", list_factory.clone().upcast()),
}
}
pub fn model(self, model: &impl IsA<gio::ListModel>) -> Self {
Self {
builder: self.builder.property("model", model.clone().upcast()),
}
}
pub fn selected(self, selected: u32) -> Self {
Self {
builder: self.builder.property("selected", selected),
}
}
#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
pub fn show_arrow(self, show_arrow: bool) -> Self {
Self {
builder: self.builder.property("show-arrow", show_arrow),
}
}
pub fn can_focus(self, can_focus: bool) -> Self {
Self {
builder: self.builder.property("can-focus", can_focus),
}
}
pub fn can_target(self, can_target: bool) -> Self {
Self {
builder: self.builder.property("can-target", can_target),
}
}
pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
Self {
builder: self.builder.property("css-classes", css_classes.into()),
}
}
pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("css-name", css_name.into()),
}
}
pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
Self {
builder: self.builder.property("cursor", cursor.clone()),
}
}
pub fn focus_on_click(self, focus_on_click: bool) -> Self {
Self {
builder: self.builder.property("focus-on-click", focus_on_click),
}
}
pub fn focusable(self, focusable: bool) -> Self {
Self {
builder: self.builder.property("focusable", focusable),
}
}
pub fn halign(self, halign: Align) -> Self {
Self {
builder: self.builder.property("halign", halign),
}
}
pub fn has_tooltip(self, has_tooltip: bool) -> Self {
Self {
builder: self.builder.property("has-tooltip", has_tooltip),
}
}
pub fn height_request(self, height_request: i32) -> Self {
Self {
builder: self.builder.property("height-request", height_request),
}
}
pub fn hexpand(self, hexpand: bool) -> Self {
Self {
builder: self.builder.property("hexpand", hexpand),
}
}
pub fn hexpand_set(self, hexpand_set: bool) -> Self {
Self {
builder: self.builder.property("hexpand-set", hexpand_set),
}
}
pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
Self {
builder: self
.builder
.property("layout-manager", layout_manager.clone().upcast()),
}
}
pub fn margin_bottom(self, margin_bottom: i32) -> Self {
Self {
builder: self.builder.property("margin-bottom", margin_bottom),
}
}
pub fn margin_end(self, margin_end: i32) -> Self {
Self {
builder: self.builder.property("margin-end", margin_end),
}
}
pub fn margin_start(self, margin_start: i32) -> Self {
Self {
builder: self.builder.property("margin-start", margin_start),
}
}
pub fn margin_top(self, margin_top: i32) -> Self {
Self {
builder: self.builder.property("margin-top", margin_top),
}
}
pub fn name(self, name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
}
}
pub fn opacity(self, opacity: f64) -> Self {
Self {
builder: self.builder.property("opacity", opacity),
}
}
pub fn overflow(self, overflow: Overflow) -> Self {
Self {
builder: self.builder.property("overflow", overflow),
}
}
pub fn receives_default(self, receives_default: bool) -> Self {
Self {
builder: self.builder.property("receives-default", receives_default),
}
}
pub fn sensitive(self, sensitive: bool) -> Self {
Self {
builder: self.builder.property("sensitive", sensitive),
}
}
pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
Self {
builder: self
.builder
.property("tooltip-markup", tooltip_markup.into()),
}
}
pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("tooltip-text", tooltip_text.into()),
}
}
pub fn valign(self, valign: Align) -> Self {
Self {
builder: self.builder.property("valign", valign),
}
}
pub fn vexpand(self, vexpand: bool) -> Self {
Self {
builder: self.builder.property("vexpand", vexpand),
}
}
pub fn vexpand_set(self, vexpand_set: bool) -> Self {
Self {
builder: self.builder.property("vexpand-set", vexpand_set),
}
}
pub fn visible(self, visible: bool) -> Self {
Self {
builder: self.builder.property("visible", visible),
}
}
pub fn width_request(self, width_request: i32) -> Self {
Self {
builder: self.builder.property("width-request", width_request),
}
}
pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
Self {
builder: self.builder.property("accessible-role", accessible_role),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> DropDown {
self.builder.build()
}
}
impl fmt::Display for DropDown {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("DropDown")
}
}