Genie にラムダがないため、ワークフローにいくつかの問題が生じます。私が回避できない特定の状況があります。
この特定の演習での私の目的は、ユーザーがクリックすると同じノートブックの次のページに移動するボタンがあるノートブックを作成することです。4 つのページがあり、最後のページのボタンを押すと、ユーザーは最初のページに戻ります (こちらのページと同様)。
valaでは、ラムダで簡単に実行できるようです。ここで提案されているクラス内で共有される変数を使用するアプローチを試してみましたが、問題は、button.click.connect によって呼び出された関数 (コールバック? 特定の専門用語についてはまだ完全にはわかりません) で変数にアクセスすることはできますが、まだノートブックとして認識されていません。
これが私のアプローチです:
[indent=4]
uses Gtk
class TestWindow : Window
notebook:Gtk.Notebook
init
// General characteristics of the window
title = "Gtk Containers"
default_height = 250
default_width = 250
window_position = WindowPosition.CENTER
destroy.connect(Gtk.main_quit)
// Now building the notebook
var notebook = new Gtk.Notebook()
var label1 = new Gtk.Label("Page one")
var label2 = new Gtk.Label("Page two")
var label3 = new Gtk.Label("Page three")
var label4 = new Gtk.Label("Page four")
var child1 = new Button.with_label ("Go to next page")
child1.clicked += def ()
notebook.set_current_page(2)
var child2 = new Button.with_label ("Go to next page")
child2.clicked += def ()
notebook.set_current_page(3)
var child3 = new Button.with_label ("Go to next page")
child3.clicked += def ()
notebook.set_current_page(4)
var child4 = new Button.with_label ("Go to first page")
child4.clicked += def ()
notebook.set_current_page(1)
notebook.append_page(child1, label1)
notebook.append_page(child2, label2)
notebook.append_page(child3, label3)
notebook.append_page(child4, label4)
// Now building the grid
var grid = new Grid()
var button1 = new Gtk.Button.with_mnemonic("Button_1")
var button2 = new Button.with_mnemonic("Button 2")
// Attaching all elements into the grid
grid.attach(notebook, 0,0,2,1)
grid.attach(button1, 0,1,1,1)
grid.attach(button2, 1,1,1,1)
add(grid)
init
Gtk.init (ref args)
var test = new TestWindow ()
test.show_all ()
Gtk.main ()
実行時に発生するエラー:
(gtkcontainerswithgrid:23039): Gtk-CRITICAL **: gtk_notebook_append_page: assertion 'GTK_IS_NOTEBOOK (notebook)' failed
したがって、in notebook.set_current_page(2)
notebook は Notebook のプロパティを継承していないと思います。
アイデアが不足しているため、この問題を回避する方法についていくつかの指針をいただければ幸いです。非推奨の構文を置き換える関数を作成しようとしました+= def()
が、同様の問題に遭遇しました。