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
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{CellRenderer, TreeViewColumn};
use glib::translate::*;
use glib::IsA;

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);
    ///  }
    /// ```
    /// ## `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")]
    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
    }

    #[doc(alias = "gtk_tree_view_column_add_attribute")]
    pub fn add_attribute(
        &self,
        cell_renderer: &impl IsA<CellRenderer>,
        attribute: &str,
        column: i32,
    ) {
        unsafe {
            ffi::gtk_tree_view_column_add_attribute(
                self.to_glib_none().0,
                cell_renderer.as_ref().to_glib_none().0,
                attribute.to_glib_none().0,
                column,
            )
        }
    }

    #[doc(alias = "gtk_tree_view_column_pack_end")]
    pub fn pack_end(&self, cell_renderer: &impl IsA<CellRenderer>, expand: bool) {
        unsafe {
            ffi::gtk_tree_view_column_pack_end(
                self.to_glib_none().0,
                cell_renderer.as_ref().to_glib_none().0,
                expand.into_glib(),
            )
        }
    }

    #[doc(alias = "gtk_tree_view_column_pack_start")]
    pub fn pack_start(&self, cell_renderer: &impl IsA<CellRenderer>, expand: bool) {
        unsafe {
            ffi::gtk_tree_view_column_pack_start(
                self.to_glib_none().0,
                cell_renderer.as_ref().to_glib_none().0,
                expand.into_glib(),
            )
        }
    }

    #[doc(alias = "gtk_tree_view_column_set_attributes")]
    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_clear")]
    pub fn clear(&self) {
        unsafe {
            ffi::gtk_tree_view_column_clear(self.to_glib_none().0);
        }
    }

    #[doc(alias = "gtk_tree_view_column_clear_attributes")]
    pub fn clear_attributes(&self, cell_renderer: &impl IsA<CellRenderer>) {
        unsafe {
            ffi::gtk_tree_view_column_clear_attributes(
                self.to_glib_none().0,
                cell_renderer.as_ref().to_glib_none().0,
            );
        }
    }

    #[doc(alias = "gtk_tree_view_column_set_cell_data_func")]
    #[doc(alias = "set_cell_data_func")]
    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,
            );
        }
    }
}