我的目标是使刻度中的滑块与旋转中的值同步,反之亦然。我尝试了一些替代方案,但我没有找到一种方法来获取比例尺所在的值,以便我可以设置新的旋转位置。
这个小练习有一个小检查按钮,应该同步两个小部件。我正在尝试通过切换功能进行此同步,但我现在卡住了。
这是到目前为止的代码:
uses
Gtk
class TestWindow:Window
_spin:Gtk.SpinButton
_scale:Gtk.Scale
construct ()
//General aspects of the window
title = "Spin and scale"
window_position = WindowPosition.CENTER
destroy.connect( Gtk.main_quit )
//create the spin button
spinAdjustment:Gtk.Adjustment = new Gtk.Adjustment(50, 0, 100, 1, 5, 0)
scaleAdjustment:Gtk.Adjustment = new Gtk.Adjustment(50, 0, 100, 1, 5, 0)
_spin:SpinButton = new Gtk.SpinButton(spinAdjustment, 1.0,1)
//create the horizontal scale
_scale:Scale = new Gtk.Scale(Gtk.Orientation.HORIZONTAL, scaleAdjustment);
//create the check button
var check = new Gtk.CheckButton.with_label ("Sync both scales!")
check.toggled.connect(toggled)
// organize it in a box
var box = new Box( Orientation.VERTICAL, 0 )
box.pack_start(_spin, true, true, 0 )
box.pack_start(_scale, true, true, 0)
box.pack_start(check, true, true, 0)
add( box )
def toggled ()
message(_spin.get_value().to_string())
//if _scale.get_value_pos() != _spin.get_value()
// _scale.set_value_pos(_spin.get_value())
init
Gtk.init( ref args )
var test = new TestWindow()
test.show_all()
Gtk.main()
谁能给我一点关于如何解决这个问题的指导?