This repository was archived by the owner on Mar 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathmain.rs
59 lines (47 loc) · 1.91 KB
/
main.rs
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
use gtk::prelude::*;
use gtk::{gio, glib};
fn build_ui(application: >k::Application) {
let window = gtk::ApplicationWindow::new(application);
window.set_title("Tree Model Sort Window");
window.set_border_width(10);
window.set_position(gtk::WindowPosition::Center);
window.set_default_size(350, 70);
let store = gtk::TreeStore::new(&[glib::Type::STRING]);
store.insert_with_values(None, None, &[(0, &"One")]);
store.insert_with_values(None, None, &[(0, &"Two")]);
store.insert_with_values(None, None, &[(0, &"Three")]);
store.insert_with_values(None, None, &[(0, &"Four")]);
// We create the `TreeModelSort` and we give it the `TreeStore` as
// parameter.
let sortable_store = gtk::TreeModelSort::new(&store);
// Then we create the `TreeView` from the `TreeModelSort`.
let treeview = gtk::TreeView::with_model(&sortable_store);
let column = gtk::TreeViewColumn::new();
column.set_title("Value");
column.set_clickable(true);
column.set_sort_indicator(true);
column.set_sort_column_id(0);
let renderer = gtk::CellRendererText::new();
TreeViewColumnExt::pack_end(&column, &renderer, true);
TreeViewColumnExt::add_attribute(&column, &renderer, "text", 0);
treeview.append_column(&column);
treeview.connect_row_activated(move |_, path, _column| {
let real_path = sortable_store
.convert_path_to_child_path(path)
.expect("Sorted path does not correspond to real path");
println!(
"Clicked on sorted: {:?}, real: {:?}",
path.indices(),
real_path.indices()
);
});
// We finally add the `TreeView` to the window.
window.add(&treeview);
window.show_all();
}
fn main() {
let application =
gtk::Application::new(Some("com.github.basic"), gio::ApplicationFlags::empty());
application.connect_activate(build_ui);
application.run();
}