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
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::{prelude::TreeViewColumnExt, CellRenderer, TreeViewColumn};
use glib::object::IsA;
impl TreeViewColumn {
/// Creates a new [`TreeViewColumn`][crate::TreeViewColumn] with a number of default values.
/// This is equivalent to calling [`TreeViewColumnExt::set_title()`][crate::prelude::TreeViewColumnExt::set_title()],
/// [`TreeViewColumnExt::pack_start()`][crate::prelude::TreeViewColumnExt::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")]
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_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);
});
}
}