From ed697a63e935c18a4de448678070c64ceb8279c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Fri, 18 Feb 2022 08:18:28 -0300 Subject: [PATCH] ui: treeview: Add wrappable feature --- src/ui/treeview.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ui/treeview.rs b/src/ui/treeview.rs index d24abb6..aa36834 100644 --- a/src/ui/treeview.rs +++ b/src/ui/treeview.rs @@ -7,10 +7,16 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::app::GPSApp; -use gtk::prelude::TreeViewExt; +use gtk::prelude::{Cast, CellLayoutExt, CellRendererTextExt, TreeViewExt}; use gtk::{CellRendererText, TreeView, TreeViewColumn}; -pub fn add_column_to_treeview(app: &GPSApp, tree_name: &str, column_name: &str, column_n: i32) { +pub fn add_column_to_treeview( + app: &GPSApp, + tree_name: &str, + column_name: &str, + column_n: i32, + wrappable: bool, +) { let treeview: TreeView = app .builder .object(tree_name) @@ -21,5 +27,11 @@ pub fn add_column_to_treeview(app: &GPSApp, tree_name: &str, column_name: &str, // Association of the view's column with the model's `id` column. column.add_attribute(&cell, "text", column_n); column.set_title(column_name); + + if wrappable { + column.set_sizing(gtk::TreeViewColumnSizing::Autosize); + let cell: gtk::CellRendererText = column.cells()[0].clone().downcast().unwrap(); + cell.set_wrap_width(1024); + } treeview.append_column(&column); }