gtk-rs bindingsを使用して es をTreeView
含むプログラムを作成したいと考えています。ComboBox
のデータを取得するにはGtkCellRendererCombo
が必要ですが、の中GtkTreeModel *
に を追加する方法がわかりません。ListStore
ListStore
今のところ、私は単純なものしか持っていませんTreeView
。ComboBox
内側の 1 列 (ヘッダー "f64")が必要です。
extern crate gtk;
use gtk::prelude::*;
use gtk::{ComboBox, ListStore, Orientation, TreeView, TreeViewColumn, Window, WindowType};
fn main() {
gtk::init().expect("Failed to initialize GTK");
let window = Window::new(WindowType::Toplevel);
window.set_position(gtk::WindowPosition::Center);
window.set_title("Rust>K+3");
window.set_position(gtk::WindowPosition::Center);
window.connect_delete_event(|wind, _| {
let (szerokosc, wysokosc) = wind.get_size();
println!("Width {} Height {}", szerokosc, wysokosc);
// Stop the main loop.
gtk::main_quit();
// Let the default handler destroy the window.
Inhibit(false)
});
let main_box = gtk::Box::new(Orientation::Vertical, 0);
let view_list = TreeView::new();
{
let types_inside_columns = &[gtk::Type::U32, gtk::Type::F64];
let model_list_of_data = ListStore::new(types_inside_columns);
for liczba in 0..10 {
let array_of_data = [&(liczba.to_value()) as &ToValue,
&((liczba as f64 * 1.5).to_value()) as &ToValue];
model_list_of_data.insert_with_values(None, &[0, 1], &array_of_data);
}
view_list.set_model(Some(&model_list_of_data));
let object_to_render_cells: gtk::CellRendererText = gtk::CellRendererText::new();
object_to_render_cells.set_visible(true);
let view_column = TreeViewColumn::new();
view_column.set_expand(true);
view_column.set_visible(true);
view_column.set_title("u32");
view_column.pack_start(&object_to_render_cells, true);
view_column.add_attribute(&object_to_render_cells, "text", 0);
view_list.append_column(&view_column);
// second column
let object_to_render_cells_2: gtk::CellRendererText = gtk::CellRendererText::new();
object_to_render_cells_2.set_visible(true);
let view_column_2 = TreeViewColumn::new();
view_column_2.set_expand(true);
view_column_2.set_visible(true);
view_column_2.set_title("f64");
view_column_2.pack_start(&object_to_render_cells, true);
view_column_2.add_attribute(&object_to_render_cells, "text", 1);
view_list.append_column(&view_column_2);
}
view_list.expand_all();
main_box.add(&view_list);
window.add(&main_box);
window.show_all();
gtk::main();
}
に追加してから、ボックス化されたを に追加しようとしgtk::Type:BaseBoxed
ましたが、メソッドによってtypeに正常に変換できません。types_inside_columns
ListStore
array_of_data
Box
to_value()
ToValue
追加: このプログラムは実行時にパニックを起こします:
extern crate gtk;
use gtk::prelude::*;
use gtk::{ComboBox, ListStore, Orientation, TreeView, TreeViewColumn, Window, WindowType};
fn main()
{
gtk::init().expect("Failed to initialize GTK");
let window = Window::new(WindowType::Toplevel);
window.set_position(gtk::WindowPosition::Center);
window.set_title("Rust>K+3");
window.set_position(gtk::WindowPosition::Center);
window.connect_delete_event(|wind, _| {
let (szerokosc,wysokosc) = wind.get_size();
println!("Width {} Height {}",szerokosc,wysokosc);
// Stop the main loop.
gtk::main_quit();
// Let the default handler destroy the window.
Inhibit(false)
});
let main_box = gtk::Box::new(Orientation::Vertical,0);
let view_list = TreeView::new();
{
let types_inside_columns = &[gtk::Type::U32,gtk::Type::F64,gtk::Type::Pointer];
let model_list_of_data = ListStore::new(types_inside_columns);
for liczba in 0..10 {
let model_for_combo = ListStore::new(types_inside_columns);
let array_of_data = [&(liczba.to_value()) as &ToValue,
&((liczba as f64 * 1.5).to_value()) as &ToValue,
];
let typ_iter = model_list_of_data.insert_with_values(None,&[0,1],&array_of_data);
model_list_of_data.set_value(&typ_iter,2, &model_for_combo.to_value() as >k::Value);
}
view_list.set_model(Some(&model_list_of_data));
let object_to_render_cells : gtk::CellRendererText = gtk::CellRendererText::new();
object_to_render_cells.set_visible(true);
let view_column= TreeViewColumn::new();
view_column.set_expand(true);
view_column.set_visible(true);
view_column.set_title("u32");
view_column.pack_start(&object_to_render_cells,true);
view_column.add_attribute(&object_to_render_cells,"text",0);
view_list.append_column(&view_column);
//second column
let object_to_render_cells_2 : gtk::CellRendererCombo = gtk::CellRendererCombo::new();
let view_column_2 = TreeViewColumn::new();
view_column_2.set_expand(true);
view_column_2.set_visible(true);
view_column_2.set_title("f64");
view_column_2.pack_start(&object_to_render_cells_2,true);
view_column_2.add_attribute(&object_to_render_cells_2,"text",1);
view_list.append_column(&view_column_2);
}
view_list.expand_all();
main_box.add(&view_list);
window.add(&main_box);
window.show_all();
gtk::main();
}