gtk4/tree_view_column.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, prelude::*, CellRenderer, TreeViewColumn};
6
7impl TreeViewColumn {
8 /// Creates a new [`TreeViewColumn`][crate::TreeViewColumn] with a number of default values.
9 /// This is equivalent to calling gtk_tree_view_column_set_title(),
10 /// gtk_tree_view_column_pack_start(), and
11 /// gtk_tree_view_column_set_attributes() on the newly created [`TreeViewColumn`][crate::TreeViewColumn].
12 ///
13 /// Here’s a simple example:
14 ///
15 ///
16 /// **⚠️ The following code is in C ⚠️**
17 ///
18 /// ```C
19 /// enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
20 /// // ...
21 /// {
22 /// GtkTreeViewColumn *column;
23 /// GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
24 ///
25 /// column = gtk_tree_view_column_new_with_attributes ("Title",
26 /// renderer,
27 /// "text", TEXT_COLUMN,
28 /// "foreground", COLOR_COLUMN,
29 /// NULL);
30 /// }
31 /// ```
32 ///
33 /// # Deprecated since 4.10
34 ///
35 /// Use GtkColumnView instead
36 /// ## `title`
37 /// The title to set the header to
38 /// ## `cell`
39 /// The [`CellRenderer`][crate::CellRenderer]
40 ///
41 /// # Returns
42 ///
43 /// A newly created [`TreeViewColumn`][crate::TreeViewColumn].
44 #[doc(alias = "gtk_tree_view_column_new_with_attributes")]
45 #[doc(alias = "new_with_attributes")]
46 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
47 #[allow(deprecated)]
48 pub fn with_attributes(
49 title: &str,
50 cell_renderer: &impl IsA<CellRenderer>,
51 attributes: &[(&str, i32)],
52 ) -> Self {
53 assert_initialized_main_thread!();
54 let tree_view_column = TreeViewColumn::new();
55 tree_view_column.set_title(title);
56 tree_view_column.pack_start(cell_renderer, true);
57 tree_view_column.set_attributes(cell_renderer, attributes);
58
59 tree_view_column
60 }
61
62 /// Sets the attributes in the list as the attributes of @self.
63 ///
64 /// The attributes should be in attribute/column order, as in
65 /// gtk_tree_view_column_add_attribute(). All existing attributes
66 /// are removed, and replaced with the new attributes.
67 ///
68 /// # Deprecated since 4.10
69 ///
70 /// Use GtkColumnView instead
71 /// ## `cell_renderer`
72 /// the [`CellRenderer`][crate::CellRenderer] we’re setting the attributes of
73 #[doc(alias = "gtk_tree_view_column_set_attributes")]
74 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
75 #[allow(deprecated)]
76 pub fn set_attributes(
77 &self,
78 cell_renderer: &impl IsA<CellRenderer>,
79 attributes: &[(&str, i32)],
80 ) {
81 self.clear_attributes(cell_renderer);
82 attributes.iter().for_each(|(attribute, column)| {
83 self.add_attribute(cell_renderer, attribute, *column);
84 });
85 }
86
87 #[doc(alias = "gtk_tree_view_column_set_cell_data_func")]
88 #[doc(alias = "set_cell_data_func")]
89 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
90 #[allow(deprecated)]
91 pub fn unset_cell_data_func(&self, cell_renderer: &impl IsA<CellRenderer>) {
92 unsafe {
93 ffi::gtk_tree_view_column_set_cell_data_func(
94 self.to_glib_none().0,
95 cell_renderer.as_ref().to_glib_none().0,
96 None,
97 std::ptr::null_mut(),
98 None,
99 );
100 }
101 }
102}