gtk/tree_view_column.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{CellRenderer, TreeViewColumn, prelude::TreeViewColumnExt};
4use glib::object::IsA;
5
6impl TreeViewColumn {
7 ///
8 /// enum { TEXT_COLUMN, COLOR_COLUMN, N_COLUMNS };
9 /// // ...
10 /// {
11 /// GtkTreeViewColumn *column;
12 /// GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
13 ///
14 /// column = gtk_tree_view_column_new_with_attributes ("Title",
15 /// renderer,
16 /// "text", TEXT_COLUMN,
17 /// "foreground", COLOR_COLUMN,
18 /// NULL);
19 /// }
20 /// ]|
21 /// ## `title`
22 /// The title to set the header to
23 /// ## `cell`
24 /// The [`CellRenderer`][crate::CellRenderer]
25 ///
26 /// # Returns
27 ///
28 /// A newly created [`TreeViewColumn`][crate::TreeViewColumn].
29 #[doc(alias = "gtk_tree_view_column_new_with_attributes")]
30 pub fn with_attributes(
31 title: &str,
32 cell_renderer: &impl IsA<CellRenderer>,
33 attributes: &[(&str, i32)],
34 ) -> Self {
35 assert_initialized_main_thread!();
36 let tree_view_column = TreeViewColumn::new();
37 tree_view_column.set_title(title);
38 tree_view_column.pack_start(cell_renderer, true);
39 tree_view_column.set_attributes(cell_renderer, attributes);
40
41 tree_view_column
42 }
43
44 #[doc(alias = "gtk_tree_view_column_set_attributes")]
45 pub fn set_attributes(
46 &self,
47 cell_renderer: &impl IsA<CellRenderer>,
48 attributes: &[(&str, i32)],
49 ) {
50 self.clear_attributes(cell_renderer);
51 attributes.iter().for_each(|(attribute, column)| {
52 self.add_attribute(cell_renderer, attribute, *column);
53 });
54 }
55}