プロジェクト

全般

プロフィール

バグ #1514 » ruby-gtk3-TreeView.rb

TreeView.visible_range テストプログラム - Izumi Tsutsui, 2021-10-30 11:42

 
1
#require 'gtk2'
2
require 'gtk3'
3

    
4
tv = [
5
	["item01","item02"],
6
	["item11","item12"],
7
	["item21","item22"],
8
	["item31","item32"],
9
	["item41","item42"],
10
	["item51","item52"],
11
	["item61","item62"],
12
	["item71","item72"],
13
	["item81","item82"],
14
	["item91","item92"],
15
	]
16

    
17
ls = Gtk::ListStore.new(*([String] * 5))
18

    
19
treeview = Gtk::TreeView.new
20
treeview.set_model(ls)
21

    
22
treeview.append_column ::Gtk::TreeViewColumn.new("label1", ::Gtk::CellRendererText.new, text: 0)
23
treeview.append_column ::Gtk::TreeViewColumn.new("label2", ::Gtk::CellRendererText.new, text: 1)
24

    
25
tv.each do |val|
26
  iter = ls.append
27
  iter.set_value(0, val[0])
28
  iter.set_value(1, val[1])
29
end
30

    
31
win = Gtk::Window.new
32
win.title = 'TreeView visible_range test'
33
win.set_size_request 100, 200
34

    
35
sw = Gtk::ScrolledWindow.new
36
if sw.respond_to? :set_propagate_natural_width
37
  sw.propagate_natural_width = true
38
  sw.propagate_natural_height = true
39
  gtkversion = 3
40
end
41
sw.add_with_viewport(treeview)
42

    
43
#box = Gtk::Box.new(:vertical)
44
box = Gtk::VBox.new
45
box.pack_start(sw, expand: true)
46

    
47
win.add box
48
win.signal_connect('destroy') { Gtk.main_quit }
49
win.show_all
50

    
51
if gtkversion == 3
52
  dummy, start_path, end_path = treeview.visible_range
53
else
54
  start_path, end_path = treeview.visible_range
55
end
56
label = Gtk::Label.new("start_path: " + start_path.to_s)
57
label.set_alignment(0, 0.5)
58
box.pack_start(label, expand: true)
59
label = Gtk::Label.new("end_path:   " + end_path.to_s)
60
label.set_alignment(0, 0.5)
61
box.pack_start(label, expand: true)
62
win.show_all
63

    
64
Gtk.main
(2-2/7)