gtk4/tree_view_column.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
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::translate::*;
use crate::{ffi, prelude::*, CellRenderer, TreeViewColumn};
impl TreeViewColumn {
/// Creates a new [`TreeViewColumn`][crate::TreeViewColumn] with a number of default values.
/// This is equivalent to calling gtk_tree_view_column_set_title(),
/// gtk_tree_view_column_pack_start(), and
/// gtk_tree_view_column_set_attributes() on the newly created [`TreeViewColumn`][crate::TreeViewColumn].
///
/// Here’s a simple example:
///
///
/// **⚠️ The following code is in C ⚠️**
///
/// ```C
/// enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
/// // ...
/// {
/// GtkTreeViewColumn *column;
/// GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
///
/// column = gtk_tree_view_column_new_with_attributes ("Title",
/// renderer,
/// "text", TEXT_COLUMN,
/// "foreground", COLOR_COLUMN,
/// NULL);
/// }
/// ```
///
/// # Deprecated since 4.10
///
/// Use GtkColumnView instead
/// ## `title`
/// The title to set the header to
/// ## `cell`
/// The [`CellRenderer`][crate::CellRenderer]
///
/// # Returns
///
/// A newly created [`TreeViewColumn`][crate::TreeViewColumn].
#[doc(alias = "gtk_tree_view_column_new_with_attributes")]
#[doc(alias = "new_with_attributes")]
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub fn with_attributes(
title: &str,
cell_renderer: &impl IsA<CellRenderer>,
attributes: &[(&str, i32)],
) -> Self {
assert_initialized_main_thread!();
let tree_view_column = TreeViewColumn::new();
tree_view_column.set_title(title);
tree_view_column.pack_start(cell_renderer, true);
tree_view_column.set_attributes(cell_renderer, attributes);
tree_view_column
}
/// Sets the attributes in the list as the attributes of @self.
///
/// The attributes should be in attribute/column order, as in
/// gtk_tree_view_column_add_attribute(). All existing attributes
/// are removed, and replaced with the new attributes.
///
/// # Deprecated since 4.10
///
/// Use GtkColumnView instead
/// ## `cell_renderer`
/// the [`CellRenderer`][crate::CellRenderer] we’re setting the attributes of
#[doc(alias = "gtk_tree_view_column_set_attributes")]
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub fn set_attributes(
&self,
cell_renderer: &impl IsA<CellRenderer>,
attributes: &[(&str, i32)],
) {
self.clear_attributes(cell_renderer);
attributes.iter().for_each(|(attribute, column)| {
self.add_attribute(cell_renderer, attribute, *column);
});
}
#[doc(alias = "gtk_tree_view_column_set_cell_data_func")]
#[doc(alias = "set_cell_data_func")]
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub fn unset_cell_data_func(&self, cell_renderer: &impl IsA<CellRenderer>) {
unsafe {
ffi::gtk_tree_view_column_set_cell_data_func(
self.to_glib_none().0,
cell_renderer.as_ref().to_glib_none().0,
None,
std::ptr::null_mut(),
None,
);
}
}
}