2

鞋子是非常方便的 GUI 工具。我想做一个搜索表单,以便帮助用户浏览更大的文本进行编辑。为此,我需要在编辑框元素内移动光标。

在这里,您将在代码中看到我的问题:

Shoes.app do

  stack do
    p=para "After pressing 'search' a question will arise"
    box=edit_box  
    box.text="One\nof\nthe\nmost\nstriking\ndifferences\nbetween\na\ncat\nand\na\nlie\nis\nthat\na\ncat\nhas\nonly\nnine lives."
    flow :margin_top=>0.1 do
      search=edit_line

      button("search") do
        pos=box.text.index search.text 
        y = box.text[0..pos].split.size-1 if pos

        if not y.nil?
          #For example if you searched "only" then 
          #cursor should jump/scroll to line 17.
          #
          #Anything there for cursor positioning, 
          #like: box.cursor=[0,y]
          #
          p.text="How can I move editbox's cursor in line #{y+1}?"
        else
          alert "'#{search.text}' not found"
        end        
      end
    end
  end
end

有没有办法改变编辑框光标的位置?如果没有,您知道另一种实施方式吗?

4

1 回答 1

0

不幸的是,Shoes 似乎没有提供任何方法来做到这一点。这些是在 EditBox 上定义的唯一方法(它继承自 Native,它有几个方法,但同样没有重新定位光标)。

rb_define_method(cEditBox, "text", CASTHOOK(shoes_edit_box_get_text), 0);
rb_define_method(cEditBox, "text=", CASTHOOK(shoes_edit_box_set_text), 1);
rb_define_method(cEditBox, "draw", CASTHOOK(shoes_edit_box_draw), 2);
rb_define_method(cEditBox, "change", CASTHOOK(shoes_control_change), -1);

http://github.com/why/shoes/blob/cea39a8bf9a5b7057b1824a9fab868d1f8609d69/shoes/ruby.c

于 2009-05-13T23:33:22.227 回答