-
-
Save maxxk/1af9a21cbfa944b045fc618b80a91caf to your computer and use it in GitHub Desktop.
GTK-rs TreeView column text wrapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "gtk-tree-view-wrap" | |
version = "0.1.0" | |
edition = "2018" | |
[[bin]] | |
name="gtk-tree-view-wrap" | |
path="main.rs" | |
[dependencies] | |
gtk = { version = "0.6", features = ["v3_22_30"] } | |
gio = "*" | |
pango = "*" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use gtk::prelude::*; | |
use gio::prelude::*; | |
use std::env::args; | |
fn main() { | |
let application = gtk::Application::new("test.app.tree.resize", | |
Default::default()) | |
.expect("Initialization failed..."); | |
application.connect_activate(|app| { | |
let window = gtk::ApplicationWindow::new(app); | |
let list_store = gtk::ListStore::new(&[gtk::Type::String]); | |
let tree_view = gtk::TreeView::new_with_model(&list_store); | |
let column = gtk::TreeViewColumn::new(); | |
let filler = gtk::TreeViewColumn::new(); | |
let cell = gtk::CellRendererText::new(); | |
cell.set_property_wrap_mode(pango::WrapMode::WordChar); | |
column.set_title("Test word wrap"); | |
column.set_resizable(true); | |
column.set_expand(false); | |
column.set_fixed_width(100); | |
column.pack_start(&cell, true); | |
column.add_attribute(&cell, "text", 0); | |
let tree_view_closure = tree_view.clone(); | |
column.connect_property_width_notify(move |col| { | |
let width = col.get_width(); | |
let cell: gtk::CellRendererText = col.get_cells()[0].clone().downcast().unwrap(); | |
cell.set_property_wrap_width(width); | |
// tree_view_closure.queue_resize(); | |
// col.cell_get_position(&cell); | |
// col.queue_resize(); // loop | |
}); | |
tree_view.append_column(&column); | |
filler.set_title("Filler"); | |
filler.set_expand(true); | |
tree_view.append_column(&filler); | |
tree_view.set_headers_visible(true); | |
for i in 0..10 { | |
list_store.insert_with_values(None, &[0], &[&"Long string to test wrapping"]); | |
} | |
window.add(&tree_view); | |
window.show_all(); | |
}); | |
application.run(&args().collect::<Vec<_>>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment