gtk4/auto/list_item.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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
// 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, Widget};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// [`ListItem`][crate::ListItem] is used by list widgets to represent items in a
/// [`gio::ListModel`][crate::gio::ListModel].
///
/// [`ListItem`][crate::ListItem] objects are managed by the list widget (with its factory)
/// and cannot be created by applications, but they need to be populated
/// by application code. This is done by calling [`ListItemExt::set_child()`][crate::prelude::ListItemExt::set_child()].
///
/// [`ListItem`][crate::ListItem] objects exist in 2 stages:
///
/// 1. The unbound stage where the listitem is not currently connected to
/// an item in the list. In that case, the [`item`][struct@crate::ListItem#item]
/// property is set to [`None`].
///
/// 2. The bound stage where the listitem references an item from the list.
/// The [`item`][struct@crate::ListItem#item] property is not [`None`].
///
/// ## Properties
///
///
/// #### `accessible-description`
/// The accessible description to set on the list item.
///
/// Readable | Writeable
///
///
/// #### `accessible-label`
/// The accessible label to set on the list item.
///
/// Readable | Writeable
///
///
/// #### `activatable`
/// If the item can be activated by the user.
///
/// Readable | Writeable
///
///
/// #### `child`
/// Widget used for display.
///
/// Readable | Writeable
///
///
/// #### `focusable`
/// If the item can be focused with the keyboard.
///
/// Readable | Writeable
///
///
/// #### `item`
/// Displayed item.
///
/// Readable
///
///
/// #### `position`
/// Position of the item.
///
/// Readable
///
///
/// #### `selectable`
/// If the item can be selected by the user.
///
/// Readable | Writeable
///
///
/// #### `selected`
/// If the item is currently selected.
///
/// Readable
///
/// # Implements
///
/// [`ListItemExt`][trait@crate::prelude::ListItemExt], [`trait@glib::ObjectExt`]
#[doc(alias = "GtkListItem")]
pub struct ListItem(Object<ffi::GtkListItem, ffi::GtkListItemClass>);
match fn {
type_ => || ffi::gtk_list_item_get_type(),
}
}
impl ListItem {
pub const NONE: Option<&'static ListItem> = None;
}
/// Trait containing all [`struct@ListItem`] methods.
///
/// # Implementors
///
/// [`ColumnViewCell`][struct@crate::ColumnViewCell], [`ListItem`][struct@crate::ListItem]
pub trait ListItemExt: IsA<ListItem> + 'static {
/// Gets the accessible description of @self.
///
/// # Returns
///
/// the accessible description
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "gtk_list_item_get_accessible_description")]
#[doc(alias = "get_accessible_description")]
#[doc(alias = "accessible-description")]
fn accessible_description(&self) -> glib::GString {
unsafe {
from_glib_none(ffi::gtk_list_item_get_accessible_description(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the accessible label of @self.
///
/// # Returns
///
/// the accessible label
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "gtk_list_item_get_accessible_label")]
#[doc(alias = "get_accessible_label")]
#[doc(alias = "accessible-label")]
fn accessible_label(&self) -> glib::GString {
unsafe {
from_glib_none(ffi::gtk_list_item_get_accessible_label(
self.as_ref().to_glib_none().0,
))
}
}
/// Checks if a list item has been set to be activatable via
/// gtk_list_item_set_activatable().
///
/// # Returns
///
/// [`true`] if the item is activatable
#[doc(alias = "gtk_list_item_get_activatable")]
#[doc(alias = "get_activatable")]
#[doc(alias = "activatable")]
fn is_activatable(&self) -> bool {
unsafe {
from_glib(ffi::gtk_list_item_get_activatable(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the child previously set via gtk_list_item_set_child() or
/// [`None`] if none was set.
///
/// # Returns
///
/// The child
#[doc(alias = "gtk_list_item_get_child")]
#[doc(alias = "get_child")]
fn child(&self) -> Option<Widget> {
unsafe { from_glib_none(ffi::gtk_list_item_get_child(self.as_ref().to_glib_none().0)) }
}
/// Checks if a list item has been set to be focusable via
/// gtk_list_item_set_focusable().
///
/// # Returns
///
/// [`true`] if the item is focusable
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "gtk_list_item_get_focusable")]
#[doc(alias = "get_focusable")]
#[doc(alias = "focusable")]
fn is_focusable(&self) -> bool {
unsafe {
from_glib(ffi::gtk_list_item_get_focusable(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the model item that associated with @self.
///
/// If @self is unbound, this function returns [`None`].
///
/// # Returns
///
/// The item displayed
#[doc(alias = "gtk_list_item_get_item")]
#[doc(alias = "get_item")]
fn item(&self) -> Option<glib::Object> {
unsafe { from_glib_none(ffi::gtk_list_item_get_item(self.as_ref().to_glib_none().0)) }
}
/// Gets the position in the model that @self currently displays.
///
/// If @self is unbound, `GTK_INVALID_LIST_POSITION` is returned.
///
/// # Returns
///
/// The position of this item
#[doc(alias = "gtk_list_item_get_position")]
#[doc(alias = "get_position")]
fn position(&self) -> u32 {
unsafe { ffi::gtk_list_item_get_position(self.as_ref().to_glib_none().0) }
}
/// Checks if a list item has been set to be selectable via
/// gtk_list_item_set_selectable().
///
/// Do not confuse this function with [`is_selected()`][Self::is_selected()].
///
/// # Returns
///
/// [`true`] if the item is selectable
#[doc(alias = "gtk_list_item_get_selectable")]
#[doc(alias = "get_selectable")]
#[doc(alias = "selectable")]
fn is_selectable(&self) -> bool {
unsafe {
from_glib(ffi::gtk_list_item_get_selectable(
self.as_ref().to_glib_none().0,
))
}
}
/// Checks if the item is displayed as selected.
///
/// The selected state is maintained by the list widget and its model
/// and cannot be set otherwise.
///
/// # Returns
///
/// [`true`] if the item is selected.
#[doc(alias = "gtk_list_item_get_selected")]
#[doc(alias = "get_selected")]
#[doc(alias = "selected")]
fn is_selected(&self) -> bool {
unsafe {
from_glib(ffi::gtk_list_item_get_selected(
self.as_ref().to_glib_none().0,
))
}
}
/// Sets the accessible description for the list item,
/// which may be used by e.g. screen readers.
/// ## `description`
/// the description
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "gtk_list_item_set_accessible_description")]
#[doc(alias = "accessible-description")]
fn set_accessible_description(&self, description: &str) {
unsafe {
ffi::gtk_list_item_set_accessible_description(
self.as_ref().to_glib_none().0,
description.to_glib_none().0,
);
}
}
/// Sets the accessible label for the list item,
/// which may be used by e.g. screen readers.
/// ## `label`
/// the label
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "gtk_list_item_set_accessible_label")]
#[doc(alias = "accessible-label")]
fn set_accessible_label(&self, label: &str) {
unsafe {
ffi::gtk_list_item_set_accessible_label(
self.as_ref().to_glib_none().0,
label.to_glib_none().0,
);
}
}
/// Sets @self to be activatable.
///
/// If an item is activatable, double-clicking on the item, using
/// the Return key or calling gtk_widget_activate() will activate
/// the item. Activating instructs the containing view to handle
/// activation. [`ListView`][crate::ListView] for example will be emitting the
/// [`activate`][struct@crate::ListView#activate] signal.
///
/// By default, list items are activatable.
/// ## `activatable`
/// if the item should be activatable
#[doc(alias = "gtk_list_item_set_activatable")]
#[doc(alias = "activatable")]
fn set_activatable(&self, activatable: bool) {
unsafe {
ffi::gtk_list_item_set_activatable(
self.as_ref().to_glib_none().0,
activatable.into_glib(),
);
}
}
/// Sets the child to be used for this listitem.
///
/// This function is typically called by applications when
/// setting up a listitem so that the widget can be reused when
/// binding it multiple times.
/// ## `child`
/// The list item's child or [`None`] to unset
#[doc(alias = "gtk_list_item_set_child")]
#[doc(alias = "child")]
fn set_child(&self, child: Option<&impl IsA<Widget>>) {
unsafe {
ffi::gtk_list_item_set_child(
self.as_ref().to_glib_none().0,
child.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Sets @self to be focusable.
///
/// If an item is focusable, it can be focused using the keyboard.
/// This works similar to [`WidgetExt::set_focusable()`][crate::prelude::WidgetExt::set_focusable()].
///
/// Note that if items are not focusable, the keyboard cannot be used to activate
/// them and selecting only works if one of the listitem's children is focusable.
///
/// By default, list items are focusable.
/// ## `focusable`
/// if the item should be focusable
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "gtk_list_item_set_focusable")]
#[doc(alias = "focusable")]
fn set_focusable(&self, focusable: bool) {
unsafe {
ffi::gtk_list_item_set_focusable(self.as_ref().to_glib_none().0, focusable.into_glib());
}
}
/// Sets @self to be selectable.
///
/// If an item is selectable, clicking on the item or using the keyboard
/// will try to select or unselect the item. If this succeeds is up to
/// the model to determine, as it is managing the selected state.
///
/// Note that this means that making an item non-selectable has no
/// influence on the selected state at all. A non-selectable item
/// may still be selected.
///
/// By default, list items are selectable. When rebinding them to
/// a new item, they will also be reset to be selectable by GTK.
/// ## `selectable`
/// if the item should be selectable
#[doc(alias = "gtk_list_item_set_selectable")]
#[doc(alias = "selectable")]
fn set_selectable(&self, selectable: bool) {
unsafe {
ffi::gtk_list_item_set_selectable(
self.as_ref().to_glib_none().0,
selectable.into_glib(),
);
}
}
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "accessible-description")]
fn connect_accessible_description_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_accessible_description_trampoline<
P: IsA<ListItem>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accessible-description\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_accessible_description_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "accessible-label")]
fn connect_accessible_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_accessible_label_trampoline<
P: IsA<ListItem>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accessible-label\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_accessible_label_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "activatable")]
fn connect_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_activatable_trampoline<
P: IsA<ListItem>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::activatable\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_activatable_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "child")]
fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_child_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::child\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_child_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(feature = "v4_12")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
#[doc(alias = "focusable")]
fn connect_focusable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_focusable_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::focusable\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_focusable_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "item")]
fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_item_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::item\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_item_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "position")]
fn connect_position_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_position_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::position\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_position_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "selectable")]
fn connect_selectable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_selectable_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::selectable\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_selectable_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "selected")]
fn connect_selected_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_selected_trampoline<P: IsA<ListItem>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkListItem,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(ListItem::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::selected\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_selected_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<ListItem>> ListItemExt for O {}