2022-01-20 14:06:14 +00:00
|
|
|
// treeview.rs
|
|
|
|
//
|
|
|
|
// Copyright 2022 Stéphane Cerveau <scerveau@collabora.com>
|
|
|
|
//
|
2022-02-09 10:28:59 +00:00
|
|
|
// This file is part of GstPipelineStudio
|
2022-01-20 14:06:14 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2022-02-09 10:28:59 +00:00
|
|
|
|
2022-01-20 14:06:14 +00:00
|
|
|
use crate::app::GPSApp;
|
2022-02-18 11:18:28 +00:00
|
|
|
use gtk::prelude::{Cast, CellLayoutExt, CellRendererTextExt, TreeViewExt};
|
2022-01-20 14:06:14 +00:00
|
|
|
use gtk::{CellRendererText, TreeView, TreeViewColumn};
|
|
|
|
|
2022-02-18 11:18:28 +00:00
|
|
|
pub fn add_column_to_treeview(
|
|
|
|
app: &GPSApp,
|
|
|
|
tree_name: &str,
|
|
|
|
column_name: &str,
|
|
|
|
column_n: i32,
|
|
|
|
wrappable: bool,
|
|
|
|
) {
|
2022-01-20 14:06:14 +00:00
|
|
|
let treeview: TreeView = app
|
|
|
|
.builder
|
|
|
|
.object(tree_name)
|
|
|
|
.expect("Couldn't get tree_name");
|
|
|
|
let column = TreeViewColumn::new();
|
|
|
|
let cell = CellRendererText::new();
|
|
|
|
column.pack_start(&cell, true);
|
|
|
|
// Association of the view's column with the model's `id` column.
|
|
|
|
column.add_attribute(&cell, "text", column_n);
|
|
|
|
column.set_title(column_name);
|
2022-02-18 11:18:28 +00:00
|
|
|
|
|
|
|
if wrappable {
|
|
|
|
column.set_sizing(gtk::TreeViewColumnSizing::Autosize);
|
|
|
|
let cell: gtk::CellRendererText = column.cells()[0].clone().downcast().unwrap();
|
|
|
|
cell.set_wrap_width(1024);
|
|
|
|
}
|
2022-01-20 14:06:14 +00:00
|
|
|
treeview.append_column(&column);
|
|
|
|
}
|